cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1073389 - in /cxf/trunk: rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/ rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ systes...
Date Tue, 22 Feb 2011 16:30:29 GMT
Author: sergeyb
Date: Tue Feb 22 16:30:28 2011
New Revision: 1073389

URL: http://svn.apache.org/viewvc?rev=1073389&view=rev
Log:
[CXF-3357] Improving ServletController updateDests method for multiple endpoints sharing the
same servlet path be supported

Modified:
    cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiServletController.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractServletController.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletTransportFactory.java
    cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAtomBookTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_book_json3.txt
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_atom/WEB-INF/beans.xml

Modified: cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiServletController.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiServletController.java?rev=1073389&r1=1073388&r2=1073389&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiServletController.java
(original)
+++ cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiServletController.java
Tue Feb 22 16:30:28 2011
@@ -19,7 +19,6 @@
 package org.apache.cxf.transport.http_osgi;
 
 import java.io.IOException;
-import java.util.Set;
 import java.util.logging.Logger;
 
 import javax.servlet.ServletConfig;
@@ -38,7 +37,6 @@ import org.apache.cxf.transport.http.Des
 import org.apache.cxf.transport.servlet.AbstractServletController;
 import org.apache.cxf.transports.http.QueryHandler;
 import org.apache.cxf.transports.http.QueryHandlerRegistry;
-import org.apache.cxf.wsdl.http.AddressType;
 
 public class OsgiServletController extends AbstractServletController {
     private static final Logger LOG = LogUtils.getL7dLogger(OsgiServletController.class);
@@ -49,25 +47,7 @@ public class OsgiServletController exten
         super(config, destinationRegistry, serviceListGenerator);
     }
 
