You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2022/11/23 21:11:04 UTC

[cxf] branch main updated: Don't use redirect-query-check with the static resource list (#1034)

This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/main by this push:
     new b18d7928c2 Don't use redirect-query-check with the static resource list (#1034)
b18d7928c2 is described below

commit b18d7928c2cfdcd44df8c38efdc4cd9333873942
Author: Colm O hEigeartaigh <co...@users.noreply.github.com>
AuthorDate: Wed Nov 23 21:10:59 2022 +0000

    Don't use redirect-query-check with the static resource list (#1034)
---
 .../cxf/transport/servlet/AbstractHTTPServlet.java   |  8 ++++----
 .../jaxrs/JAXRSClientServerSpringBookTest.java       | 10 ++++++++++
 .../jaxrs/src/test/resources/jaxrs/WEB-INF/web.xml   | 20 ++++++++++++++++++++
 3 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
index 5630693175..50bc968cb8 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
@@ -284,14 +284,14 @@ public abstract class AbstractHTTPServlet extends HttpServlet implements Filter
     protected void handleRequest(HttpServletRequest request, HttpServletResponse response)
         throws ServletException {
         if ((dispatcherServletPath != null || dispatcherServletName != null)
-            && (redirectList != null && matchPath(redirectList, request)
+            && (redirectList != null && matchPath(redirectQueryCheck, redirectList, request)
                 || redirectList == null)) {
             // if no redirectList is provided then this servlet is redirecting only
             redirect(request, response, request.getPathInfo());
             return;
         }
         boolean staticResourcesMatch = staticResourcesList != null
-            && matchPath(staticResourcesList, request);
+            && matchPath(false, staticResourcesList, request);
         boolean staticWelcomeFileMatch = staticWelcomeFile != null
             && (StringUtils.isEmpty(request.getPathInfo()) || "/".equals(request.getPathInfo()));
         if (staticResourcesMatch || staticWelcomeFileMatch) {
@@ -328,12 +328,12 @@ public abstract class AbstractHTTPServlet extends HttpServlet implements Filter
     }
 
 
-    private boolean matchPath(List<Pattern> values, HttpServletRequest request) {
+    private static boolean matchPath(boolean checkRedirect, List<Pattern> values, HttpServletRequest request) {
         String path = request.getPathInfo();
         if (path == null) {
             path = "/";
         }
-        if (redirectQueryCheck) {
+        if (checkRedirect) {
             String queryString = request.getQueryString();
             if (queryString != null && !queryString.isEmpty()) {
                 path += "?" + queryString;
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 731d611f8a..4903aac938 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
@@ -147,6 +147,7 @@ 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";
@@ -158,6 +159,15 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest
         assertTrue(s.contains("<a href=\"http://localhost:" + PORT + "/services/list/"));
     }
 
+    @Test
+    public void testStaticResourcesWithRedirectQueryCheck() throws Exception {
+        final String address = "http://localhost:" + PORT + "/services/?.html";
+        WebClient wc = WebClient.create(address).accept("text/*");
+        String s = wc.get(String.class);
+        // Check we don't have a directory listing
+        assertFalse(s.contains("META-INF"));
+    }
+
     @Test
     public void testEchoBookForm() throws Exception {
         String address = "http://localhost:" + PORT + "/bus/thebooksform/bookform";
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 7ae0013fc7..8372cb93a2 100644
--- a/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/web.xml
+++ b/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/web.xml
@@ -60,6 +60,22 @@
                 </servlet-class>
         <load-on-startup>1</load-on-startup>
     </servlet>
+    <servlet>
+        <servlet-name>CXFServlet4</servlet-name>
+        <display-name>CXF Servlet4</display-name>
+        <servlet-class>
+                        org.apache.cxf.transport.servlet.CXFServlet
+                </servlet-class>
+        <init-param>
+            <param-name>static-resources-list</param-name>
+            <param-value>.*\.html</param-value>
+        </init-param>
+        <init-param>
+            <param-name>redirect-query-check</param-name>
+            <param-value>true</param-value>
+        </init-param>
+        <load-on-startup>1</load-on-startup>
+    </servlet>
     <servlet-mapping>
         <servlet-name>CXFServlet</servlet-name>
         <url-pattern>/the/*</url-pattern>
@@ -72,5 +88,9 @@
         <servlet-name>CXFServlet3</servlet-name>
         <url-pattern>/services/list/*</url-pattern>
     </servlet-mapping>
+    <servlet-mapping>
+        <servlet-name>CXFServlet4</servlet-name>
+        <url-pattern>/services/*</url-pattern>
+    </servlet-mapping>
 </web-app>
 <!-- END SNIPPET: webxml -->