summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--WebContent/WEB-INF/web.xml5
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java35
-rw-r--r--src/com/vaadin/terminal/gwt/server/Constants.java7
3 files changed, 44 insertions, 3 deletions
diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml
index 584c9805bd..27ca7d6c7a 100644
--- a/WebContent/WEB-INF/web.xml
+++ b/WebContent/WEB-INF/web.xml
@@ -19,6 +19,11 @@
<param-value>false</param-value>
<description>Vaadin production mode</description>
</context-param>
+
+ <context-param>
+ <param-name>resourceCacheTime</param-name>
+ <param-value>3600</param-value>
+ </context-param>
<servlet>
<servlet-name>VaadinApplicationRunner</servlet-name>
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
index 83310a943b..092fde21ff 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
@@ -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.
*
@@ -344,6 +360,16 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
}
/**
+ * 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.
diff --git a/src/com/vaadin/terminal/gwt/server/Constants.java b/src/com/vaadin/terminal/gwt/server/Constants.java
index 69a4f8babc..2d4135ebf7 100644
--- a/src/com/vaadin/terminal/gwt/server/Constants.java
+++ b/src/com/vaadin/terminal/gwt/server/Constants.java
@@ -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";