From 1be97cb13aef121b799b1be4d9793c0e8b925a12 Mon Sep 17 00:00:00 2001 From: Sergey Beryozkin Date: Tue, 18 Oct 2016 13:04:04 +0100 Subject: [PATCH] [CXF-6216] Stripping away the matrix parameters if any from the base URL --- .../cxf/transport/servlet/BaseUrlHelper.java | 5 ++++ .../FormattedServiceListWriter.java | 6 +++- .../ServiceListGeneratorServlet.java | 12 ++++++-- .../JAXRSClientServerSpringBookTest.java | 29 ++++++++++++++++++- 4 files changed, 48 insertions(+), 4 deletions(-) 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 4b820c9f4da..bdc6f551a7b 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 static String getBaseURL(HttpServletRequest request) { } reqPrefix = sb.toString(); + } else { + int matrixParamIndex = reqPrefix.indexOf(";"); + if (matrixParamIndex > 0) { + reqPrefix = reqPrefix.substring(0, matrixParamIndex); + } } return reqPrefix; } 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 7903f86d792..2045ce9e4fb 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 @@ -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; } } 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 8912fb316bc..c952d759c79 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 @@ -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); 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 bb0b82ea30c..1f3082e8545 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 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); @@ -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("CXF - Service list")); + assertTrue(s.contains("CXF - Service list")); + assertFalse(s.contains(";a=b")); + assertTrue(s.contains("