axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From isur...@apache.org
Subject svn commit: r815607 - in /webservices/axis2/trunk/java/modules: kernel/src/org/apache/axis2/ kernel/src/org/apache/axis2/deployment/util/ kernel/src/org/apache/axis2/dispatchers/ kernel/src/org/apache/axis2/util/ kernel/test/org/apache/axis2/deployment...
Date Wed, 16 Sep 2009 05:03:29 GMT
Author: isurues
Date: Wed Sep 16 05:03:28 2009
New Revision: 815607

URL: http://svn.apache.org/viewvc?rev=815607&view=rev
Log:
Supporting hierarchical services with the '/' charactor. Currently '!' charactor is used to
indicate the service hierarchy. But the natural and proper way is to use the '/'
character. Therefore used '/' and improved the dispatching logic to support all possible scenarios.

Added service and operation dispatching tests to cover all possilbe scenarios.


Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/HTTPLocationBasedDispatcher.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/RequestURIBasedOperationDispatcher.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/RequestURIBasedServiceDispatcher.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Utils.java
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/HierarchicalServiceTest.java
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/dispatchers/RequestURIBasedOperationDispatcherTest.java
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/dispatchers/RequestURIBasedServiceDispatcherTest.java
    webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/HTTPWorker.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java?rev=815607&r1=815606&r2=815607&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java Wed Sep
16 05:03:28 2009
@@ -308,6 +308,11 @@
 
    public static final String JSR311_ANNOTATIONS="JAXRSAnnotaion";
 
+    /**
+     * Dispatching constants
+     */
+    public static int MAX_HIERARCHICAL_DEPTH = 10;
+
     public static interface Configuration {
         public static final String ENABLE_REST = "enableREST";
         public static final String ENABLE_HTTP_CONTENT_NEGOTIATION = "httpContentNegotiation";

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java?rev=815607&r1=815606&r2=815607&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java
Wed Sep 16 05:03:28 2009
@@ -1878,12 +1878,11 @@
 
     /**
      * Computes the hierarchical part of the service name if this is such a service path.
-     * In this hierarchical path, we use '!' instead of '/'.
-     * Ex:  filePath = .../repository/services/foo/1.0.0/version.aar -> "foo!1.0.0"
+     * Ex:  filePath = .../repository/services/foo/1.0.0/version.aar -> "foo/1.0.0/"
      *      filePath = .../repository/services/version.aar -> ""
      * @param filePath - input file path of the deploying file
      * @param serviceDir - 'services', 'pojo', 'servicejars' etc..
-     * @return hierarchical path. either "" or a '/' separated string (Ex: foo!1.0.0)
+     * @return hierarchical path. either "" or a '/' separated string (Ex: foo/1.0.0/)
      */
     public static String getServiceHierarchy(String filePath, String serviceDir) {
         if (filePath == null || serviceDir == null) {
@@ -1902,13 +1901,6 @@
                 return "";
             }
             serviceHierarchy = temp.substring(0, temp.lastIndexOf('/') + 1);
-
-            /**
-             * Now replace '/' using the special charactor '!'. This is to overcome the issues
-             * in dispatching. If we use '/', it is hard to find service and operation by
looking
-             * at the EPR, in dispatch time.
-             */
-            serviceHierarchy = serviceHierarchy.replace('/', '!');
         }
         return serviceHierarchy;
     }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/HTTPLocationBasedDispatcher.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/HTTPLocationBasedDispatcher.java?rev=815607&r1=815606&r2=815607&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/HTTPLocationBasedDispatcher.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/HTTPLocationBasedDispatcher.java
