Repository: cxf Updated Branches: refs/heads/3.1.x-fixes ae102f9e8 -> 32e89366e
[CXF-6216] Stripping away the matrix parameters if any from the base URL Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/32e89366 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/32e89366 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/32e89366 Branch: refs/heads/3.1.x-fixes Commit: 32e89366e2daa5670ac7a5c5c19f0bf9329a4c1e Parents: ae102f9 Author: Sergey Beryozkin <sberyoz...@gmail.com> Authored: Tue Oct 18 13:04:04 2016 +0100 Committer: Sergey Beryozkin <sberyoz...@gmail.com> Committed: Tue Oct 18 13:06:28 2016 +0100 ---------------------------------------------------------------------- .../cxf/transport/servlet/BaseUrlHelper.java | 5 ++++ .../servicelist/FormattedServiceListWriter.java | 6 +++- .../ServiceListGeneratorServlet.java | 12 ++++++-- .../jaxrs/JAXRSClientServerSpringBookTest.java | 29 +++++++++++++++++++- 4 files changed, 48 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/32e89366/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/BaseUrlHelper.java ---------------------------------------------------------------------- diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/BaseUrlHelper.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/BaseUrlHelper.java index 4b820c9..bdc6f55 100644 --- a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/BaseUrlHelper.java +++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/BaseUrlHelper.java @@ -55,6 +55,11 @@ public final class BaseUrlHelper { } reqPrefix = sb.toString(); + } else { + int matrixParamIndex = reqPrefix.indexOf(";"); + if (matrixParamIndex > 0) { + reqPrefix = reqPrefix.substring(0, matrixParamIndex); + } } return reqPrefix; } http://git-wip-us.apache.org/repos/asf/cxf/blob/32e89366/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java ---------------------------------------------------------------------- diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java index ae9a4d4..67241b4 100644 --- a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java +++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java @@ -146,7 +146,11 @@ public class FormattedServiceListWriter implements ServiceListWriter { return null; } } else { - return basePath + endpointAddress; + String address = basePath; + if (address.endsWith("/") && endpointAddress.startsWith("/")) { + address = address.substring(0, address.length() - 1); + } + return address + endpointAddress; } } http://git-wip-us.apache.org/repos/asf/cxf/blob/32e89366/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java ---------------------------------------------------------------------- diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java index 93266fa..0ab092d 100644 --- a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java +++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java @@ -102,9 +102,17 @@ public class ServiceListGeneratorServlet extends HttpServlet { 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, bus); http://git-wip-us.apache.org/repos/asf/cxf/blob/32e89366/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java index 9dae3ae..5aab183 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java @@ -85,7 +85,6 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest 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); @@ -103,11 +102,39 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest 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"; doTestEchoBookForm(address);