aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/vaadin
diff options
context:
space:
mode:
authorJohn Alhroos <john.ahlroos@itmill.com>2010-04-06 07:27:54 +0000
committerJohn Alhroos <john.ahlroos@itmill.com>2010-04-06 07:27:54 +0000
commit48acda6b333ad486fc9876a8e6f252b1b1e2997b (patch)
treef89e632c387ccfd0896fa124430d5a14d2955c6b /src/com/vaadin
parente95fe48416deb81c38444fd4c1d6d099cb9d0add (diff)
downloadvaadin-framework-48acda6b333ad486fc9876a8e6f252b1b1e2997b.tar.gz
vaadin-framework-48acda6b333ad486fc9876a8e6f252b1b1e2997b.zip
Fix for #4332
svn changeset:12298/svn branch:6.3
Diffstat (limited to 'src/com/vaadin')
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java35
-rw-r--r--src/com/vaadin/terminal/gwt/server/Constants.java7
2 files changed, 39 insertions, 3 deletions
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";