Wed Sep 16 05:03:28 2009
@@ -54,8 +54,7 @@
         AxisService axisService = messageContext.getAxisService();
         if (axisService != null && messageContext.getTo() != null) {
             String uri = messageContext.getTo().getAddress();
-            String httpLocation = parseRequestURL(uri, messageContext
-                    .getConfigurationContext().getServiceContextPath());
+            String httpLocation = parseRequestURL(uri, axisService.getName());
             String httpMethod = (String) messageContext.getProperty(HTTPConstants.HTTP_METHOD);
 
             if (httpLocation != null) {
@@ -97,30 +96,31 @@
         init(new HandlerDescription(NAME));
     }
 
-    private String parseRequestURL(String path, String servicePath) {
+    private String parseRequestURL(String path, String serviceName) {
 
-        int index = path.lastIndexOf(servicePath);
-        String service = null;
+        serviceName = "/" + serviceName;
+        int index = path.lastIndexOf(serviceName);
+        String httpLocation = null;
 
         if (-1 != index) {
-            int serviceStart = index + servicePath.length();
+            int serviceStart = index + serviceName.length();
             if (path.length() > serviceStart + 1) {
-                service = path.substring(serviceStart + 1);
+                httpLocation = path.substring(serviceStart);
             }
         }
 
-        if (service != null) {
-            index = service.indexOf("/");
+        if (httpLocation != null) {
+            index = httpLocation.indexOf("/");
             if (-1 != index) {
-                service = service.substring(index);
+                httpLocation = httpLocation.substring(index);
             } else {
-                int queryIndex = service.indexOf("?");
+                int queryIndex = httpLocation.indexOf("?");
                 if (queryIndex != -1) {
-                    service = service.substring(queryIndex);
+                    httpLocation = httpLocation.substring(queryIndex);
                 }
             }
         }
-        return service;
+        return httpLocation;
     }
 
     /**

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/RequestURIBasedOperationDispatcher.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/RequestURIBasedOperationDispatcher.java?rev=815607&r1=815606&r2=815607&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/RequestURIBasedOperationDispatcher.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/RequestURIBasedOperationDispatcher.java
Wed Sep 16 05:03:28 2009
@@ -50,12 +50,10 @@
         EndpointReference toEPR = messageContext.getTo();
         if (toEPR != null) {
             String filePart = toEPR.getAddress();
-            String[] values = Utils.parseRequestURLForServiceAndOperation(filePart,
-                                                                          messageContext
-                                                                                  .getConfigurationContext().getServiceContextPath());
+            String operation  = Utils.getOperationName(filePart, service.getName());
 
-            if ((values.length >= 2) && (values[1] != null)) {
-                QName operationName = new QName(values[1]);
+            if (operation != null) {
+                QName operationName = new QName(operation);
                 log.debug(messageContext.getLogIDString() +
                         " Checking for Operation using QName(target endpoint URI fragment)
: " +
                         operationName);

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/RequestURIBasedServiceDispatcher.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/RequestURIBasedServiceDispatcher.java?rev=815607&r1=815606&r2=815607&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/RequestURIBasedServiceDispatcher.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/RequestURIBasedServiceDispatcher.java
Wed Sep 16 05:03:28 2009
@@ -20,6 +20,7 @@
 package org.apache.axis2.dispatchers;
 
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
@@ -52,32 +53,57 @@
                         toEPR.getAddress());
             }
             String filePart = toEPR.getAddress();
-            //REVIEW: (nagy) Parsing the RequestURI will also give us the operationName if
present, so we could conceivably store it in the MessageContext, but doing so and retrieving
it is probably no faster than simply reparsing the URI
             ConfigurationContext configurationContext = messageContext.getConfigurationContext();
-            String[] values = Utils.parseRequestURLForServiceAndOperation(filePart,
-                                                                          messageContext
-                                                                                  .getConfigurationContext().getServiceContextPath());
 
-            if ((values.length >= 1) && (values[0] != null)) {
+            //Get the service/operation part from the request URL
+            String serviceOpPart = Utils.getServiceAndOperationPart(filePart,
+                    messageContext.getConfigurationContext().getServiceContextPath());
+
+            if (serviceOpPart != null) {
             	
-            	AxisConfiguration registry =
-            		configurationContext.getAxisConfiguration();
+                AxisConfiguration registry =
+                        configurationContext.getAxisConfiguration();
 
-            	AxisService axisService = registry.getService(values[0]);
+                /**
+                 * Split the serviceOpPart from '/' and add part by part and check whether
we have
+                 * a service. This is because we are supporting hierarchical services. We
can't
+                 * decide the service name just by looking at the request URL.
+                 */
+                AxisService axisService = null;
+                String[] parts = serviceOpPart.split("/");
+                String serviceName = "";
+                int count = 0;
+
+                /**
+                 * To avoid performance issues if an incorrect URL comes in with a long service
name
+                 * including lots of '/' separated strings, we limit the hierarchical depth
to 10
+                 */
+                while (axisService == null && count < parts.length &&
+                        count < Constants.MAX_HIERARCHICAL_DEPTH) {
+                    serviceName = count == 0 ? serviceName + parts[count] :
+                            serviceName + "/" + parts[count];
+                    axisService = registry.getService(serviceName);
+                    count++;
+                }
 
-            	// If the axisService is not null we get the binding that the request came to
add
-            	// add it as a property to the messageContext
-            	if (axisService != null) {
-            		Map endpoints = axisService.getEndpoints();
-            		if (endpoints != null) {
-            			if (endpoints.size() == 1) {
-            				messageContext.setProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME,
-            						endpoints.get(
+                // If the axisService is not null we get the binding that the request came
to add
+                // add it as a property to the messageContext
+                if (axisService != null) {
+                    Map endpoints = axisService.getEndpoints();
+                    if (endpoints != null) {
+                        if (endpoints.size() == 1) {
+                            messageContext.setProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME,
+                                    endpoints.get(
             								axisService.getEndpointName()));
             			} else {
-            				String endpointName = values[0].substring(values[0].indexOf(".") + 1);
-            				messageContext.setProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME,
-            						endpoints.get(endpointName));
+                            String[] temp = serviceName.split("/");
+                            int periodIndex = temp[temp.length - 1].lastIndexOf('.');
+                            if (periodIndex != -1) {
+                                String endpointName
+                                        = temp[temp.length - 1].substring(periodIndex + 1);
+                                messageContext.setProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME,
+                                        endpoints.get(endpointName));
+                            }
             			}
             		}
             	}

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Utils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Utils.java?rev=815607&r1=815606&r2=815607&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Utils.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Utils.java Wed Sep
16 05:03:28 2009
@@ -247,6 +247,78 @@
         return values;
     }
 
+    /**
+     * Gives the service/operation part from the incoming EPR
+     * Ex: ..services/foo/bar/Version/getVersion -> foo/bar/Version/getVersion
+     * @param path - incoming EPR
+     * @param servicePath - Ex: 'services'
+     * @return - service/operation part
+     */
+    public static String getServiceAndOperationPart(String path, String servicePath) {
+        if (path == null) {
+            return null;
+        }
+        int index = path.lastIndexOf(servicePath);
+        String serviceOpPart = null;
+
+        if (-1 != index) {
+            int serviceStart = index + servicePath.length();
+
+            //get the string after services path
+            if (path.length() > serviceStart + 1) {
+                serviceOpPart = path.substring(serviceStart + 1);
+
+                //remove everything after ?
+                int queryIndex = serviceOpPart.indexOf('?');
+                if (queryIndex > 0) {
+                    serviceOpPart = serviceOpPart.substring(0, queryIndex);
+                }
+            }
+        }
+        return serviceOpPart;
+    }
+
+    /**
+     * Compute the operation path from request URI using the servince name. Service name
can be a
+     * normal one or a hierarchical one.
+     * Ex:  ../services/Echo/echoString -> echoString
+     *      ../services/foo/1.0.0/Echo/echoString -> echoString
+     *      ../services/Echo/ -> null
+     * @param path - request URI
+     * @param serviceName - service name
+     * @return - operation name if any, else null
+     */
+    public static String getOperationName(String path, String serviceName) {
+        if (path == null || serviceName == null) {
+            return null;
+        }
+        String[] temp = path.split(serviceName + "/");
+        String operationName = null;
+        if (temp.length > 1) {
+            operationName = temp[temp.length - 1];
+        } else {
+            //this scenario occurs if the endpoint name is there in the URL after service
name
+            temp = path.split(serviceName + ".");
+            if (temp.length > 1) {
+                operationName = temp[temp.length - 1];
+                operationName = operationName.substring(operationName.indexOf('/') + 1);
+            }
+        }
+
+        if (operationName != null) {
+            //remove everyting after '?'
+            int queryIndex = operationName.indexOf('?');
+            if (queryIndex > 0) {
+                operationName = operationName.substring(0, queryIndex);
+            }
+            //remove last '/'
+            if (operationName.endsWith("/")) {
+                operationName = operationName.substring(0, operationName.length() - 1);
+            }
+        }
+        return operationName;
+    }
+
     public static ConfigurationContext getNewConfigurationContext(String repositry)
             throws Exception {
         final File file = new File(repositry);

Modified: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/HierarchicalServiceTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/HierarchicalServiceTest.java?rev=815607&r1=815606&r2=815607&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/HierarchicalServiceTest.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/HierarchicalServiceTest.java
Wed Sep 16 05:03:28 2009
@@ -21,19 +21,19 @@
 
     public void testHierarchicalServices() throws AxisFault {
         //Test for foo/bar/1.0.0 hierarchy
-        AxisServiceGroup sg100 = axisConfig.getServiceGroup("foo!bar!1.0.0!testService");
+        AxisServiceGroup sg100 = axisConfig.getServiceGroup("foo/bar/1.0.0/testService");
         assertNotNull(sg100);
-        AxisService hie100service1 = axisConfig.getService("foo!bar!1.0.0!Hie100Service1");
+        AxisService hie100service1 = axisConfig.getService("foo/bar/1.0.0/Hie100Service1");
         assertNotNull(hie100service1);
-        AxisService hie100service2 = axisConfig.getService("foo!bar!1.0.0!Hie100Service2");
+        AxisService hie100service2 = axisConfig.getService("foo/bar/1.0.0/Hie100Service2");
         assertNotNull(hie100service2);
 
         //Test for foo/bar/1.0.1 hierarchy
-        AxisServiceGroup sg101 = axisConfig.getServiceGroup("foo!bar!1.0.1!testService");
+        AxisServiceGroup sg101 = axisConfig.getServiceGroup("foo/bar/1.0.1/testService");
         assertNotNull(sg101);
-        AxisService hie101service1 = axisConfig.getService("foo!bar!1.0.1!Hie101Service1");
+        AxisService hie101service1 = axisConfig.getService("foo/bar/1.0.1/Hie101Service1");
         assertNotNull(hie101service1);
-        AxisService hie101service2 = axisConfig.getService("foo!bar!1.0.1!Hie101Service2");
+        AxisService hie101service2 = axisConfig.getService("foo/bar/1.0.1/Hie101Service2");
         assertNotNull(hie101service2);
     }
 

Modified: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/dispatchers/RequestURIBasedOperationDispatcherTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/dispatchers/RequestURIBasedOperationDispatcherTest.java?rev=815607&r1=815606&r2=815607&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/dispatchers/RequestURIBasedOperationDispatcherTest.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/dispatchers/RequestURIBasedOperationDispatcherTest.java
Wed Sep 16 05:03:28 2009
@@ -28,6 +28,7 @@
 import org.apache.axis2.description.AxisOperation;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.InOnlyAxisOperation;
+import org.apache.axis2.description.AxisEndpoint;
 import org.apache.axis2.engine.AxisConfiguration;
 
 import javax.xml.namespace.QName;
@@ -36,7 +37,16 @@
 
     public void testFindService() throws AxisFault {
         MessageContext messageContext;
+
+        //Global services
         AxisService as1 = new AxisService("Service1");
+        as1.addEndpoint("Service1Endpoint", new AxisEndpoint());
+
+        //Hierarchical Services
+        AxisService as2 = new AxisService("foo/bar/Version");
+        AxisService as3 = new AxisService("foo/bar/1.0.1/Echo");
+        as2.addEndpoint("VersionEndpoint", new AxisEndpoint());
+        as3.addEndpoint("EchoEndpoint", new AxisEndpoint());
 
 
         AxisOperation operation1 = new InOnlyAxisOperation(new QName("operation1"));
@@ -44,19 +54,67 @@
         as1.addOperation(operation1);
         as1.addOperation(operation2);
 
+        AxisOperation operation3 = new InOnlyAxisOperation(new QName("getVersion"));
+        AxisOperation operation4 = new InOnlyAxisOperation(new QName("echo"));
+        as2.addOperation(operation3);
+        as3.addOperation(operation4);
+
         ConfigurationContext cc = ConfigurationContextFactory.createEmptyConfigurationContext();
         AxisConfiguration ac = cc.getAxisConfiguration();
         ac.addService(as1);
+        ac.addService(as2);
+        ac.addService(as3);
+
+        RequestURIBasedOperationDispatcher ruisd = new RequestURIBasedOperationDispatcher();
+
+        /**
+         * Tests for global services
+         */
         messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/Service1/operation2"));
+        messageContext.setAxisService(as1);
+        ruisd.invoke(messageContext);
+        assertEquals(operation2, messageContext.getAxisOperation());
 
-        messageContext.setTo(new EndpointReference(
-                "http://127.0.0.1:8080/axis2/services/Service1/operation2"));
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/Service1.Service1Endpoint/operation2"));
         messageContext.setAxisService(as1);
+        ruisd.invoke(messageContext);
+        assertEquals(operation2, messageContext.getAxisOperation());
 
-        RequestURIBasedOperationDispatcher ruisd = new RequestURIBasedOperationDispatcher();
+        /**
+         * Tests for hierarchical services
+         */
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/foo/bar/Version/getVersion"));
+        messageContext.setAxisService(as2);
         ruisd.invoke(messageContext);
+        assertEquals(operation3, messageContext.getAxisOperation());
 
-        assertEquals(operation2, messageContext.getAxisOperation());
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/foo/bar/Version.VersionEndpoint/getVersion"));
+        messageContext.setAxisService(as2);
+        ruisd.invoke(messageContext);
+        assertEquals(operation3, messageContext.getAxisOperation());
+
+
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/foo/bar/1.0.1/Echo/echo"));
+        messageContext.setAxisService(as3);
+        ruisd.invoke(messageContext);
+        assertEquals(operation4, messageContext.getAxisOperation());
+
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/foo/bar/1.0.1/Echo.EchoEndpoint/echo"));
+        messageContext.setAxisService(as3);
+        ruisd.invoke(messageContext);
+        assertEquals(operation4, messageContext.getAxisOperation());
     }
 
 }

Modified: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/dispatchers/RequestURIBasedServiceDispatcherTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/dispatchers/RequestURIBasedServiceDispatcherTest.java?rev=815607&r1=815606&r2=815607&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/dispatchers/RequestURIBasedServiceDispatcherTest.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/dispatchers/RequestURIBasedServiceDispatcherTest.java
Wed Sep 16 05:03:28 2009
@@ -26,28 +26,136 @@
 import org.apache.axis2.context.ConfigurationContextFactory;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisEndpoint;
 import org.apache.axis2.engine.AxisConfiguration;
 
 public class RequestURIBasedServiceDispatcherTest extends TestCase {
 
     public void testFindService() throws AxisFault {
         MessageContext messageContext;
+
+        //Global services
         AxisService as1 = new AxisService("Service1");
         AxisService as2 = new AxisService("Service2");
+        as1.addEndpoint("Service1Endpoint", new AxisEndpoint());
+
+        //Hierarchical Services
+        AxisService as3 = new AxisService("foo/bar/Version");
+        AxisService as4 = new AxisService("foo/bar/1.0.1/Echo");
+        as3.addEndpoint("VersionEndpoint", new AxisEndpoint());
+        as4.addEndpoint("EchoEndpoint", new AxisEndpoint());
 
         ConfigurationContext cc = ConfigurationContextFactory.createEmptyConfigurationContext();
         AxisConfiguration ac = cc.getAxisConfiguration();
         ac.addService(as1);
         ac.addService(as2);
-        messageContext = cc.createMessageContext();
-
-        messageContext
-                .setTo(new EndpointReference("http://127.0.0.1:8080/axis2/services/Service2"));
+        ac.addService(as3);
+        ac.addService(as4);
 
         RequestURIBasedServiceDispatcher ruisd = new RequestURIBasedServiceDispatcher();
+
+        /**
+         * Tests for global services
+         */
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/Service2"));
         ruisd.invoke(messageContext);
+        assertEquals(as2, messageContext.getAxisService());
+
+        //service/operation scenario
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/Service2/getName"));
+        ruisd.invoke(messageContext);
+        assertEquals(as2, messageContext.getAxisService());
 
+        //REST scenario
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/Service2/student/name/peter/age/25"));
+        ruisd.invoke(messageContext);
         assertEquals(as2, messageContext.getAxisService());
+
+        //service.endpoint scenario
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/Service1.Service1Endpoint"));
+        ruisd.invoke(messageContext);
+        assertEquals(as1, messageContext.getAxisService());
+
+        //service.endpoint/operation scenario
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/Service1.Service1Endpoint/getName"));
+        ruisd.invoke(messageContext);
+        assertEquals(as1, messageContext.getAxisService());
+
+        /**
+         * Tests for hierarchical services
+         */
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/foo/bar/Version"));
+        ruisd.invoke(messageContext);
+        assertEquals(as3, messageContext.getAxisService());
+
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/foo/bar/Version/getVersion"));
+        ruisd.invoke(messageContext);
+        assertEquals(as3, messageContext.getAxisService());
+
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/foo/bar/Version/student/name/peter/age/25"));
+        ruisd.invoke(messageContext);
+        assertEquals(as3, messageContext.getAxisService());
+        
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/foo/bar/Version.VersionEndpoint"));
+        ruisd.invoke(messageContext);
+        assertEquals(as3, messageContext.getAxisService());
+
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/foo/bar/Version.VersionEndpoint/getVersion"));
+        ruisd.invoke(messageContext);
+        assertEquals(as3, messageContext.getAxisService());
+
+        /**
+         * Tests for hierarchical services with '.' in the service name
+         */
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/foo/bar/1.0.1/Echo"));
+        ruisd.invoke(messageContext);
+        assertEquals(as4, messageContext.getAxisService());
+
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/foo/bar/1.0.1/Echo/echo"));
+        ruisd.invoke(messageContext);
+        assertEquals(as4, messageContext.getAxisService());
+
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/foo/bar/1.0.1/Echo/student/name/peter/age/25"));
+        ruisd.invoke(messageContext);
+        assertEquals(as4, messageContext.getAxisService());
+
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/foo/bar/1.0.1/Echo.EchoEndpoint"));
+        ruisd.invoke(messageContext);
+        assertEquals(as4, messageContext.getAxisService());
+
+        messageContext = cc.createMessageContext();
+        messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" +
+                "/axis2/services/foo/bar/1.0.1/Echo.EchoEndpoint/echo"));
+        ruisd.invoke(messageContext);
+        assertEquals(as4, messageContext.getAxisService());
     }
 
 }

Modified: webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/HTTPWorker.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/HTTPWorker.java?rev=815607&r1=815606&r2=815607&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/HTTPWorker.java
(original)
+++ webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/HTTPWorker.java
Wed Sep 16 05:03:28 2009
@@ -125,7 +125,13 @@
                 }
             }
             if (uri.endsWith("?wsdl")) {
-                String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length()
- 5);
+                /**
+                 * service name can be hierarchical (axis2/services/foo/1.0.0/Version?wsdl)
or
+                 * normal (axis2/services/Version?wsdl).
+                 */
+                String[] temp = uri.split(configurationContext.getServiceContextPath() +
"/");
+                String serviceName = temp[1].substring(0, temp[1].length() - 5);
+                
                 HashMap services = configurationContext.getAxisConfiguration().getServices();
                 AxisService service = (AxisService) services.get(serviceName);
                 if (service != null) {



Mime
View raw message