cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject svn commit: r469449 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/common/util/ common/common/src/test/java/org/apache/cxf/common/util/ rt/core/src/main/java/org/apache/cxf/interceptor/ rt/core/src/main/java/org/apache/cxf/transp...
Date Tue, 31 Oct 2006 11:25:39 GMT
Author: mmao
Date: Tue Oct 31 03:25:36 2006
New Revision: 469449

URL: http://svn.apache.org/viewvc?view=rev&rev=469449
Log:
HTTP GET update
* Change the way to get the resource base path
* Rollback the JettyHTTPDestination method changes.

Added:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/HttpUriMapper.java
  (with props)
    incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/transport/HttpUriMapperTest.java
  (with props)
Modified:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
    incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/URIMappingInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorDocLitTest.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorRPCTest.java
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPServerEngine.java

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java?view=diff&rev=469449&r1=469448&r2=469449
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
(original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
Tue Oct 31 03:25:36 2006
@@ -19,8 +19,12 @@
 
 package org.apache.cxf.common.util;
 
-import java.io.*;
-import java.net.*;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
 public final class StringUtils {
 
@@ -92,5 +96,34 @@
         } else {
             return uri1.equals(uri2);
         }
+    }
+    
+    public static String diff(String str1, String str2) {
+        int index = str1.lastIndexOf(str2);
+        if (index > -1) {
+            return str1.substring(str2.length());
+        }
+        return str1;
+    }
+    
+    public static List<String> getParts(String str, String sperator) {
+        List<String> ret = new ArrayList<String>();
+        List<String> parts = Arrays.asList(str.split("/"));
+        for (String part : parts) {
+            if (!isEmpty(part)) {
+                ret.add(part);
+            }
+        }
+        return ret;
+    }
+    
+    public static String getFirstNotEmpty(String str, String sperator) {
+        List<String> parts = Arrays.asList(str.split("/"));
+        for (String part : parts) {
+            if (!isEmpty(part)) {
+                return part;
+            }
+        }
+        return str;
     }
 }

Modified: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java?view=diff&rev=469449&r1=469448&r2=469449
==============================================================================
--- incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java
(original)
+++ incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java
Tue Oct 31 03:25:36 2006
@@ -19,11 +19,36 @@
 
 package org.apache.cxf.common.util;
 
+import java.util.List;
+
 import junit.framework.TestCase;
 
 public class StringUtilsTest extends TestCase {
     public void testTrim() throws Exception {
         String target = "////soapport///";
         assertEquals("soapport", StringUtils.trim(target, "/"));
+    }
+    
+    public void testDiff() throws Exception {
+        String str1 = "http://local/SoapContext/SoapPort/greetMe/me/CXF";
+        String str2 = "http://local/SoapContext/SoapPort";
+        String str3 = "http://local/SoapContext/SoapPort/";
+        assertEquals("/greetMe/me/CXF", StringUtils.diff(str1, str2));
+        assertEquals("greetMe/me/CXF", StringUtils.diff(str1, str3));
+        assertEquals("http://local/SoapContext/SoapPort/", StringUtils.diff(str3, str1));
+    }
+    
+    public void testGetFirstNotEmpty() throws Exception {        
+        assertEquals("greetMe", StringUtils.getFirstNotEmpty("/greetMe/me/CXF", "/"));
+        assertEquals("greetMe", StringUtils.getFirstNotEmpty("greetMe/me/CXF", "/"));
+    }
+    
+    public void testGetParts() throws Exception {
+        String str = "/greetMe/me/CXF";
+        List<String> parts = StringUtils.getParts(str, "/");
+        assertEquals(3, parts.size());
+        assertEquals("greetMe", parts.get(0));
+        assertEquals("me", parts.get(1));
+        assertEquals("CXF", parts.get(2));
     }
 }

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/URIMappingInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/URIMappingInterceptor.java?view=diff&rev=469449&r1=469448&r2=469449
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/URIMappingInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/URIMappingInterceptor.java
Tue Oct 31 03:25:36 2006
@@ -159,39 +159,32 @@
             return queries;
         }
 
