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
}
checkProductionMode();
checkCrossSiteProtection();
+ checkResourceCacheTime();
}
private void checkCrossSiteProtection() {
}
+ 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.
*
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.
* 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.
+ "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";
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";