This is an automated email from the ASF dual-hosted git repository.
robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git
The following commit(s) were added to refs/heads/master by this push:
new db7874e2a8 When enableJSONOnly=true avoid loading Axiom
db7874e2a8 is described below
commit db7874e2a8d2b7b6fe469d14d7a93fffae2d012e
Author: Robert Lazarski <[email protected]>
AuthorDate: Sun Nov 23 05:34:00 2025 -1000
When enableJSONOnly=true avoid loading Axiom
---
.../apache/axis2/transport/http/AxisServlet.java | 6 ++
.../axis2/transport/http/HTTPTransportUtils.java | 66 +++++++++++++++++++++-
2 files changed, 69 insertions(+), 3 deletions(-)
diff --git
a/modules/transport/http/src/main/java/org/apache/axis2/transport/http/AxisServlet.java
b/modules/transport/http/src/main/java/org/apache/axis2/transport/http/AxisServlet.java
index f070788576..199d757edb 100644
---
a/modules/transport/http/src/main/java/org/apache/axis2/transport/http/AxisServlet.java
+++
b/modules/transport/http/src/main/java/org/apache/axis2/transport/http/AxisServlet.java
@@ -614,6 +614,12 @@ public class AxisServlet extends HttpServlet {
disableREST = !JavaUtils.isFalseExplicitly(parameter.getValue());
}
+ // Check if JSON-only mode is enabled
+ parameter =
axisConfiguration.getParameter(Constants.Configuration.ENABLE_JSON_ONLY);
+ if (parameter != null) {
+ enableJSONOnly = JavaUtils.isTrueExplicitly(parameter.getValue());
+ }
+
// Should we close the reader(s)
parameter = axisConfiguration.getParameter("axis2.close.reader");
if (parameter != null) {
diff --git
a/modules/transport/http/src/main/java/org/apache/axis2/transport/http/HTTPTransportUtils.java
b/modules/transport/http/src/main/java/org/apache/axis2/transport/http/HTTPTransportUtils.java
index 34d4ed284f..4800f1ca43 100644
---
a/modules/transport/http/src/main/java/org/apache/axis2/transport/http/HTTPTransportUtils.java
+++
b/modules/transport/http/src/main/java/org/apache/axis2/transport/http/HTTPTransportUtils.java
@@ -169,7 +169,26 @@ public class HTTPTransportUtils {
throws AxisFault {
int soapVersion = VERSION_UNKNOWN;
try {
- soapVersion = initializeMessageContext(msgContext,
soapActionHeader, requestURI, contentType);
+ // Early JSON-only mode check to avoid Axiom loading
+ AxisConfiguration axisConfig =
msgContext.getConfigurationContext().getAxisConfiguration();
+ String enableJSONOnly = (String)
axisConfig.getParameterValue(Constants.Configuration.ENABLE_JSON_ONLY);
+ if (enableJSONOnly != null &&
enableJSONOnly.equalsIgnoreCase("true")) {
+ if (contentType == null || contentType.isEmpty() ||
!isJSONRequest(contentType)) {
+ // Handle JSON-only error without initializing
MessageContext (avoids Axiom loading)
+ throw new AxisFault("JSON-only mode enabled but
content-type is not application/json: " + contentType);
+ }
+ // For JSON requests in JSON-only mode, use simplified
initialization
+ msgContext.setServerSide(true);
+ msgContext.setTo(new EndpointReference(requestURI));
+ msgContext.setDoingREST(true);
+ // Skip BuilderUtil.getCharSetEncoding() call that triggers
Axiom loading
+ String charSetEnc = getCharSetEncodingSimple(contentType);
+
msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
charSetEnc);
+ soapVersion = VERSION_SOAP11; // Default for REST/JSON
+ } else {
+ // Normal path with full Axiom support
+ soapVersion = initializeMessageContext(msgContext,
soapActionHeader, requestURI, contentType);
+ }
msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
InputStream is = handleGZip(msgContext, in);
@@ -211,8 +230,27 @@ public class HTTPTransportUtils {
throws AxisFault {
int soapVersion = VERSION_UNKNOWN;
try {
- soapVersion = initializeMessageContext(msgContext,
soapActionHeader,
- requestURI, contentType);
+ // Early JSON-only mode check to avoid Axiom loading
+ AxisConfiguration axisConfig =
msgContext.getConfigurationContext().getAxisConfiguration();
+ String enableJSONOnly = (String)
axisConfig.getParameterValue(Constants.Configuration.ENABLE_JSON_ONLY);
+ if (enableJSONOnly != null &&
enableJSONOnly.equalsIgnoreCase("true")) {
+ if (contentType == null || contentType.isEmpty() ||
!isJSONRequest(contentType)) {
+ // Handle JSON-only error without initializing
MessageContext (avoids Axiom loading)
+ throw new AxisFault("JSON-only mode enabled but
content-type is not application/json: " + contentType);
+ }
+ // For JSON requests in JSON-only mode, use simplified
initialization
+ msgContext.setServerSide(true);
+ msgContext.setTo(new EndpointReference(requestURI));
+ msgContext.setDoingREST(true);
+ // Skip BuilderUtil.getCharSetEncoding() call that triggers
Axiom loading
+ String charSetEnc = getCharSetEncodingSimple(contentType);
+
msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
charSetEnc);
+ soapVersion = VERSION_SOAP11; // Default for REST/JSON
+ } else {
+ // Normal path with full Axiom support
+ soapVersion = initializeMessageContext(msgContext,
soapActionHeader,
+ requestURI, contentType);
+ }
msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
msgContext.setEnvelope(
@@ -423,4 +461,26 @@ public class HTTPTransportUtils {
return null;
}
}
+
+ /**
+ * Simple charset encoding extraction that avoids Axiom dependencies.
+ * Used in JSON-only mode to prevent loading XML-oriented libraries.
+ *
+ * @param contentType HTTP content type header
+ * @return charset encoding or default UTF-8
+ */
+ private static String getCharSetEncodingSimple(String contentType) {
+ if (contentType == null) {
+ return MessageContext.DEFAULT_CHAR_SET_ENCODING;
+ }
+ int index = contentType.indexOf("charset=");
+ if (index != -1) {
+ String encoding = contentType.substring(index + 8);
+ if (encoding.indexOf(';') != -1) {
+ encoding = encoding.substring(0, encoding.indexOf(';'));
+ }
+ return encoding.trim();
+ }
+ return MessageContext.DEFAULT_CHAR_SET_ENCODING;
+ }
}