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;