=== added file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/servlet/filter/HttpMaxCacheFilter.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/servlet/filter/HttpMaxCacheFilter.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/servlet/filter/HttpMaxCacheFilter.java 2014-10-17 16:11:39 +0000
@@ -0,0 +1,102 @@
+package org.hisp.dhis.servlet.filter;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.io.IOException;
+import java.util.regex.Pattern;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.hisp.dhis.system.util.DateUtils;
+import org.joda.time.DateTime;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class HttpMaxCacheFilter
+ implements Filter
+{
+ private static final String PARAM_REGEX = "regex";
+ private static final String HEADER_EXPIRES = "Expires";
+ private static final String HEADER_CACHE_CONTROL = "Cache-Control";
+ private static final String HEADER_MAX_CACHE = "public, max-age=31536000";
+
+ private Pattern PATTERN = null;
+
+ @Override
+ public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain )
+ throws IOException, ServletException
+ {
+ if ( PATTERN != null && request != null && request instanceof HttpServletRequest &&
+ response != null && response instanceof HttpServletResponse )
+ {
+ HttpServletRequest httpRequest = (HttpServletRequest) request;
+ HttpServletResponse httpResponse = (HttpServletResponse) response;
+
+ String uri = httpRequest.getRequestURI();
+
+ if ( uri != null && PATTERN.matcher( uri ).find() )
+ {
+ DateTime expiry = new DateTime().plusYears( 1 );
+
+ httpResponse.setHeader( HEADER_EXPIRES, DateUtils.getHttpDateString( expiry.toDate() ) );
+ httpResponse.setHeader( HEADER_CACHE_CONTROL, HEADER_MAX_CACHE );
+ }
+ }
+
+ chain.doFilter( request, response );
+ }
+
+ @Override
+ public void init( FilterConfig config )
+ throws ServletException
+ {
+ String regex = config.getInitParameter( PARAM_REGEX );
+
+ if ( regex == null )
+ {
+ throw new IllegalStateException( "Init parameter 'regex' must be defined for HttpMaxCacheFilter" );
+ }
+
+ PATTERN = Pattern.compile( regex );
+ }
+
+ @Override
+ public void destroy()
+ {
+ }
+}
+
=== modified file 'dhis-2/dhis-web/dhis-web-portal/src/main/webapp/WEB-INF/web.xml'
--- dhis-2/dhis-web/dhis-web-portal/src/main/webapp/WEB-INF/web.xml 2014-01-15 14:09:56 +0000
+++ dhis-2/dhis-web/dhis-web-portal/src/main/webapp/WEB-INF/web.xml 2014-10-17 16:11:39 +0000
@@ -13,6 +13,8 @@
databaseAdmin
+
+
RedirectFilter
org.hisp.dhis.servlet.filter.HttpRedirectFilter
@@ -22,6 +24,14 @@
+ HttpMaxCacheFilter
+ org.hisp.dhis.servlet.filter.HttpMaxCacheFilter
+
+ regex
+ (\.js|\.css|\.gif|\.woff|\.ttf|\.eot|\.ico|(/dhis-web-commons/|/images/|/icons/).*\.png)$
+
+
+
shallowEtagHeaderFilter
org.springframework.web.filter.ShallowEtagHeaderFilter
@@ -41,7 +51,6 @@
Struts
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
-
encoding-filter
org.springframework.web.filter.CharacterEncodingFilter
@@ -64,6 +73,10 @@
/
+ HttpMaxCacheFilter
+ /*
+
+
OpenSessionInViewFilter
*.action
@@ -96,6 +109,8 @@
*.action
+
+
org.springframework.web.context.ContextLoaderListener
@@ -103,6 +118,8 @@
org.hisp.dhis.system.startup.StartupListener
+
+
webapi
org.springframework.web.servlet.DispatcherServlet
@@ -112,7 +129,6 @@
1
-
mobile
org.springframework.web.servlet.DispatcherServlet
@@ -122,7 +138,6 @@
1
-
ohie
org.springframework.web.servlet.DispatcherServlet
@@ -133,37 +148,26 @@
1
-
-
mobile
/mobile
-
mobile
/mobile/*
-
-
-
webapi
/api
-
webapi
/api/*
-
-
-
ohie
/ohie
-
ohie
/ohie/*