cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6079, CXF-6153] Support for RequestDispatcher.include and Cache-Control for static resources
Date Fri, 12 Dec 2014 16:23:22 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 5e97d1e29 -> 1946e323a


[CXF-6079, CXF-6153] Support for RequestDispatcher.include and Cache-Control for static resources


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

Branch: refs/heads/master
Commit: 1946e323a0df6e5f9748af82106cff39d7b5d01f
Parents: 5e97d1e
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Fri Dec 12 16:23:00 2014 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Fri Dec 12 16:23:00 2014 +0000

----------------------------------------------------------------------
 .../jaxrs/provider/RequestDispatcherProvider.java    | 15 +++++++++++++--
 .../cxf/transport/servlet/AbstractHTTPServlet.java   | 14 ++++++++++++--
 .../systest/jaxrs/JAXRSRequestDispatcherTest.java    | 10 ++++++++++
 .../test/resources/jaxrs_dispatch/WEB-INF/beans.xml  | 12 ++++++++++++
 4 files changed, 47 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/1946e323/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 dfcb3a8..7282005 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
@@ -91,6 +91,7 @@ public class RequestDispatcherProvider extends AbstractConfigurableProvider
     private boolean strictPathCheck;
     private String locationPrefix;
     private String resourceExtension;
+    private boolean includeResource; 
     
     private MessageContext mc; 
 
@@ -191,7 +192,9 @@ public class RequestDispatcherProvider extends AbstractConfigurableProvider
         RequestDispatcher rd = getRequestDispatcher(sc, clazz, theServletPath + path);
         
         try {
-            mc.put(AbstractHTTPDestination.REQUEST_REDIRECTED, Boolean.TRUE);
+            if (!includeResource) {
+                mc.put(AbstractHTTPDestination.REQUEST_REDIRECTED, Boolean.TRUE);
+            }
             
             HttpServletRequestFilter requestFilter = new HttpServletRequestFilter(
                 servletRequest, path, theServletPath, saveParametersAsAttributes);
@@ -203,7 +206,11 @@ public class RequestDispatcherProvider extends AbstractConfigurableProvider
             } 
             setRequestParameters(requestFilter);
             logRedirection(path, attributeName, o);
-            rd.forward(requestFilter, mc.getHttpServletResponse());
+            if (includeResource) {
+                rd.include(requestFilter, mc.getHttpServletResponse());
+            } else {
+                rd.forward(requestFilter, mc.getHttpServletResponse());
+            }
         } catch (Throwable ex) {
             mc.put(AbstractHTTPDestination.REQUEST_REDIRECTED, Boolean.FALSE);
             ex.printStackTrace();
@@ -395,6 +402,10 @@ public class RequestDispatcherProvider extends AbstractConfigurableProvider
         this.useCurrentServlet = useCurrentServlet;
     }
 
+    public void setIncludeResource(boolean includeResource) {
+        this.includeResource = includeResource;
+    }
+
     protected static class HttpServletRequestFilter extends HttpServletRequestWrapper {
         
         private Map<String, String[]> params;

http://git-wip-us.apache.org/repos/asf/cxf/blob/1946e323/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 a48b157..520b448 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
@@ -50,6 +50,7 @@ import org.apache.cxf.Bus;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.PropertyUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.resource.ResourceManager;
@@ -69,6 +70,7 @@ public abstract class AbstractHTTPServlet extends HttpServlet implements
Filter
     
     private static final String STATIC_RESOURCES_PARAMETER = "static-resources-list";
     private static final String STATIC_WELCOME_FILE_PARAMETER = "static-welcome-file";
+    private static final String STATIC_CACHE_CONTROL = "static-cache-control";
     private static final String STATIC_RESOURCES_MAP_RESOURCE = "/cxfServletStaticResourcesMap.txt";
   
     
     private static final String REDIRECTS_PARAMETER = "redirects-list";
@@ -76,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_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";
     private static final String X_FORWARDED_FOR_HEADER = "X-Forwarded-For";
@@ -340,7 +343,10 @@ public abstract class AbstractHTTPServlet extends HttpServlet implements
Filter
                     response.setContentType(type);
                 }
             }
