You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by st...@apache.org on 2005/11/16 12:12:07 UTC

svn commit: r344981 - in /webservices/axis2/trunk/java/modules/core: src/org/apache/axis2/engine/AddressingBasedDispatcher.java src/org/apache/axis2/util/Utils.java test/org/apache/axis2/util/UtilsParseRequestTest.java

Author: stevel
Date: Wed Nov 16 03:11:57 2005
New Revision: 344981

URL: http://svn.apache.org/viewcvs?rev=344981&view=rev
Log:
handle path?query string dispatches

there is a test for the function that I am not sure runs, because I would have expected one of the tests to maybe fail with confusion. the code retains a possible defect from the past, namely dispatching to a service called /services/ could fail.

Added:
    webservices/axis2/trunk/java/modules/core/test/org/apache/axis2/util/UtilsParseRequestTest.java
Modified:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AddressingBasedDispatcher.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AddressingBasedDispatcher.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AddressingBasedDispatcher.java?rev=344981&r1=344980&r2=344981&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AddressingBasedDispatcher.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AddressingBasedDispatcher.java Wed Nov 16 03:11:57 2005
@@ -67,9 +67,8 @@
             }
             QName serviceName = new QName(address);
 
-            String filePart = toEPR.getAddress();
             String[] values = Utils.parseRequestURLForServiceAndOperation(
-                    filePart);
+                    address);
             if (values[0] != null) {
                 serviceName = new QName(values[0]);
                 AxisConfiguration registry =

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java?rev=344981&r1=344980&r2=344981&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java Wed Nov 16 03:11:57 2005
@@ -155,26 +155,32 @@
     }
 
 
+    /**
+     * Break a full path into pieces
+     * @param path
+     * @return an array where element [0] always contains the service, and element 1, if not null, contains
+     * the path after the first element. all ? parameters are discarded.
+     */
     public static String[] parseRequestURLForServiceAndOperation(
-            String filePart) {
+            String path) {
         String[] values = new String[2];
+        //TODO. This is kind of brittle. Any service with the name /services would cause fun.
+        int index = path.lastIndexOf(Constants.REQUEST_URL_PREFIX);
+        String service = null;
 
-        int index = filePart.lastIndexOf(Constants.REQUEST_URL_PREFIX);
-        String serviceStr = null;
         if (-1 != index) {
-            serviceStr =
-                    filePart.substring(
-                            index + Constants.REQUEST_URL_PREFIX.length() + 1);
-            if ((index = serviceStr.indexOf('/')) > 0) {
-                values[0] = serviceStr.substring(0, index);
-                int lastIndex = serviceStr.indexOf('?');
-                if (lastIndex >= 0) {
-                    values[1] = serviceStr.substring(index + 1, lastIndex);
-                } else {
-                    values[1] = serviceStr.substring(index + 1);
-                }
+            int serviceStart = index + Constants.REQUEST_URL_PREFIX.length();
+            service = path.substring(serviceStart + 1);
+            int queryIndex = service.indexOf('?');
+            if(queryIndex>0) {
+                service = service.substring(0,queryIndex);
+            }
+            int operationIndex= service.indexOf('/');
+            if (operationIndex > 0) {
+                values[0] = service.substring(0, operationIndex);
+                values[1] = service.substring(operationIndex + 1);
             } else {
-                values[0] = serviceStr;
+                values[0] = service;
             }
         }
         return values;

Added: webservices/axis2/trunk/java/modules/core/test/org/apache/axis2/util/UtilsParseRequestTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/test/org/apache/axis2/util/UtilsParseRequestTest.java?rev=344981&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/core/test/org/apache/axis2/util/UtilsParseRequestTest.java (added)
+++ webservices/axis2/trunk/java/modules/core/test/org/apache/axis2/util/UtilsParseRequestTest.java Wed Nov 16 03:11:57 2005
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.util;
+
+import org.apache.axis2.AbstractTestCase;
+
+/**
+ * Test that things break
+ */
+
+public class UtilsParseRequestTest extends AbstractTestCase {
+
+    public UtilsParseRequestTest(String testName) {
+        super(testName);
+    }
+
+    public void testfailure() throws Exception {
+        fail("here");
+    }
+    public void testService() throws Exception {
+        assertParsesTo("http://localhost:8081/services/System",
+                "System");
+    }
+
+    public void testServiceCalledServices() throws Exception {
+        assertParsesTo("http://localhost:8081/services/services",
+                "services");
+    }
+
+    public void testServiceWithQuery() throws Exception {
+        assertParsesTo("http://localhost:8081/services/System?system=ecb2f",
+                "System");
+    }
+
+    public void testServiceWithDoubleQuery() throws Exception {
+        assertParsesTo("http://localhost:8081/services/System?system=ecb2f?job=3",
+                "System");
+    }
+
+    public void testOperation() throws Exception {
+        assertParsesTo("http://localhost:8081/services/System/operation",
+                "System", "operation");
+    }
+
+    public void testOperationWithQuery() throws Exception {
+        assertParsesTo("http://localhost:8081/services/System/operation?system=ecb2f",
+                "System","operation");
+    }
+
+    public void testOperationServiceCalledServices() throws Exception {
+        assertParsesTo("http://localhost:8081/services/services/operation",
+                "services","operation");
+    }
+
+    private void assertParsesTo(String path, String service) {
+        assertParsesTo(path, service, null);
+    }
+
+    private void assertParsesTo(String path, String service, String operation) {
+        String[] strings = Utils.parseRequestURLForServiceAndOperation(path);
+        assertEquals(service,strings[0]);
+        assertEquals(operation, strings[1]);
+    }
+
+}