-        String path = (String)message.get(Message.PATH_INFO);
-        String basePath = getBasePath(message);
-        List<String> parts = Arrays.asList(path.split("/"));
-        int baseIndex = parts.indexOf(basePath);
-        if (baseIndex + 2 > parts.size()) {
-            return null;
-        }
-        for (int i = baseIndex + 2; i < parts.size(); i += 2) {
+        String rest = getRest(message);
+        List<String> parts = StringUtils.getParts(rest, "/");
+        
+        for (int i = 1; i < parts.size(); i+=2) {
             if (i + 1 > parts.size()) {
                 queries.put(parts.get(i), null);
+            } else {
+                queries.put(parts.get(i), parts.get(i + 1));
             }
-            queries.put(parts.get(i), parts.get(i + 1));
         }
         return queries;
     }
     
     private String getBasePath(Message message) {
-        String basePath = (String)message.get(Message.BASE_PATH);     
-        return StringUtils.trim(basePath, "/");
+        return (String)message.get(Message.BASE_PATH);        
     }
-
-    protected String getOperationName(Message message) {
+    
+    private String getRest(Message message) {
         String path = (String)message.get(Message.PATH_INFO);
-
-        String basePath = getBasePath(message);
-
-        List<String> parts = Arrays.asList(path.split("/"));
-
-        int baseIndex = parts.indexOf(basePath);
-        if (baseIndex + 1 > parts.size()) {
-            return null;
-        }
-        String opName = parts.get(baseIndex + 1);
+        String basePath = getBasePath(message);        
+        return StringUtils.diff(path, basePath);        
+    }
+    
+    protected String getOperationName(Message message) {
+        String rest = getRest(message);        
+        String opName = StringUtils.getFirstNotEmpty(rest, "/");
         if (opName.indexOf("?") != -1) {
             opName = opName.split("\\?")[0];
         }

Added: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/HttpUriMapper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/HttpUriMapper.java?view=auto&rev=469449
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/HttpUriMapper.java
(added)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/HttpUriMapper.java
Tue Oct 31 03:25:36 2006
@@ -0,0 +1,26 @@
+package org.apache.cxf.transport;
+
+public final class HttpUriMapper {
+    
+    private HttpUriMapper() {
+        // Util class dont need public constructor
+    }
+    
+    public static String getContextName(String path) {
+        String contextName = "";        
+        int idx = path.lastIndexOf('/');
+        if (idx > 0) {
+            contextName = path.substring(0, idx);          
+        }
+        return contextName;
+    }
+    
+    public static String getResourceBase(String path) {
+        String servletMap = path;
+        int idx = path.lastIndexOf('/');
+        if (idx > 0) {
+            servletMap = path.substring(idx);
+        }
+        return servletMap;
+    }
+}

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/HttpUriMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/HttpUriMapper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/transport/HttpUriMapperTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/transport/HttpUriMapperTest.java?view=auto&rev=469449
==============================================================================
--- incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/transport/HttpUriMapperTest.java
(added)
+++ incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/transport/HttpUriMapperTest.java
Tue Oct 31 03:25:36 2006
@@ -0,0 +1,29 @@
+package org.apache.cxf.transport;
+
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+public class HttpUriMapperTest extends TestCase {
+
+    public void testGetContext() throws Exception {
+        URL url = new URL("http://localhost:8080/SoapContext/SoapPort");
+        String path = url.getPath();
+        System.err.println(path);
+        assertEquals("/SoapContext", HttpUriMapper.getContextName(path));
+        
+        url = new URL("http://localhost:8080/SoapContext/SoapPort/");
+        path = url.getPath();
+        System.err.println(path);
+        assertEquals("/SoapContext/SoapPort", HttpUriMapper.getContextName(path));
+    }
+    
+    public void testGetResourceBase() throws Exception {
+        URL url = new URL("http://localhost:8080/SoapContext/SoapPort");
+        String path = url.getPath();
+        assertEquals("/SoapPort", HttpUriMapper.getResourceBase(path));
+        url = new URL("http://localhost:8080/SoapContext/SoapPort/");
+        path = url.getPath();
+        assertEquals("/", HttpUriMapper.getResourceBase(path));
+    }
+}

Propchange: incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/transport/HttpUriMapperTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/transport/HttpUriMapperTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorDocLitTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorDocLitTest.java?view=diff&rev=469449&r1=469448&r2=469449
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorDocLitTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorDocLitTest.java
Tue Oct 31 03:25:36 2006
@@ -54,7 +54,7 @@
         
         message = new MessageImpl();
         message.put(Message.HTTP_REQUEST_METHOD, "GET");
-        message.put(Message.BASE_PATH, "SoapPort");
+        message.put(Message.BASE_PATH, "/CalculatorService/SoapPort");
         
         Exchange exchange = new ExchangeImpl();
         message.setExchange(exchange);        

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorRPCTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorRPCTest.java?view=diff&rev=469449&r1=469448&r2=469449
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorRPCTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorRPCTest.java
Tue Oct 31 03:25:36 2006
@@ -53,7 +53,7 @@
                                    new SoapBindingFactory());
         message = new MessageImpl();
         message.put(Message.HTTP_REQUEST_METHOD, "GET");
-        message.put(Message.BASE_PATH, "SoapPort");
+        message.put(Message.BASE_PATH, "/SOAPServiceRPCLit/SoapPort/");
         
         Exchange exchange = new ExchangeImpl();
         message.setExchange(exchange);        

Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java?view=diff&rev=469449&r1=469448&r2=469449
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
Tue Oct 31 03:25:36 2006
@@ -36,6 +36,7 @@
 import javax.wsdl.xml.WSDLWriter;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.io.AbstractWrappedOutputStream;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
@@ -114,9 +115,9 @@
                 } else {
                     engine.addServant(url, new AbstractHttpHandler() {
                         public void handle(String pathInContext, String pathParams, HttpRequest
req,
-                                           HttpResponse resp) throws IOException {
+                                           HttpResponse resp) throws IOException {      
                     
                             if (pathInContext.startsWith(getName())) {
-                                doService(req, resp, getName());
+                                doService(req, resp);
                             }
                         }
                     });
@@ -228,10 +229,6 @@
     }
 
     protected void doService(HttpRequest req, HttpResponse resp) throws IOException {
-        doService(req, resp, null);
-    }
-
-    protected void doService(HttpRequest req, HttpResponse resp, String pathInContext) throws
IOException {
         if (getServer().isSetRedirectURL()) {
             resp.sendRedirect(getServer().getRedirectURL());
             resp.commit();
@@ -260,14 +257,10 @@
         }
 
         // REVISIT: service on executor if associated with endpoint
-        serviceRequest(req, resp, pathInContext);
+        serviceRequest(req, resp);
     }
 
