Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 56733 invoked from network); 23 Jul 2009 17:33:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 23 Jul 2009 17:33:30 -0000 Received: (qmail 29186 invoked by uid 500); 23 Jul 2009 17:34:35 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 29110 invoked by uid 500); 23 Jul 2009 17:34:35 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 29101 invoked by uid 99); 23 Jul 2009 17:34:35 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Jul 2009 17:34:35 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Jul 2009 17:34:31 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 105E023888D3; Thu, 23 Jul 2009 17:34:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r797159 - in /cxf/trunk/rt/transports/http/src: main/java/org/apache/cxf/transport/servlet/ServletController.java test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java Date: Thu, 23 Jul 2009 17:34:09 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090723173410.105E023888D3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sergeyb Date: Thu Jul 23 17:34:09 2009 New Revision: 797159 URL: http://svn.apache.org/viewvc?rev=797159&view=rev Log: CXF-2355 : fixing an issue with multiple matrix parameters on the last segment Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java 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=797159&r1=797158&r2=797159&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 Thu Jul 23 17:34:09 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/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=797159&r1=797158&r2=797159&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 Thu Jul 23 17:34:09 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;