Skip to content

Commit a30397b

Browse files
committed
Better stripping of matrix parameters
1 parent 1be97cb commit a30397b

File tree

4 files changed

+43
-17
lines changed

4 files changed

+43
-17
lines changed

rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/BaseUrlHelper.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ private BaseUrlHelper() {
3636
*/
3737
public static String getBaseURL(HttpServletRequest request) {
3838
String reqPrefix = request.getRequestURL().toString();
39-
String pathInfo = request.getPathInfo() == null ? "" : request.getPathInfo();
40-
//fix for CXF-898
41-
if (!"/".equals(pathInfo) || reqPrefix.endsWith("/")) {
39+
String pathInfo = request.getPathInfo();
40+
if (!"/".equals(pathInfo) || reqPrefix.contains(";")) {
4241
StringBuilder sb = new StringBuilder();
4342
// request.getScheme(), request.getLocalName() and request.getLocalPort()
4443
// should be marginally cheaper - provided request.getLocalName() does
@@ -47,19 +46,16 @@ public static String getBaseURL(HttpServletRequest request) {
4746

4847
URI uri = URI.create(reqPrefix);
4948
sb.append(uri.getScheme()).append("://").append(uri.getRawAuthority());
50-
if (request.getContextPath() != null) {
51-
sb.append(request.getContextPath());
49+
String contextPath = request.getContextPath();
50+
if (contextPath != null) {
51+
sb.append(contextPath);
5252
}
53-
if (request.getServletPath() != null) {
54-
sb.append(request.getServletPath());
53+
String servletPath = request.getServletPath();
54+
if (servletPath != null) {
55+
sb.append(servletPath);
5556
}
5657

5758
reqPrefix = sb.toString();
58-
} else {
59-
int matrixParamIndex = reqPrefix.indexOf(";");
60-
if (matrixParamIndex > 0) {
61-
reqPrefix = reqPrefix.substring(0, matrixParamIndex);
62-
}
6359
}
6460
return reqPrefix;
6561
}

rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,20 @@ public void service(HttpServletRequest request,
112112
if (serviceListStyleSheet != null) {
113113
styleSheetPath = request.getContextPath() + "/" + serviceListStyleSheet;
114114
} else {
115-
String requestUri = request.getRequestURI();
116-
int matrixParamIndex = requestUri.indexOf(";");
117-
if (matrixParamIndex > 0) {
118-
requestUri = requestUri.substring(0, matrixParamIndex);
115+
styleSheetPath = "";
116+
String contextPath = request.getContextPath();
117+
if (contextPath != null) {
118+
styleSheetPath += contextPath;
119119
}
120-
styleSheetPath = requestUri;
120+
String servletPath = request.getServletPath();
121+
if (servletPath != null) {
122+
styleSheetPath += servletPath;
123+
}
124+
String pathInfo = request.getPathInfo();
125+
if (pathInfo != null) {
126+
styleSheetPath += pathInfo;
127+
}
128+
121129
if (!styleSheetPath.endsWith("/")) {
122130
styleSheetPath += "/";
123131
}

systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ public void testGetServicesPageWithServletPatternMatchOnly() throws Exception {
133133
assertFalse(s.contains(";a=b"));
134134
assertTrue(s.contains("<a href=\"http://localhost:" + PORT + "/the/"));
135135
}
136+
@Test
137+
public void testGetServicesPageWithServletPatternMatchOnly2() throws Exception {
138+
final String address = "http://localhost:" + PORT + "/services;a=b;/list;a=b/;a=b";
139+
WebClient wc = WebClient.create(address).accept("text/*");
140+
String s = wc.get(String.class);
141+
assertTrue(s.contains("href=\"/services/list/?stylesheet=1\""));
142+
assertTrue(s.contains("<title>CXF - Service list</title>"));
143+
assertFalse(s.contains(";a=b"));
144+
assertTrue(s.contains("<a href=\"http://localhost:" + PORT + "/services/list/"));
145+
}
136146

137147
@Test
138148
public void testEchoBookForm() throws Exception {

systests/jaxrs/src/test/resources/jaxrs/WEB-INF/web.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@
5151
</init-param>
5252
<load-on-startup>1</load-on-startup>
5353
</servlet>
54+
<servlet>
55+
<servlet-name>CXFServlet3</servlet-name>
56+
<display-name>CXF Servlet3</display-name>
57+
<servlet-class>
58+
org.apache.cxf.transport.servlet.CXFServlet
59+
</servlet-class>
60+
<load-on-startup>1</load-on-startup>
61+
</servlet>
5462
<servlet-mapping>
5563
<servlet-name>CXFServlet</servlet-name>
5664
<url-pattern>/the/*</url-pattern>
@@ -59,5 +67,9 @@
5967
<servlet-name>CXFServlet2</servlet-name>
6068
<url-pattern>/bus/*</url-pattern>
6169
</servlet-mapping>
70+
<servlet-mapping>
71+
<servlet-name>CXFServlet3</servlet-name>
72+
<url-pattern>/services/list/*</url-pattern>
73+
</servlet-mapping>
6274
</web-app>
6375
<!-- END SNIPPET: webxml -->

0 commit comments

Comments
 (0)