Author: sergeyb
Date: Tue Mar 15 16:28:22 2011
New Revision: 1081841

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

........
  r1081825 | sergeyb | 2011-03-15 16:02:03 +0000 (Tue, 15 Mar 2011) | 1 line
  
  [CXF-3403] Using context and servlet path for the baseURL calculation
........

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

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Mar 15 16:28:22 2011
@@ -1 +1 @@
-/cxf/trunk:1081787
+/cxf/trunk:1081787,1081825

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

Modified: 
cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractServletController.java
URL: 
http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractServletController.java?rev=1081841&r1=1081840&r2=1081841&view=diff
==============================================================================
--- 
cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractServletController.java
 (original)
+++ 
cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractServletController.java
 Tue Mar 15 16:28:22 2011
@@ -23,7 +23,6 @@ import javax.servlet.ServletConfig;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.common.util.UrlUtils;
 
 public abstract class AbstractServletController {
     
@@ -100,33 +99,17 @@ public abstract class AbstractServletCon
         String pathInfo = request.getPathInfo() == null ? "" : 
request.getPathInfo();
         //fix for CXF-898
         if (!"/".equals(pathInfo) || reqPrefix.endsWith("/")) {
-            // needs to be done given that pathInfo is decoded
-            // TODO : it's unlikely servlet path will contain encoded values 
so we're most 
-            // likely safe however we need to ensure if it happens then this 
code works properly too
-            reqPrefix = UrlUtils.pathDecode(reqPrefix);
-            // pathInfo drops matrix parameters attached to a last path segment
-            int offset = 0;
-            int index = getMatrixParameterIndex(reqPrefix, pathInfo);
-            if (index >= pathInfo.length()) {
-                offset = reqPrefix.length() - index;
+            String basePath = request.getContextPath() + 
request.getServletPath();
+            int index;
+            if (basePath.length() == 0) {
+                index = reqPrefix.indexOf(request.getRequestURI());
+            } else {
+                index = reqPrefix.indexOf(basePath);
             }
-            reqPrefix = reqPrefix.substring(0, reqPrefix.length() - 
pathInfo.length() - offset);
+            reqPrefix = reqPrefix.substring(0, index + basePath.length());
         }
         return reqPrefix;
     }
     
-    private int getMatrixParameterIndex(String reqPrefix, String pathInfo) {
-        int index = reqPrefix.lastIndexOf(';');
-        int lastIndex = -1;
-        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.3.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java
URL: 
http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java?rev=1081841&r1=1081840&r2=1081841&view=diff
==============================================================================
--- 
cxf/branches/2.3.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java
 (original)
+++ 
cxf/branches/2.3.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java
 Tue Mar 15 16:28:22 2011
@@ -117,6 +117,10 @@ public class ServletControllerTest exten
             new StringBuffer("http://localhost:8080/services/bar";)).times(2);
         req.getPathInfo();
         EasyMock.expectLastCall().andReturn("/bar").anyTimes();
+        req.getContextPath();
+        EasyMock.expectLastCall().andReturn("");
+        req.getServletPath();
+        EasyMock.expectLastCall().andReturn("/services");
         EasyMock.replay(req);
         String url = new ServletController().getBaseURL(req);
         assertEquals("http://localhost:8080/services";, url);
@@ -130,6 +134,10 @@ public class ServletControllerTest exten
             new 
StringBuffer("http://localhost:8080/services/bar;a=b";)).times(2);
         req.getPathInfo();
         EasyMock.expectLastCall().andReturn("/bar").anyTimes();
+        req.getContextPath();
+        EasyMock.expectLastCall().andReturn("");
+        req.getServletPath();
+        EasyMock.expectLastCall().andReturn("/services");
         EasyMock.replay(req);
         String url = new ServletController().getBaseURL(req);
         assertEquals("http://localhost:8080/services";, url);
@@ -143,6 +151,10 @@ public class ServletControllerTest exten
             new 
StringBuffer("http://localhost:8080/services/bar;a=b;c=d;e=f";)).times(2);       
 
         req.getPathInfo();
         EasyMock.expectLastCall().andReturn("/bar").anyTimes();
+        req.getContextPath();
+        EasyMock.expectLastCall().andReturn("");
+        req.getServletPath();
+        EasyMock.expectLastCall().andReturn("/services");
         EasyMock.replay(req);
         String url = new ServletController().getBaseURL(req);
         assertEquals("http://localhost:8080/services";, url);
@@ -156,6 +168,10 @@ public class ServletControllerTest exten
             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();
+        req.getContextPath();
+        EasyMock.expectLastCall().andReturn("");
+        req.getServletPath();
+        EasyMock.expectLastCall().andReturn("/services");
         EasyMock.replay(req);
         String url = new ServletController().getBaseURL(req);
         assertEquals("http://localhost:8080/services";, url);
@@ -169,6 +185,10 @@ public class ServletControllerTest exten
             new 
StringBuffer("http://localhost:8080/services/bar;a=b;c=d;e=f";)).times(2);       
 
         req.getPathInfo();
         EasyMock.expectLastCall().andReturn("/bar;a=b").anyTimes();
+        req.getContextPath();
+        EasyMock.expectLastCall().andReturn("");
+        req.getServletPath();
+        EasyMock.expectLastCall().andReturn("/services");
         EasyMock.replay(req);
         String url = new ServletController().getBaseURL(req);
         assertEquals("http://localhost:8080/services";, url);
@@ -182,6 +202,10 @@ public class ServletControllerTest exten
             new 
StringBuffer("http://localhost:8080/services/bar;a=b;c=d;e=f;";)).times(2);      
  
         req.getPathInfo();
         EasyMock.expectLastCall().andReturn("/bar;a=b").anyTimes();
+        req.getContextPath();
+        EasyMock.expectLastCall().andReturn("");
+        req.getServletPath();
+        EasyMock.expectLastCall().andReturn("/services");
         EasyMock.replay(req);
         String url = new ServletController().getBaseURL(req);
         assertEquals("http://localhost:8080/services";, url);


Reply via email to