You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2009/07/23 19:41:21 UTC

svn commit: r797163 - in /cxf/branches/2.2.x-fixes: ./ rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java

Author: sergeyb
Date: Thu Jul 23 17:41:21 2009
New Revision: 797163

URL: http://svn.apache.org/viewvc?rev=797163&view=rev
Log:
Merged revisions 797159 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r797159 | sergeyb | 2009-07-23 18:34:09 +0100 (Thu, 23 Jul 2009) | 1 line
  
  CXF-2355 : fixing an issue with multiple matrix parameters on the last segment
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
    cxf/branches/2.2.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jul 23 17:41:21 2009
@@ -1 +1 @@
-/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396,794680,794728,794771,794778-794780,794892,795044,795104,795160,795583,795907,796022-796023,796352,796593,796741,796994-796997,797117
+/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396,794680,794728,794771,794778-794780,794892,795044,795104,795160,795583,795907,796022-796023,796352,796593,796741,796994-796997,797117,797159

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java?rev=797163&r1=797162&r2=797163&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java (original)
+++ cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java Thu Jul 23 17:41:21 2009
@@ -402,7 +402,7 @@
         }
     }
     
-    private String getBaseURL(HttpServletRequest request) {
+    protected String getBaseURL(HttpServletRequest request) {
         String reqPrefix = request.getRequestURL().toString();        
         String pathInfo = request.getPathInfo() == null ? "" : request.getPathInfo();
         //fix for CXF-898
@@ -413,7 +413,7 @@
             reqPrefix = UrlUtils.pathDecode(reqPrefix);
             // pathInfo drops matrix parameters attached to a last path segment
             int offset = 0;
-            int index = getMatrixParameterIndex(reqPrefix, pathInfo.length());
+            int index = getMatrixParameterIndex(reqPrefix, pathInfo);
             if (index >= pathInfo.length()) {
                 offset = reqPrefix.length() - index;
             }
@@ -422,12 +422,15 @@
         return reqPrefix;
     }
     
-    private int getMatrixParameterIndex(String reqPrefix, int pathInfoLength) {
+    private int getMatrixParameterIndex(String reqPrefix, String pathInfo) {
         int index = reqPrefix.lastIndexOf(';');
         int lastIndex = -1;
-        while (index >= pathInfoLength) {
+        while (index >= pathInfo.length()) {
             lastIndex = index;
             reqPrefix = reqPrefix.substring(0, index);
+            if (reqPrefix.endsWith(pathInfo)) {
+                break;
+            }
             index = reqPrefix.lastIndexOf(';');
         }
         return lastIndex;

Modified: cxf/branches/2.2.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java?rev=797163&r1=797162&r2=797163&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java (original)
+++ cxf/branches/2.2.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java Thu Jul 23 17:41:21 2009
@@ -40,12 +40,12 @@
     public void setUp() {
         req = EasyMock.createMock(HttpServletRequest.class);
         res = EasyMock.createMock(HttpServletResponse.class);
-        req.getPathInfo();
-        EasyMock.expectLastCall().andReturn(null);
     }
     
     @Test
     public void testGenerateServiceListing() throws Exception {
+        req.getPathInfo();
+        EasyMock.expectLastCall().andReturn(null);
         req.getRequestURI();
         EasyMock.expectLastCall().andReturn("/services");
         req.getParameter("stylesheet");
@@ -62,6 +62,8 @@
     
     @Test
     public void testGenerateUnformattedServiceListing() throws Exception {
+        req.getPathInfo();
+        EasyMock.expectLastCall().andReturn(null);
         req.getRequestURI();
         EasyMock.expectLastCall().andReturn("/services");
         req.getParameter("stylesheet");
@@ -78,6 +80,8 @@
     
     @Test
     public void testHideServiceListing() throws Exception {
+        req.getPathInfo();
+        EasyMock.expectLastCall().andReturn(null);
         EasyMock.replay(req);
         TestServletController sc = new TestServletController();
         sc.setHideServiceList(true);
@@ -89,6 +93,8 @@
     
     @Test
     public void testDifferentServiceListPath() throws Exception {
+        req.getPathInfo();
+        EasyMock.expectLastCall().andReturn(null);
         req.getRequestURI();
         EasyMock.expectLastCall().andReturn("/listing");
         req.getParameter("stylesheet");
@@ -104,6 +110,84 @@
         assertFalse(sc.invokeDestinationCalled());
     }
     
+    @Test
+    public void testGetRequestURL() throws Exception {
+        req.getRequestURL();
+        EasyMock.expectLastCall().andReturn(
+            new StringBuffer("http://localhost:8080/services/bar")).times(2);
+        req.getPathInfo();
+        EasyMock.expectLastCall().andReturn("/bar").anyTimes();
+        EasyMock.replay(req);
+        String url = new ServletController().getBaseURL(req);
+        assertEquals("http://localhost:8080/services", url);
+        
+    }
+    
+    @Test
+    public void testGetRequestURLSingleMatrixParam() throws Exception {
+        req.getRequestURL();
+        EasyMock.expectLastCall().andReturn(
+            new StringBuffer("http://localhost:8080/services/bar;a=b")).times(2);
+        req.getPathInfo();
+        EasyMock.expectLastCall().andReturn("/bar").anyTimes();
+        EasyMock.replay(req);
+        String url = new ServletController().getBaseURL(req);
+        assertEquals("http://localhost:8080/services", url);
+        
+    }
+    
+    @Test
+    public void testGetRequestURLMultipleMatrixParam() throws Exception {
+        req.getRequestURL();
+        EasyMock.expectLastCall().andReturn(
+            new StringBuffer("http://localhost:8080/services/bar;a=b;c=d;e=f")).times(2);        
+        req.getPathInfo();
+        EasyMock.expectLastCall().andReturn("/bar").anyTimes();
+        EasyMock.replay(req);
+        String url = new ServletController().getBaseURL(req);
+        assertEquals("http://localhost:8080/services", url);
+        
+    }
+    
+    @Test
+    public void testGetRequestURLMultipleMatrixParam2() throws Exception {
+        req.getRequestURL();
+        EasyMock.expectLastCall().andReturn(
+            new StringBuffer("http://localhost:8080/services/bar;a=b;c=d;e=f")).times(2);        
+        req.getPathInfo();
+        EasyMock.expectLastCall().andReturn("/bar;a=b;c=d").anyTimes();
+        EasyMock.replay(req);
+        String url = new ServletController().getBaseURL(req);
+        assertEquals("http://localhost:8080/services", url);
+        
+    }
+    
+    @Test
+    public void testGetRequestURLMultipleMatrixParam3() throws Exception {
+        req.getRequestURL();
+        EasyMock.expectLastCall().andReturn(
+            new StringBuffer("http://localhost:8080/services/bar;a=b;c=d;e=f")).times(2);        
+        req.getPathInfo();
+        EasyMock.expectLastCall().andReturn("/bar;a=b").anyTimes();
+        EasyMock.replay(req);
+        String url = new ServletController().getBaseURL(req);
+        assertEquals("http://localhost:8080/services", url);
+        
+    }
+    
+    @Test
+    public void testGetRequestURLMultipleMatrixParam4() throws Exception {
+        req.getRequestURL();
+        EasyMock.expectLastCall().andReturn(
+            new StringBuffer("http://localhost:8080/services/bar;a=b;c=d;e=f;")).times(2);        
+        req.getPathInfo();
+        EasyMock.expectLastCall().andReturn("/bar;a=b").anyTimes();
+        EasyMock.replay(req);
+        String url = new ServletController().getBaseURL(req);
+        assertEquals("http://localhost:8080/services", url);
+        
+    }
+    
     public static class TestServletController extends ServletController {
         
         private boolean generateListCalled;