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

commit fa0a9e5a87f3ed1a67045b6aeecdfe999728236d
Author: Zibran Khan <[email protected]>
AuthorDate: Sat Oct 24 12:20:36 2026 +0530

    apply the content-based dispatch policy to JSONBasedDefaultDispatcher
---
 .../dispatchers/JSONBasedDefaultDispatcher.java    | 10 +++
 .../JSONBasedDefaultDispatcherTest.java            | 76 ++++++++++++++++++++++
 2 files changed, 86 insertions(+)

diff --git 
a/modules/kernel/src/org/apache/axis2/dispatchers/JSONBasedDefaultDispatcher.java
 
b/modules/kernel/src/org/apache/axis2/dispatchers/JSONBasedDefaultDispatcher.java
index 61dd128f5d..0ed3019d9e 100644
--- 
a/modules/kernel/src/org/apache/axis2/dispatchers/JSONBasedDefaultDispatcher.java
+++ 
b/modules/kernel/src/org/apache/axis2/dispatchers/JSONBasedDefaultDispatcher.java
@@ -78,6 +78,16 @@ public class JSONBasedDefaultDispatcher extends 
AbstractDispatcher {
      * @see 
org.apache.axis2.engine.AbstractDispatcher#findService(org.apache.axis2.context.MessageContext)
      */
     public AxisService findService(MessageContext messageContext) throws 
AxisFault {
+        if (!ContentBasedDispatchPolicy.isAllowed(messageContext)) {
+            if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) {
+                log.debug(messageContext.getLogIDString()
+                        + " Not dispatching on the SOAP body: "
+                        + 
ContentBasedDispatchPolicy.ALLOW_CONTENT_BASED_DISPATCH
+                        + " is false");
+            }
+            return null;
+        }
+
         String serviceName;
 
         String localPart = 
messageContext.getEnvelope().getSOAPBodyFirstElementLocalName();
diff --git 
a/modules/kernel/test/org/apache/axis2/dispatchers/JSONBasedDefaultDispatcherTest.java
 
b/modules/kernel/test/org/apache/axis2/dispatchers/JSONBasedDefaultDispatcherTest.java
new file mode 100644
index 0000000000..5e19066232
--- /dev/null
+++ 
b/modules/kernel/test/org/apache/axis2/dispatchers/JSONBasedDefaultDispatcherTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axis2.dispatchers;
+
+import junit.framework.TestCase;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.AxisConfiguration;
+
+public class JSONBasedDefaultDispatcherTest extends TestCase {
+
+    /**
+     * JSONBasedDefaultDispatcher is the only Dispatch-phase dispatcher in the 
JSON
+     * configuration, and the application/xml builder registered there puts the
+     * caller's root element in the body. Selecting a service from its 
namespace is
+     * off by default, as for the SOAP body dispatchers.
+     * See {@link ContentBasedDispatchPolicy}.
+     */
+    public void testFindServiceDeniedByDefault() throws AxisFault {
+        MessageContext messageContext = messageContextNaming("Service2");
+
+        new JSONBasedDefaultDispatcher().invoke(messageContext);
+
+        assertNull("a service must not be selected from the body by default",
+                messageContext.getAxisService());
+    }
+
+    public void testFindServiceWhenAllowed() throws AxisFault {
+        MessageContext messageContext = messageContextNaming("Service2");
+        
messageContext.getConfigurationContext().getAxisConfiguration().addParameter(
+                ContentBasedDispatchPolicy.ALLOW_CONTENT_BASED_DISPATCH, 
"true");
+
+        new JSONBasedDefaultDispatcher().invoke(messageContext);
+
+        assertEquals("Service2", messageContext.getAxisService().getName());
+    }
+
+    /** A message whose body first element namespace addresses the named 
service. */
+    private MessageContext messageContextNaming(String serviceName) throws 
AxisFault {
+        ConfigurationContext cc = 
ConfigurationContextFactory.createEmptyConfigurationContext();
+        AxisConfiguration ac = cc.getAxisConfiguration();
+        ac.addService(new AxisService(serviceName));
+        MessageContext messageContext = cc.createMessageContext();
+
+        SOAPEnvelope se = 
OMAbstractFactory.getSOAP11Factory().createSOAPEnvelope();
+        SOAPBody sb = OMAbstractFactory.getSOAP11Factory().createSOAPBody(se);
+        
sb.addChild(OMAbstractFactory.getSOAP11Factory().createOMElement("operation2",
+                "http://127.0.0.1:8080/axis2/services/"; + serviceName, "pfx"));
+        messageContext.setEnvelope(se);
+        return messageContext;
+    }
+
+}

Reply via email to