Skip to content

Commit

Permalink
Better stripping of matrix parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
sberyozkin committed Oct 18, 2016
1 parent 1be97cb commit a30397b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 17 deletions.
Expand Up @@ -36,9 +36,8 @@ private BaseUrlHelper() {
*/
public static String getBaseURL(HttpServletRequest request) {
String reqPrefix = request.getRequestURL().toString();
String pathInfo = request.getPathInfo() == null ? "" : request.getPathInfo();
//fix for CXF-898
if (!"/".equals(pathInfo) || reqPrefix.endsWith("/")) {
String pathInfo = request.getPathInfo();
if (!"/".equals(pathInfo) || reqPrefix.contains(";")) {
StringBuilder sb = new StringBuilder();
// request.getScheme(), request.getLocalName() and request.getLocalPort()
// should be marginally cheaper - provided request.getLocalName() does
Expand All @@ -47,19 +46,16 @@ public static String getBaseURL(HttpServletRequest request) {

URI uri = URI.create(reqPrefix);
sb.append(uri.getScheme()).append("://").append(uri.getRawAuthority());
if (request.getContextPath() != null) {
sb.append(request.getContextPath());
String contextPath = request.getContextPath();
if (contextPath != null) {
sb.append(contextPath);
}
if (request.getServletPath() != null) {
sb.append(request.getServletPath());
String servletPath = request.getServletPath();
if (servletPath != null) {
sb.append(servletPath);
}

reqPrefix = sb.toString();
} else {
int matrixParamIndex = reqPrefix.indexOf(";");
if (matrixParamIndex > 0) {
reqPrefix = reqPrefix.substring(0, matrixParamIndex);
}
}
return reqPrefix;
}
Expand Down
Expand Up @@ -112,12 +112,20 @@ public void service(HttpServletRequest request,
if (serviceListStyleSheet != null) {
styleSheetPath = request.getContextPath() + "/" + serviceListStyleSheet;
} else {
String requestUri = request.getRequestURI();
int matrixParamIndex = requestUri.indexOf(";");
if (matrixParamIndex > 0) {
requestUri = requestUri.substring(0, matrixParamIndex);
styleSheetPath = "";
String contextPath = request.getContextPath();
if (contextPath != null) {
styleSheetPath += contextPath;
}
styleSheetPath = requestUri;
String servletPath = request.getServletPath();
if (servletPath != null) {
styleSheetPath += servletPath;
}
String pathInfo = request.getPathInfo();
if (pathInfo != null) {
styleSheetPath += pathInfo;
}

if (!styleSheetPath.endsWith("/")) {
styleSheetPath += "/";
}
Expand Down
Expand Up @@ -133,6 +133,16 @@ public void testGetServicesPageWithServletPatternMatchOnly() throws Exception {
assertFalse(s.contains(";a=b"));
assertTrue(s.contains("<a href=\"http://localhost:" + PORT + "/the/"));
}
@Test
public void testGetServicesPageWithServletPatternMatchOnly2() throws Exception {
final String address = "http://localhost:" + PORT + "/services;a=b;/list;a=b/;a=b";
WebClient wc = WebClient.create(address).accept("text/*");
String s = wc.get(String.class);
assertTrue(s.contains("href=\"/services/list/?stylesheet=1\""));
assertTrue(s.contains("<title>CXF - Service list</title>"));
assertFalse(s.contains(";a=b"));
assertTrue(s.contains("<a href=\"http://localhost:" + PORT + "/services/list/"));
}

@Test
public void testEchoBookForm() throws Exception {
Expand Down
12 changes: 12 additions & 0 deletions systests/jaxrs/src/test/resources/jaxrs/WEB-INF/web.xml
Expand Up @@ -51,6 +51,14 @@
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>CXFServlet3</servlet-name>
<display-name>CXF Servlet3</display-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/the/*</url-pattern>
Expand All @@ -59,5 +67,9 @@
<servlet-name>CXFServlet2</servlet-name>
<url-pattern>/bus/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CXFServlet3</servlet-name>
<url-pattern>/services/list/*</url-pattern>
</servlet-mapping>
</web-app>
<!-- END SNIPPET: webxml -->

0 comments on commit a30397b

Please sign in to comment.