Repository: cxf Updated Branches: refs/heads/master 09a3b5810 -> a23c615b6
[CXF-6216] Better stripping of matrix params Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/a23c615b Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a23c615b Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a23c615b Branch: refs/heads/master Commit: a23c615b68830edb56855f8edb015fae32616516 Parents: 09a3b58 Author: Sergey Beryozkin <[email protected]> Authored: Tue Oct 18 16:01:45 2016 +0100 Committer: Sergey Beryozkin <[email protected]> Committed: Tue Oct 18 16:01:45 2016 +0100 ---------------------------------------------------------------------- .../rs/service/SampleRestApplication.java | 2 +- .../cxf/transport/servlet/BaseUrlHelper.java | 20 ++++++++------------ .../ServiceListGeneratorServlet.java | 18 +++++++++++++----- .../jaxrs/JAXRSClientServerSpringBookTest.java | 10 ++++++++++ .../src/test/resources/jaxrs/WEB-INF/web.xml | 12 ++++++++++++ 5 files changed, 44 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/a23c615b/distribution/src/main/release/samples/jax_rs/spring_boot/src/main/java/sample/rs/service/SampleRestApplication.java ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot/src/main/java/sample/rs/service/SampleRestApplication.java b/distribution/src/main/release/samples/jax_rs/spring_boot/src/main/java/sample/rs/service/SampleRestApplication.java index 358ca4a..34567f3 100644 --- a/distribution/src/main/release/samples/jax_rs/spring_boot/src/main/java/sample/rs/service/SampleRestApplication.java +++ b/distribution/src/main/release/samples/jax_rs/spring_boot/src/main/java/sample/rs/service/SampleRestApplication.java @@ -45,7 +45,7 @@ public class SampleRestApplication { JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean(); endpoint.setBus(bus); endpoint.setServiceBeans(Arrays.<Object>asList(new HelloServiceImpl1(), new HelloServiceImpl2())); - endpoint.setAddress("/"); + endpoint.setAddress("/a"); endpoint.setFeatures(Arrays.asList(new Swagger2Feature())); return endpoint.create(); } http://git-wip-us.apache.org/repos/asf/cxf/blob/a23c615b/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 bdc6f55..a3c2e85 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 @@ -36,9 +36,8 @@ public final class 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 @@ -47,19 +46,16 @@ public final class BaseUrlHelper { 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; } http://git-wip-us.apache.org/repos/asf/cxf/blob/a23c615b/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 0ab092d..27f14e7 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 @@ -103,12 +103,20 @@ public class ServiceListGeneratorServlet extends HttpServlet { 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 += "/"; } http://git-wip-us.apache.org/repos/asf/cxf/blob/a23c615b/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 5aab183..f3f6058 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 @@ -133,6 +133,16 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest 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 { http://git-wip-us.apache.org/repos/asf/cxf/blob/a23c615b/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/web.xml b/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/web.xml index e872d41..619dc1a 100644 --- a/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/web.xml +++ b/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/web.xml @@ -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> @@ -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 -->