-    protected void serviceRequest(final HttpRequest req, final HttpResponse resp) throws
IOException {
-        serviceRequest(req, resp, null);
-    }
-
-    protected void serviceRequest(final HttpRequest req, final HttpResponse resp, String
base)
+    protected void serviceRequest(final HttpRequest req, final HttpResponse resp)
         throws IOException {
         try {
             if (LOG.isLoggable(Level.INFO)) {
@@ -282,7 +275,9 @@
             inMessage.put(Message.PATH_INFO, req.getPath());
             inMessage.put(Message.QUERY_STRING, req.getQuery());
             inMessage.put(Message.CONTENT_TYPE, req.getContentType());
-            inMessage.put(Message.BASE_PATH, base);
+            if (!StringUtils.isEmpty(getAddressValue())) {
+                inMessage.put(Message.BASE_PATH, new URL(getAddressValue()).getPath());
+            }
 
             setHeaders(inMessage);
 

Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPServerEngine.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPServerEngine.java?view=diff&rev=469449&r1=469448&r2=469449
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPServerEngine.java
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPServerEngine.java
Tue Oct 31 03:25:36 2006
@@ -26,6 +26,7 @@
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.configuration.Configurer;
+import org.apache.cxf.transport.HttpUriMapper;
 import org.apache.cxf.transport.http.listener.HTTPListenerConfigBean;
 import org.apache.cxf.transports.http.configuration.HTTPListenerPolicy;
 import org.mortbay.http.HttpContext;
@@ -95,9 +96,6 @@
      * @param handler notified on incoming HTTP requests
      */
     public synchronized void addServant(URL url, AbstractHttpHandler handler) {
-
-        String lpath = url.getPath();
-
         if (server == null) {
             server = new HttpServer();
             
@@ -133,16 +131,9 @@
                 }    
             }
         }
-
-        String contextName = "";
-        String servletMap = lpath;
-        int idx = lpath.lastIndexOf('/');
-        if (idx > 0) {
-            contextName = lpath.substring(0, idx);
-            servletMap = lpath.substring(idx);
-        }
-        final String smap = servletMap;
         
+        String contextName = HttpUriMapper.getContextName(url.getPath());
+        final String smap = HttpUriMapper.getResourceBase(url.getPath());
         
         HttpContext context = server.getContext(contextName);
         try {



Mime
View raw message