Skip to content

Commit

Permalink
[CXF-6216] Stripping away the matrix parameters if any from the base URL
Browse files Browse the repository at this point in the history
  • Loading branch information
sberyozkin committed Oct 18, 2016
1 parent 51a2368 commit 1be97cb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
Expand Up @@ -55,6 +55,11 @@ public static String getBaseURL(HttpServletRequest request) {
}

reqPrefix = sb.toString();
} else {
int matrixParamIndex = reqPrefix.indexOf(";");
if (matrixParamIndex > 0) {
reqPrefix = reqPrefix.substring(0, matrixParamIndex);
}
}
return reqPrefix;
}
Expand Down
Expand Up @@ -133,7 +133,11 @@ private String getAbsoluteAddress(String basePath, AbstractDestination d) {
return null;
}
} else {
return basePath + endpointAddress;
String address = basePath;
if (address.endsWith("/") && endpointAddress.startsWith("/")) {
address = address.substring(0, address.length() - 1);
}
return address + endpointAddress;
}
}

Expand Down
Expand Up @@ -111,9 +111,17 @@ public void service(HttpServletRequest request,
String styleSheetPath;
if (serviceListStyleSheet != null) {
styleSheetPath = request.getContextPath() + "/" + serviceListStyleSheet;

} else {
styleSheetPath = request.getRequestURI() + "/?stylesheet=1";
String requestUri = request.getRequestURI();
int matrixParamIndex = requestUri.indexOf(";");
if (matrixParamIndex > 0) {
requestUri = requestUri.substring(0, matrixParamIndex);
}
styleSheetPath = requestUri;
if (!styleSheetPath.endsWith("/")) {
styleSheetPath += "/";
}
styleSheetPath += "?stylesheet=1";
}
serviceListWriter =
new FormattedServiceListWriter(styleSheetPath, title, showForeignContexts, atomMap);
Expand Down
Expand Up @@ -85,7 +85,6 @@ public static void startServers() throws Exception {
public void testGetGenericBook() throws Exception {
String baseAddress = "http://localhost:" + PORT + "/the/thebooks8/books";
WebClient wc = WebClient.create(baseAddress);
WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000);
Long id = wc.type("application/xml").accept("text/plain").post(new Book("CXF", 1L), Long.class);
assertEquals(new Long(1), id);
Book book = wc.replaceHeader("Accept", "application/xml").query("id", 1L).get(Book.class);
Expand All @@ -103,10 +102,38 @@ public void testGetBookWebEx() throws Exception {
public void testGetBookText() throws Exception {
final String address = "http://localhost:" + PORT + "/the/thebooks/bookstore/books/text";
WebClient wc = WebClient.create(address).accept("text/*");
WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000);
assertEquals(406, wc.get().getStatus());

}

@Test
public void testGetServicesPageNotFound() throws Exception {
final String address = "http://localhost:" + PORT + "/the/services;a=b";
WebClient wc = WebClient.create(address).accept("text/*");
WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000);
assertEquals(404, wc.get().getStatus());
}
@Test
public void testGetServicesPage() throws Exception {
final String address = "http://localhost:" + PORT + "/the/services";
WebClient wc = WebClient.create(address).accept("text/*");
String s = wc.get(String.class);
assertTrue(s.contains("href=\"/the/services/?stylesheet=1\""));
assertTrue(s.contains("<title>CXF - Service list</title>"));
assertTrue(s.contains("<a href=\"http://localhost:" + PORT + "/the/"));
}
@Test
public void testGetServicesPageWithServletPatternMatchOnly() throws Exception {
final String address = "http://localhost:" + PORT + "/the/;a=b";
WebClient wc = WebClient.create(address).accept("text/*");
String s = wc.get(String.class);
assertTrue(s.contains("href=\"/the/?stylesheet=1\""));
assertTrue(s.contains("<title>CXF - Service list</title>"));
assertFalse(s.contains(";a=b"));
assertTrue(s.contains("<a href=\"http://localhost:" + PORT + "/the/"));
}

@Test
public void testEchoBookForm() throws Exception {
String address = "http://localhost:" + PORT + "/bus/thebooksform/bookform";
Expand Down

0 comments on commit 1be97cb

Please sign in to comment.