-            
+            String cacheControl = getServletConfig().getInitParameter(STATIC_CACHE_CONTROL);
+            if (cacheControl != null) {
+                response.setHeader("Cache-Control", cacheControl.trim());
+            }
             ServletOutputStream os = response.getOutputStream();
             IOUtils.copy(is, os);
             os.flush();
@@ -377,7 +383,11 @@ public abstract class AbstractHTTPServlet extends HttpServlet implements
Filter
             }
             HttpServletRequest servletRequest = 
                 new HttpServletRequestRedirectFilter(request, pathInfo, theServletPath, customServletPath);
-            rd.forward(servletRequest, response);
+            if (PropertyUtils.isTrue(getServletConfig().getInitParameter(REDIRECT_WITH_INCLUDE_PARAMETER)))
{
+                rd.include(servletRequest, response);
+            } else {
+                rd.forward(servletRequest, response);
+            }
         } catch (Throwable ex) {
             throw new ServletException("RequestDispatcher for path " + pathInfo + " has failed",
ex);
         }   

http://git-wip-us.apache.org/repos/asf/cxf/blob/1946e323/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java
index 0cc12a8..93a1394 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java
@@ -43,6 +43,16 @@ public class JAXRSRequestDispatcherTest extends AbstractBusClientServerTestBase
     public void testGetBookHTML() throws Exception {
         String endpointAddress =
             "http://localhost:" + PORT + "/the/bookstore1/books/html/123"; 
+        doTestGetBookHTML(endpointAddress);
+    }
+    @Test
+    public void testGetBookHTMLInclude() throws Exception {
+        String endpointAddress =
+            "http://localhost:" + PORT + "/the/bookstore5/books/html/123"; 
+        doTestGetBookHTML(endpointAddress);
+    }
+
+    private void doTestGetBookHTML(String endpointAddress) throws Exception {
         WebClient client = WebClient.create(endpointAddress);
         client.accept("text/html");
         WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(100000000);

http://git-wip-us.apache.org/repos/asf/cxf/blob/1946e323/systests/jaxrs/src/test/resources/jaxrs_dispatch/WEB-INF/beans.xml
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/resources/jaxrs_dispatch/WEB-INF/beans.xml b/systests/jaxrs/src/test/resources/jaxrs_dispatch/WEB-INF/beans.xml
index abe3a17..c1187b5 100644
--- a/systests/jaxrs/src/test/resources/jaxrs_dispatch/WEB-INF/beans.xml
+++ b/systests/jaxrs/src/test/resources/jaxrs_dispatch/WEB-INF/beans.xml
@@ -42,6 +42,10 @@
         <property name="resourcePath" value="/book.html"/>
         <property name="dispatcherName" value="default"/>
     </bean>
+    <bean id="dispatchProvider5" class="org.apache.cxf.jaxrs.provider.RequestDispatcherProvider">
+        <property name="resourcePath" value="/book.html"/>
+        <property name="includeResource" value="true"/>
+    </bean>
     <jaxrs:server id="bookservice1" address="/bookstore1">
         <jaxrs:serviceBeans>
             <ref bean="serviceBean"/>
@@ -74,5 +78,13 @@
             <ref bean="dispatchProvider4"/>
         </jaxrs:providers>
     </jaxrs:server>
+    <jaxrs:server id="bookservice5" address="/bookstore5">
+        <jaxrs:serviceBeans>
+            <ref bean="serviceBean"/>
+        </jaxrs:serviceBeans>
+        <jaxrs:providers>
+            <ref bean="dispatchProvider5"/>
+        </jaxrs:providers>
+    </jaxrs:server>
 </beans>
 <!-- END SNIPPET: beans -->


Mime
View raw message