diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2012-08-17 13:12:51 +0300 |
---|---|---|
committer | Johannes Dahlström <johannesd@vaadin.com> | 2012-08-17 13:12:51 +0300 |
commit | 8e3aa0a9823556896f1af00599c3e79ca2ce2e01 (patch) | |
tree | 93ee8856d280e7a17d0e65961652ad7e4b20b95b /src/com/vaadin/terminal | |
parent | b52fbdfc7f03d83b521cc969acae906b669cd64c (diff) | |
download | vaadin-framework-8e3aa0a9823556896f1af00599c3e79ca2ce2e01.tar.gz vaadin-framework-8e3aa0a9823556896f1af00599c3e79ca2ce2e01.zip |
Pass whole DeploymentConfiguration to ApplicationStartEvent and Application; add accessors to supported servlet init params to DeploymentConfiguration; move init param checks and validation to AbstractDeploymentConfiguration (#9340,#9341)
Diffstat (limited to 'src/com/vaadin/terminal')
4 files changed, 96 insertions, 90 deletions
diff --git a/src/com/vaadin/terminal/DeploymentConfiguration.java b/src/com/vaadin/terminal/DeploymentConfiguration.java index 160350ca24..6847072523 100644 --- a/src/com/vaadin/terminal/DeploymentConfiguration.java +++ b/src/com/vaadin/terminal/DeploymentConfiguration.java @@ -120,4 +120,25 @@ public interface DeploymentConfiguration extends Serializable { public VaadinContext getVaadinContext(); public void setVaadinContext(VaadinContext vaadinContext); + + /** + * Returns whether Vaadin is in production mode. + * + * @return true if in production mode, false otherwise. + */ + public boolean isProductionMode(); + + /** + * Returns whether cross-site request forgery protection is enabled. + * + * @return true if XSRF protection is enabled, false otherwise. + */ + public boolean isXsrfProtectionEnabled(); + + /** + * Returns the time resources can be cached in the browsers, in seconds. + * + * @return The resource cache time. + */ + public int getResourceCacheTime(); } diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java index bb4e8ba0a7..bfd35fd034 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java @@ -316,9 +316,6 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet config.getInitParameter(name)); } - checkProductionMode(); - checkCrossSiteProtection(); - vaadinContext.init(); } @@ -329,34 +326,6 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet vaadinContext.destroy(); } - private void checkCrossSiteProtection() { - if (getDeploymentConfiguration().getApplicationOrSystemProperty( - SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION, "false").equals( - "true")) { - /* - * Print an information/warning message about running with xsrf - * protection disabled - */ - getLogger().warning(WARNING_XSRF_PROTECTION_DISABLED); - } - } - - private void checkProductionMode() { - // TODO Identical code in AbstractApplicationServlet -> refactor - // Check if the application is in production mode. - // We are in production mode if productionMode=true - if (getDeploymentConfiguration().getApplicationOrSystemProperty( - SERVLET_PARAMETER_PRODUCTION_MODE, "false").equals("true")) { - productionMode = true; - } - - if (!productionMode) { - /* Print an information/warning message about running in debug mode */ - // TODO Maybe we need a different message for portlets? - getLogger().warning(NOT_PRODUCTION_MODE_INFO); - } - } - protected enum RequestType { FILE_UPLOAD, UIDL, RENDER, STATIC_FILE, APPLICATION_RESOURCE, DUMMY, EVENT, ACTION, UNKNOWN, BROWSER_DETAILS, CONNECTOR_RESOURCE; } @@ -799,8 +768,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet application.setLocale(locale); // No application URL when running inside a portlet application.start(new ApplicationStartEvent(null, - getDeploymentConfiguration().getInitParameters(), context, - isProductionMode())); + getDeploymentConfiguration(), context)); } } diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java index c2e1d2d3e7..2ba19b0cf6 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java @@ -87,12 +87,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements // TODO Move some (all?) of the constants to a separate interface (shared // with portlet) - private boolean productionMode = false; - private final String resourcePath = null; - private int resourceCacheTime = 3600; - private DeploymentConfiguration deploymentConfiguration = new AbstractDeploymentConfiguration( getClass()) { @@ -166,10 +162,6 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements servletConfig.getInitParameter(name)); } - checkProductionMode(); - checkCrossSiteProtection(); - checkResourceCacheTime(); - vaadinContext.init(); } @@ -180,47 +172,6 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements vaadinContext.destroy(); } - private void checkCrossSiteProtection() { - if (getDeploymentConfiguration().getApplicationOrSystemProperty( - SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION, "false").equals( - "true")) { - /* - * Print an information/warning message about running with xsrf - * protection disabled - */ - getLogger().warning(WARNING_XSRF_PROTECTION_DISABLED); - } - } - - private void checkProductionMode() { - // Check if the application is in production mode. - // We are in production mode if productionMode=true - if (getDeploymentConfiguration().getApplicationOrSystemProperty( - SERVLET_PARAMETER_PRODUCTION_MODE, "false").equals("true")) { - productionMode = true; - } - - if (!productionMode) { - /* Print an information/warning message about running in debug mode */ - getLogger().warning(NOT_PRODUCTION_MODE_INFO); - } - - } - - private void checkResourceCacheTime() { - // Check if the browser caching time has been set in web.xml - try { - String rct = getDeploymentConfiguration() - .getApplicationOrSystemProperty( - SERVLET_PARAMETER_RESOURCE_CACHE_TIME, "3600"); - resourceCacheTime = Integer.parseInt(rct); - } catch (NumberFormatException nfe) { - // Default is 1h - resourceCacheTime = 3600; - getLogger().warning(WARNING_RESOURCE_CACHING_TIME_NOT_NUMERIC); - } - } - /** * Returns true if the servlet is running in production mode. Production * mode disables all debug facilities. @@ -228,17 +179,17 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements * @return true if in production mode, false if in debug mode */ public boolean isProductionMode() { - return productionMode; + return getDeploymentConfiguration().isProductionMode(); } /** - * Returns the amount of milliseconds the browser should cache a file. - * Default is 1 hour (3600 ms). + * Returns the number of seconds the browser should cache a file. Default is + * 1 hour (3600 s). * - * @return The amount of milliseconds files are cached in the browser + * @return The number of seconds files are cached in the browser */ public int getResourceCacheTime() { - return resourceCacheTime; + return getDeploymentConfiguration().getResourceCacheTime(); } /** @@ -899,8 +850,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements Locale locale = request.getLocale(); application.setLocale(locale); application.start(new ApplicationStartEvent(applicationUrl, - getDeploymentConfiguration().getInitParameters(), - webApplicationContext, isProductionMode())); + getDeploymentConfiguration(), webApplicationContext)); } } @@ -1045,7 +995,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements * parameter in web.xml */ response.setHeader("Cache-Control", - "max-age= " + String.valueOf(resourceCacheTime)); + "max-age= " + String.valueOf(getResourceCacheTime())); } // Write the resource to the client. diff --git a/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java b/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java index 47bf5ecc60..1382c1ed53 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java @@ -8,6 +8,7 @@ import java.lang.reflect.Constructor; import java.util.Iterator; import java.util.Properties; import java.util.ServiceLoader; +import java.util.logging.Logger; import com.vaadin.terminal.DeploymentConfiguration; @@ -17,9 +18,16 @@ public abstract class AbstractDeploymentConfiguration implements private final Class<?> systemPropertyBaseClass; private final Properties applicationProperties = new Properties(); private VaadinContext vaadinContext; + private boolean productionMode; + private boolean xsrfProtectionEnabled; + private int resourceCacheTime; public AbstractDeploymentConfiguration(Class<?> systemPropertyBaseClass) { this.systemPropertyBaseClass = systemPropertyBaseClass; + + checkProductionMode(); + checkXsrfProtection(); + checkResourceCacheTime(); } @Override @@ -140,4 +148,63 @@ public abstract class AbstractDeploymentConfiguration implements public VaadinContext getVaadinContext() { return vaadinContext; } + + @Override + public boolean isProductionMode() { + return productionMode; + } + + @Override + public boolean isXsrfProtectionEnabled() { + return xsrfProtectionEnabled; + } + + @Override + public int getResourceCacheTime() { + return resourceCacheTime; + } + + /** + * Log a warning if Vaadin is not running in production mode. + */ + private void checkProductionMode() { + productionMode = getApplicationOrSystemProperty( + Constants.SERVLET_PARAMETER_PRODUCTION_MODE, "false").equals( + "true"); + if (!productionMode) { + getLogger().warning(Constants.NOT_PRODUCTION_MODE_INFO); + } + } + + /** + * Log a warning if cross-site request forgery protection is disabled. + */ + private void checkXsrfProtection() { + xsrfProtectionEnabled = getApplicationOrSystemProperty( + Constants.SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION, "false") + .equals("true"); + if (!xsrfProtectionEnabled) { + getLogger().warning(Constants.WARNING_XSRF_PROTECTION_DISABLED); + } + } + + /** + * Log a warning if resource cache time is set but is not an integer. + */ + private void checkResourceCacheTime() { + try { + resourceCacheTime = Integer + .parseInt(getApplicationOrSystemProperty( + Constants.SERVLET_PARAMETER_RESOURCE_CACHE_TIME, + "3600")); + } catch (NumberFormatException e) { + getLogger().warning( + Constants.WARNING_RESOURCE_CACHING_TIME_NOT_NUMERIC); + resourceCacheTime = 3600; + } + } + + private Logger getLogger() { + return Logger.getLogger(getClass().getName()); + } } |