cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Optionally ignoring the context path during redirects
Date Fri, 05 Jun 2015 12:08:32 GMT
Repository: cxf
Updated Branches:
  refs/heads/master c8c90d4dc -> 20467ecea


Optionally ignoring the context path during redirects


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/20467ece
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/20467ece
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/20467ece

Branch: refs/heads/master
Commit: 20467ecea3cb0778bd02e60029d4d4ec7a8a2483
Parents: c8c90d4
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Fri Jun 5 13:08:17 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Fri Jun 5 13:08:17 2015 +0100

----------------------------------------------------------------------
 .../provider/RequestDispatcherProvider.java     | 21 +++++++++++++++--
 .../transport/servlet/AbstractHTTPServlet.java  | 24 ++++++++++++++++----
 2 files changed, 39 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/20467ece/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
index e24075f..f3ed18f 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
@@ -92,6 +92,7 @@ public class RequestDispatcherProvider extends AbstractConfigurableProvider
     private String locationPrefix;
     private String resourceExtension;
     private boolean includeResource; 
+    private boolean ignoreContextPath;
     
     private MessageContext mc; 
 
@@ -194,7 +195,7 @@ public class RequestDispatcherProvider extends AbstractConfigurableProvider
             }
             
             HttpServletRequestFilter requestFilter = new HttpServletRequestFilter(
-                servletRequest, path, theServletPath, saveParametersAsAttributes);
+                servletRequest, path, theServletPath, saveParametersAsAttributes, ignoreContextPath);
             String attributeName = getBeanName(o);
             if (REQUEST_SCOPE.equals(scope)) {
                 requestFilter.setAttribute(attributeName, o);
@@ -411,25 +412,41 @@ public class RequestDispatcherProvider extends AbstractConfigurableProvider
         this.resourceExtension = resourceExtension;
     }
 
+    public void setIgnoreContextPath(boolean ignoreContextPath) {
+        this.ignoreContextPath = ignoreContextPath;
+    }
+
     protected static class HttpServletRequestFilter extends HttpServletRequestWrapper {
         
         private Map<String, String[]> params;
         private String path;
         private String servletPath;
         private boolean saveParamsAsAttributes;
+        private boolean ignoreContextPath;
         
         public HttpServletRequestFilter(HttpServletRequest request, 
                                         String path, 
                                         String servletPath,
-                                        boolean saveParamsAsAttributes) {
+                                        boolean saveParamsAsAttributes,
+                                        boolean ignoreContextPath) {
             super(request);
             this.path = path;
             this.servletPath = servletPath;
             this.saveParamsAsAttributes = saveParamsAsAttributes;
+            this.ignoreContextPath = ignoreContextPath;
             params = new HashMap<String, String[]>(request.getParameterMap());
         }
         
         @Override
+        public String getContextPath() {
+            if (ignoreContextPath) {
+                return "/";
+            } else {
+                return super.getContextPath();
+            }
+        }
+        
+        @Override
         public String getServletPath() {
             return servletPath;
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/20467ece/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
----------------------------------------------------------------------
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 520b448..1bd12f8 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
@@ -78,6 +78,7 @@ public abstract class AbstractHTTPServlet extends HttpServlet implements
Filter
     private static final String REDIRECT_SERVLET_PATH_PARAMETER = "redirect-servlet-path";
     private static final String REDIRECT_ATTRIBUTES_PARAMETER = "redirect-attributes";
     private static final String REDIRECT_QUERY_CHECK_PARAMETER = "redirect-query-check";
+    private static final String REDIRECT_IGNORE_CONTEXT_PARAMETER = "redirect-ignore-context";
     private static final String REDIRECT_WITH_INCLUDE_PARAMETER = "redirect-with-include";
     private static final String USE_X_FORWARDED_HEADERS_PARAMETER = "use-x-forwarded-headers";
     private static final String X_FORWARDED_PROTO_HEADER = "X-Forwarded-Proto";
@@ -104,8 +105,9 @@ public abstract class AbstractHTTPServlet extends HttpServlet implements
Filter
     private Map<String, String> staticContentTypes = 
         new HashMap<String, String>(DEFAULT_STATIC_CONTENT_TYPES);
     private boolean redirectQueryCheck;
-    private boolean useXForwardedHeaders; 
-    
+    private boolean redirectIgnoreContextPath;
+    private boolean useXForwardedHeaders;
+        
     public void init(ServletConfig servletConfig) throws ServletException {
         super.init(servletConfig);
 
@@ -113,6 +115,7 @@ public abstract class AbstractHTTPServlet extends HttpServlet implements
Filter
         staticWelcomeFile = servletConfig.getInitParameter(STATIC_WELCOME_FILE_PARAMETER);
         redirectList = parseListSequence(servletConfig.getInitParameter(REDIRECTS_PARAMETER));
         redirectQueryCheck = Boolean.valueOf(servletConfig.getInitParameter(REDIRECT_QUERY_CHECK_PARAMETER));
+        redirectIgnoreContextPath = Boolean.valueOf(servletConfig.getInitParameter(REDIRECT_IGNORE_CONTEXT_PARAMETER));
         dispatcherServletName = servletConfig.getInitParameter(REDIRECT_SERVLET_NAME_PARAMETER);
         dispatcherServletPath = servletConfig.getInitParameter(REDIRECT_SERVLET_PATH_PARAMETER);
         redirectAttributes = parseMapSequence(servletConfig.getInitParameter(REDIRECT_ATTRIBUTES_PARAMETER));
@@ -382,7 +385,8 @@ public abstract class AbstractHTTPServlet extends HttpServlet implements
Filter
                 request.setAttribute(entry.getKey(), entry.getValue());
             }
             HttpServletRequest servletRequest = 
-                new HttpServletRequestRedirectFilter(request, pathInfo, theServletPath, customServletPath);
+                new HttpServletRequestRedirectFilter(request, pathInfo, theServletPath, customServletPath,

+                                                     redirectIgnoreContextPath);
             if (PropertyUtils.isTrue(getServletConfig().getInitParameter(REDIRECT_WITH_INCLUDE_PARAMETER)))
{
                 rd.include(servletRequest, response);
             } else {
@@ -401,14 +405,17 @@ public abstract class AbstractHTTPServlet extends HttpServlet implements
Filter
         
         private String pathInfo;
         private String servletPath;
+        private boolean ignoreContextPath;
         
         public HttpServletRequestRedirectFilter(HttpServletRequest request, 
                                         String pathInfo,
                                         String servletPath,
-                                        boolean customServletPath) {
+                                        boolean customServletPath,
+                                        boolean ignoreContextPath) {
             super(request);
             this.pathInfo = pathInfo;
             this.servletPath = servletPath;
+            this.ignoreContextPath = ignoreContextPath;
             if ("/".equals(this.servletPath) && !customServletPath) {
                 if (this.pathInfo == null) {
                     this.pathInfo = "/";
@@ -420,6 +427,15 @@ public abstract class AbstractHTTPServlet extends HttpServlet implements
Filter
         }
         
         @Override
+        public String getContextPath() {
+            if (ignoreContextPath) {
+                return "/";
+            } else {
+                return super.getContextPath();
+            }
+        }
+        
+        @Override
         public String getServletPath() {
             return servletPath;
         }


Mime
View raw message