-    private synchronized void updateDests(HttpServletRequest request) {
-        if (disableAddressUpdates) {
-            return;
-        }
-        String base = forcedBaseAddress == null ? getBaseURL(request) : forcedBaseAddress;
-
-        Set<String> paths = destinationRegistry.getDestinationsPaths();
-        for (String path : paths) {
-            AbstractHTTPDestination d2 = destinationRegistry.getDestinationForPath(path);
-            String ad = d2.getEndpointInfo().getAddress();
-            if (ad.equals(path)) {
-                d2.getEndpointInfo().setAddress(base + path);
-                if (d2.getEndpointInfo().getExtensor(AddressType.class) != null) {
-                    d2.getEndpointInfo().getExtensor(AddressType.class).setLocation(base
+ path);
-                }
-            }
-        }
-    }
-
+    
     public void invoke(HttpServletRequest request, HttpServletResponse res) throws ServletException
{
         try {
             String address = request.getPathInfo() == null ? "" : request.getPathInfo();
@@ -78,7 +58,7 @@ public class OsgiServletController exten
                     || request.getRequestURI().endsWith(serviceListRelativePath + "/"))
                     || StringUtils.isEmpty(request.getPathInfo())
                     || "/".equals(request.getPathInfo())) {
-                    updateDests(request);
+                    updateDests(request, true);
                     serviceListGenerator.service(request, res);
                 } else {
                     d = destinationRegistry.checkRestfulRequest(address);

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java?rev=1073389&r1=1073388&r2=1073389&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
Tue Feb 22 16:30:28 2011
@@ -61,7 +61,6 @@ public abstract class AbstractCXFServlet
             new ServletController(servletTransportFactory.getRegistry(),
                                   servletConfig,
                                   serviceListGeneratorServlet);
-        servletTransportFactory.setServletController(newController);
         if (servletConfig.getInitParameter("disable-address-updates") == null) {
             newController.setDisableAddressUpdates(disableAddressUpdates);
         }

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractServletController.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractServletController.java?rev=1073389&r1=1073388&r2=1073389&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractServletController.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractServletController.java
Tue Feb 22 16:30:28 2011
@@ -21,6 +21,7 @@ package org.apache.cxf.transport.servlet
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -38,6 +39,8 @@ import org.apache.cxf.transport.http.Abs
 import org.apache.cxf.transport.http.DestinationRegistry;
 import org.apache.cxf.transports.http.QueryHandler;
 import org.apache.cxf.transports.http.QueryHandlerRegistry;
+import org.apache.cxf.wsdl.WSDLLibrary;
+import org.apache.cxf.wsdl.http.AddressType;
 
 public abstract class AbstractServletController {
     protected static final String DEFAULT_LISTINGS_CLASSIFIER = "/services";
@@ -83,6 +86,50 @@ public abstract class AbstractServletCon
         title = t;
     }
     
+    protected synchronized void updateDests(HttpServletRequest request) {
+        updateDests(request, false);
+    }
+    
+    protected synchronized void updateDests(HttpServletRequest request, boolean force) {
+        
+        String base = forcedBaseAddress == null ? getBaseURL(request) : forcedBaseAddress;
+                
+        String pathInfo = request.getPathInfo();
+        if (pathInfo == null) {
+            pathInfo = "/";
+        }
+        
+        Set<String> paths = destinationRegistry.getDestinationsPaths();
+        for (String path : paths) {
+            if (!force && pathInfo != null && !pathInfo.startsWith(path))
{
+                continue;
+            }
+            AbstractHTTPDestination d2 = destinationRegistry.getDestinationForPath(path);
+            String ad = d2.getEndpointInfo().getAddress();
+            if (ad == null 
+                && d2.getAddress() != null
+                && d2.getAddress().getAddress() != null) {
+                ad = d2.getAddress().getAddress().getValue();
+                if (ad == null) {
+                    ad = "/";
+                }
+            }
+            if (ad != null 
+                && (ad.equals(path))) {
+                if (disableAddressUpdates) {
+                    request.setAttribute("org.apache.cxf.transport.endpoint.address", 
+                                         base + path);
+                } else {
+                    d2.getEndpointInfo().setAddress(base + path);
+                    if (WSDLLibrary.isAvailable() 
+                        && d2.getEndpointInfo().getExtensor(AddressType.class) !=
null) {
+                        d2.getEndpointInfo().getExtensor(AddressType.class).setLocation(base
+ path);
+                    }
+                }
+            }
+        }
+    }
+    
     private void init() {
         if (servletConfig == null) {
             return;

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java?rev=1073389&r1=1073388&r2=1073389&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
Tue Feb 22 16:30:28 2011
@@ -20,7 +20,6 @@ package org.apache.cxf.transport.servlet
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -39,13 +38,10 @@ import org.apache.cxf.transport.http.Abs
 import org.apache.cxf.transport.http.DestinationRegistry;
 import org.apache.cxf.transports.http.QueryHandler;
 import org.apache.cxf.transports.http.QueryHandlerRegistry;
-import org.apache.cxf.wsdl.WSDLLibrary;
-import org.apache.cxf.wsdl.http.AddressType;
 
 public class ServletController extends AbstractServletController {
     
     private static final Logger LOG = LogUtils.getL7dLogger(ServletController.class);  
-    private volatile String lastBase = "";
     
     public ServletController(DestinationRegistry destinationRegistry,
                              ServletConfig config, 
@@ -53,67 +49,24 @@ public class ServletController extends A
         super(config, destinationRegistry, serviceListGeneratorServlet);
     }
         
-    String getLastBaseURL() {
-        return lastBase;
-    }
-    
-    protected synchronized void updateDests(HttpServletRequest request) {
-        
-        String base = forcedBaseAddress == null ? getBaseURL(request) : forcedBaseAddress;
-                
-        if (base.equals(lastBase)) {
-            return;
-        }
-        Set<String> paths = destinationRegistry.getDestinationsPaths();
-        for (String path : paths) {
-            AbstractHTTPDestination d2 = destinationRegistry.getDestinationForPath(path);
-            String ad = d2.getEndpointInfo().getAddress();
-            if (ad == null 
-                && d2.getAddress() != null
-                && d2.getAddress().getAddress() != null) {
-                ad = d2.getAddress().getAddress().getValue();
-                if (ad == null) {
-                    ad = "/";
-                }
-            }
-            if (ad != null 
-                && (ad.equals(path)
-                || ad.equals(lastBase + path))) {
-                if (disableAddressUpdates) {
-                    request.setAttribute("org.apache.cxf.transport.endpoint.address", base
+ path);
-                } else {
-                    d2.getEndpointInfo().setAddress(base + path);
-                    if (WSDLLibrary.isAvailable() 
-                        && d2.getEndpointInfo().getExtensor(AddressType.class) !=
null) {
-                        d2.getEndpointInfo().getExtensor(AddressType.class).setLocation(base
+ path);
-                    }
-                }
-            }
-        }
-        if (disableAddressUpdates) {
-            return;
-        }
-        lastBase = base;
-    }
-
     public void invoke(HttpServletRequest request, HttpServletResponse res) 
         throws ServletException {
         try {
             EndpointInfo ei = new EndpointInfo();
             
-            String address = request.getPathInfo() == null ? "" : request.getPathInfo();
-            ei.setAddress(address);
+            String pathInfo = request.getPathInfo() == null ? "" : request.getPathInfo();
+            ei.setAddress(pathInfo);
             
             AbstractHTTPDestination d = destinationRegistry.getDestinationForPath(ei.getAddress(),
true);
             if (d == null) {
                 if (!isHideServiceList && (request.getRequestURI().endsWith(serviceListRelativePath)
                     || request.getRequestURI().endsWith(serviceListRelativePath + "/")
-                    || StringUtils.isEmpty(request.getPathInfo())
-                    || "/".equals(request.getPathInfo()))) {
-                    updateDests(request);
+                    || StringUtils.isEmpty(pathInfo)
+                    || "/".equals(pathInfo))) {
+                    updateDests(request, true);
                     serviceListGenerator.service(request, res);
                 } else {
-                    d = destinationRegistry.checkRestfulRequest(address);
+                    d = destinationRegistry.checkRestfulRequest(pathInfo);
                     if (d == null) {                        
                         LOG.warning("Can't find the request for " 
                                     + request.getRequestURL() + "'s Observer ");

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletTransportFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletTransportFactory.java?rev=1073389&r1=1073388&r2=1073389&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletTransportFactory.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletTransportFactory.java
Tue Feb 22 16:30:28 2011
@@ -27,19 +27,15 @@ import java.util.List;
 import javax.annotation.Resource;
 
 import org.apache.cxf.Bus;
-import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.Destination;
 import org.apache.cxf.transport.DestinationFactory;
 import org.apache.cxf.transport.http.AbstractHTTPDestination;
 import org.apache.cxf.transport.http.AbstractHTTPTransportFactory;
-import org.apache.cxf.wsdl.http.AddressType;
 
 public class ServletTransportFactory extends AbstractHTTPTransportFactory
     implements DestinationFactory {
    
-    private ServletController controller;
-    
     public ServletTransportFactory(Bus b) {
         super.setBus(b);
         List<String> ids = Arrays.asList(new String[] {
@@ -54,10 +50,6 @@ public class ServletTransportFactory ext
     public ServletTransportFactory() {
     }
    
-    public void setServletController(ServletController c) {
-        controller = c;
-    }
-
     @Resource(name = "cxf")
     public void setBus(Bus b) {
         super.setBus(b);
@@ -70,20 +62,6 @@ public class ServletTransportFactory ext
             String path = registry.getTrimmedPath(endpointInfo.getAddress());
             d = new ServletDestination(getBus(), registry, endpointInfo, path);
             registry.addDestination(path, d);
-
-            if (controller != null
-                && !StringUtils.isEmpty(controller.getLastBaseURL())) {
-                String ad = d.getEndpointInfo().getAddress();
-                if (ad != null 
-                    && (ad.equals(path)
-                    || ad.equals(controller.getLastBaseURL() + path))) {
-                    d.getEndpointInfo().setAddress(controller.getLastBaseURL() + path);
-                    if (d.getEndpointInfo().getExtensor(AddressType.class) != null) {
-                        d.getEndpointInfo().getExtensor(AddressType.class)
-                            .setLocation(controller.getLastBaseURL() + path);
-                    }
-                }
-            }
         }
         return d;
     }

Modified: cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java?rev=1073389&r1=1073388&r2=1073389&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java
(original)
+++ cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java
Tue Feb 22 16:30:28 2011
@@ -19,6 +19,7 @@
 package org.apache.cxf.transport.servlet;
 
 import java.io.IOException;
+import java.util.Collections;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
@@ -50,13 +51,19 @@ public class ServletControllerTest exten
     
     private void setReq(String pathInfo, String requestUri, String styleSheet, String formatted)
{
         req.getPathInfo();
-        EasyMock.expectLastCall().andReturn(pathInfo);
+        EasyMock.expectLastCall().andReturn(pathInfo).anyTimes();
         req.getRequestURI();
         EasyMock.expectLastCall().andReturn(requestUri);
         req.getParameter("stylesheet");
         EasyMock.expectLastCall().andReturn(styleSheet);
         req.getParameter("formatted");
         EasyMock.expectLastCall().andReturn(formatted);
+        req.getRequestURL();
+        EasyMock.expectLastCall().andReturn(new StringBuffer("http://localhost:8080" + requestUri));
+        registry.getDestinationsPaths();
+        EasyMock.expectLastCall().andReturn(Collections.emptySet()).atLeastOnce();
+        registry.getDestinationForPath("", true);
+        EasyMock.expectLastCall().andReturn(null).anyTimes();
     }
     
     private void expectServiceListGeneratorCalled() throws ServletException, IOException
{
@@ -72,7 +79,7 @@ public class ServletControllerTest exten
     public void testGenerateServiceListing() throws Exception {
         setReq(null, "/services", null, "true");
         expectServiceListGeneratorCalled();
-        EasyMock.replay(req, serviceListGenerator);
+        EasyMock.replay(req, registry, serviceListGenerator);
         TestServletController sc = new TestServletController(registry, serviceListGenerator);
         sc.invoke(req, res);
         assertFalse(sc.invokeDestinationCalled());
@@ -81,16 +88,22 @@ public class ServletControllerTest exten
     @Test
     public void testGenerateUnformattedServiceListing() throws Exception {
         req.getPathInfo();
-        EasyMock.expectLastCall().andReturn(null);
+        EasyMock.expectLastCall().andReturn(null).anyTimes();
         req.getRequestURI();
         EasyMock.expectLastCall().andReturn("/services");
         req.getParameter("stylesheet");
         EasyMock.expectLastCall().andReturn(null);
         req.getParameter("formatted");
         EasyMock.expectLastCall().andReturn("false");
+        req.getRequestURL();
+        EasyMock.expectLastCall().andReturn(new StringBuffer("http://localhost:8080/services"));
+        registry.getDestinationsPaths();
+        EasyMock.expectLastCall().andReturn(Collections.emptySet()).atLeastOnce();
+        registry.getDestinationForPath("", true);
+        EasyMock.expectLastCall().andReturn(null).anyTimes();
         
         expectServiceListGeneratorCalled();
-        EasyMock.replay(req, serviceListGenerator);
+        EasyMock.replay(req, registry, serviceListGenerator);
         
         TestServletController sc = new TestServletController(registry, serviceListGenerator);
         sc.invoke(req, res);
@@ -121,7 +134,7 @@ public class ServletControllerTest exten
     public void testDifferentServiceListPath() throws Exception {
         setReq(null, "/listing", null, "true");
         expectServiceListGeneratorCalled();
-        EasyMock.replay(req, serviceListGenerator);
+        EasyMock.replay(req, registry, serviceListGenerator);
         TestServletController sc = new TestServletController(registry, serviceListGenerator);
         sc.setServiceListRelativePath("/listing");
         sc.invoke(req, res);

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAtomBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAtomBookTest.java?rev=1073389&r1=1073388&r2=1073389&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAtomBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAtomBookTest.java
Tue Feb 22 16:30:28 2011
@@ -50,7 +50,7 @@ public class JAXRSAtomBookTest extends A
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly",
-                   launchServer(AtomBookServer.class));
+                   launchServer(AtomBookServer.class, true));
     }
     
     @Test
@@ -145,7 +145,7 @@ public class JAXRSAtomBookTest extends A
     
     @Test
     public void testGetBooks3() throws Exception {
-        getAndCompareJson("http://localhost:" + PORT + "/atom/atom/books/entries/123.json",
+        getAndCompareJson("http://localhost:" + PORT + "/atom/atomservice3/atom/books/entries/123.json",
                         "resources/expected_atom_book_json3.txt",
                         "*/*");
     }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_book_json3.txt
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_book_json3.txt?rev=1073389&r1=1073388&r2=1073389&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_book_json3.txt
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_book_json3.txt
Tue Feb 22 16:30:28 2011
@@ -9,6 +9,6 @@
   ]
  },
  "attributes":{
-  "xml:base":"http://localhost:9080/atom/atom/books/entries/123"
+  "xml:base":"http://localhost:9080/atom/atomservice3/atom/books/entries/123"
  }
 }
\ No newline at end of file

Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_atom/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_atom/WEB-INF/beans.xml?rev=1073389&r1=1073388&r2=1073389&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_atom/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_atom/WEB-INF/beans.xml Tue Feb 22 16:30:28
2011
@@ -69,7 +69,7 @@ http://cxf.apache.org/schemas/jaxrs.xsd"
   </jaxrs:server>
   
   <jaxrs:server id="atomservice3"
-		        address="/">
+		        address="/atomservice3">
     <jaxrs:serviceBeans>
       <ref bean="atomstore3"/>
     </jaxrs:serviceBeans>



Mime
View raw message