Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 51a2368c1 -> 1be97cb13


[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/1be97cb1
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/1be97cb1
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/1be97cb1

Branch: refs/heads/3.0.x-fixes
Commit: 1be97cb13aef121b799b1be4d9793c0e8b925a12
Parents: 51a2368
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:07: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/1be97cb1/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/1be97cb1/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 7903f86..2045ce9 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 @@ 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/1be97cb1/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 8912fb3..c952d75 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 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, atomMap);

http://git-wip-us.apache.org/repos/asf/cxf/blob/1be97cb1/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 bb0b82e..1f3082e 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);

Reply via email to