]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix for #4332
authorJohn Alhroos <john.ahlroos@itmill.com>
Tue, 6 Apr 2010 07:27:54 +0000 (07:27 +0000)
committerJohn Alhroos <john.ahlroos@itmill.com>
Tue, 6 Apr 2010 07:27:54 +0000 (07:27 +0000)
svn changeset:12298/svn branch:6.3

WebContent/WEB-INF/web.xml
src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
src/com/vaadin/terminal/gwt/server/Constants.java

index 584c9805bd10ebdac797406e1e3ecdc16fc0659a..27ca7d6c7a60a37a091a21056ce51e622b3621f9 100644 (file)
                <param-value>false</param-value>\r
                <description>Vaadin production mode</description>\r
        </context-param>\r
+       \r
+       <context-param>\r
+               <param-name>resourceCacheTime</param-name>\r
+               <param-value>3600</param-value> \r
+       </context-param>\r
 
        <servlet>\r
                <servlet-name>VaadinApplicationRunner</servlet-name>\r
index 83310a943b5558fa0b6677271eb319812a9ad5a0..092fde21ff8a4ae6937b3da193b048950a4be227 100644 (file)
@@ -182,7 +182,9 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     private boolean productionMode = false;
 
-    private String resourcePath = null;
+    private final String resourcePath = null;
+
+    private int resourceCacheTime = 3600;
 
     /**
      * Called by the servlet container to indicate to a servlet that the servlet
@@ -220,6 +222,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
         }
         checkProductionMode();
         checkCrossSiteProtection();
+        checkResourceCacheTime();
     }
 
     private void checkCrossSiteProtection() {
@@ -254,6 +257,19 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     }
 
+    private void checkResourceCacheTime() {
+        // Check if the browser caching time has been set in web.xml
+        try {
+            String rct = getApplicationOrSystemProperty(
+                    SERVLET_PARAMETER_RESOURCE_CACHE_TIME, "3600");
+            resourceCacheTime = Integer.parseInt(rct);
+        } catch (NumberFormatException nfe) {
+            // Default is 1h
+            resourceCacheTime = 3600;
+            System.err.println(WARNING_RESOURCE_CACHING_TIME_NOT_NUMERIC);
+        }
+    }
+
     /**
      * Gets an application property value.
      * 
@@ -343,6 +359,16 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
         return productionMode;
     }
 
+    /**
+     * Returns the amount of milliseconds the browser should cache a file.
+     * Default is 1 hour (3600 ms).
+     * 
+     * @return The amount of milliseconds files are cached in the browser
+     */
+    public int getResourceCacheTime() {
+        return resourceCacheTime;
+    }
+
     /**
      * Receives standard HTTP requests from the public service method and
      * dispatches them.
@@ -1181,9 +1207,12 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
              * the file has changed. This forces browsers to fetch a new version
              * when the Vaadin version is updated. This will cause more requests
              * to the servlet than without this but for high volume sites the
-             * static files should never be served through the servlet.
+             * static files should never be served through the servlet. The
+             * cache timeout can be configured by setting the resourceCacheTime
+             * parameter in web.xml
              */
-            response.setHeader("Cache-Control", "max-age: 3600");
+            response.setHeader("Cache-Control", "max-age: "
+                    + String.valueOf(resourceCacheTime));
         }
 
         // Write the resource to the client.
index 69a4f8babc2c81e4727506de84a8cf6e64189934..2d4135ebf79bc01e14358a885aa74cf14414693e 100644 (file)
@@ -23,6 +23,12 @@ public interface Constants {
             + "WARNING: Cross-site request forgery protection is disabled!\n"
             + "===========================================================";
 
+    static final String WARNING_RESOURCE_CACHING_TIME_NOT_NUMERIC = ""
+            + "===========================================================\n"
+            + "WARNING: resourceCacheTime has been set to a non integer value "
+            + "in web.xml. The default of 1h will be used.\n"
+            + "===========================================================";
+
     static final String URL_PARAMETER_RESTART_APPLICATION = "restartApplication";
     static final String URL_PARAMETER_CLOSE_APPLICATION = "closeApplication";
     static final String URL_PARAMETER_REPAINT_ALL = "repaintAll";
@@ -31,6 +37,7 @@ public interface Constants {
     static final String SERVLET_PARAMETER_DEBUG = "Debug";
     static final String SERVLET_PARAMETER_PRODUCTION_MODE = "productionMode";
     static final String SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION = "disable-xsrf-protection";
+    static final String SERVLET_PARAMETER_RESOURCE_CACHE_TIME = "resourceCacheTime";
 
     // Configurable parameter names
     static final String PARAMETER_VAADIN_RESOURCES = "Resources";