diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-09-04 16:48:13 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-09-05 11:39:35 +0300 |
commit | c71563c8a6e9993cbbdff3ddfdfccfee4aa34f7b (patch) | |
tree | 8f35fb183d97efa07dfca8dcbc6f4b126e973d43 /server | |
parent | 437e700dfc4173da66d45abd95b6f661d7216218 (diff) | |
download | vaadin-framework-c71563c8a6e9993cbbdff3ddfdfccfee4aa34f7b.tar.gz vaadin-framework-c71563c8a6e9993cbbdff3ddfdfccfee4aa34f7b.zip |
Extract ApplicationConfiguration from DeploymentConfiguration (#9382)
Diffstat (limited to 'server')
14 files changed, 420 insertions, 395 deletions
diff --git a/server/src/com/vaadin/Application.java b/server/src/com/vaadin/Application.java index 088934c5f9..745d0ad784 100644 --- a/server/src/com/vaadin/Application.java +++ b/server/src/com/vaadin/Application.java @@ -24,7 +24,6 @@ import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Enumeration; import java.util.EventObject; import java.util.HashMap; import java.util.Iterator; @@ -45,6 +44,7 @@ import com.vaadin.data.util.converter.DefaultConverterFactory; import com.vaadin.event.EventRouter; import com.vaadin.server.AbstractErrorMessage; import com.vaadin.server.AbstractUIProvider; +import com.vaadin.server.ApplicationConfiguration; import com.vaadin.server.ApplicationContext; import com.vaadin.server.BootstrapFragmentResponse; import com.vaadin.server.BootstrapListener; @@ -400,7 +400,7 @@ public class Application implements Terminal.ErrorListener, Serializable { public static class ApplicationStartEvent implements Serializable { private final URL applicationUrl; - private final DeploymentConfiguration configuration; + private final ApplicationConfiguration configuration; private final ApplicationContext context; @@ -408,12 +408,12 @@ public class Application implements Terminal.ErrorListener, Serializable { * @param applicationUrl * the URL the application should respond to. * @param configuration - * the deployment configuration for the application. + * the application configuration for the application. * @param context * the context application will be running in. */ public ApplicationStartEvent(URL applicationUrl, - DeploymentConfiguration configuration, + ApplicationConfiguration configuration, ApplicationContext context) { this.applicationUrl = applicationUrl; this.configuration = configuration; @@ -433,11 +433,11 @@ public class Application implements Terminal.ErrorListener, Serializable { } /** - * Returns the deployment configuration used by this application. + * Returns the application configuration used by this application. * * @return the deployment configuration. */ - public DeploymentConfiguration getConfiguration() { + public ApplicationConfiguration getConfiguration() { return configuration; } @@ -462,9 +462,9 @@ public class Application implements Terminal.ErrorListener, Serializable { private ApplicationContext context; /** - * Deployment configuration for the application. + * Configuration for the application. */ - private DeploymentConfiguration configuration; + private ApplicationConfiguration configuration; /** * The application's URL. @@ -604,44 +604,12 @@ public class Application implements Terminal.ErrorListener, Serializable { } /** - * Returns the properties of this application as specified in the deployment - * configuration. + * Gets the configuration for this application * - * @return Application properties + * @return the application configuration */ - protected Properties getProperties() { - return configuration.getInitParameters(); - } - - /** - * Returns an enumeration of all the names in this application. - * - * <p> - * See {@link #start(URL, Properties, ApplicationContext)} how properties - * are defined. - * </p> - * - * @return an enumeration of all the keys in this property list, including - * the keys in the default property list. - * - */ - public Enumeration<?> getPropertyNames() { - return getProperties().propertyNames(); - } - - /** - * Searches for the property with the specified name in this application. - * This method returns <code>null</code> if the property is not found. - * - * See {@link #start(URL, Properties, ApplicationContext)} how properties - * are defined. - * - * @param name - * the name of the property. - * @return the value in this property list with the specified key value. - */ - public String getProperty(String name) { - return getProperties().getProperty(name); + public ApplicationConfiguration getConfiguration() { + return configuration; } /** diff --git a/server/src/com/vaadin/DefaultApplicationConfiguration.java b/server/src/com/vaadin/DefaultApplicationConfiguration.java new file mode 100644 index 0000000000..2e2267193e --- /dev/null +++ b/server/src/com/vaadin/DefaultApplicationConfiguration.java @@ -0,0 +1,229 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin; + +import java.util.Properties; +import java.util.logging.Logger; + +import com.vaadin.server.ApplicationConfiguration; +import com.vaadin.server.Constants; + +public class DefaultApplicationConfiguration implements + ApplicationConfiguration { + private final Properties applicationProperties; + private boolean productionMode; + private boolean xsrfProtectionEnabled; + private int resourceCacheTime; + private int heartbeatInterval; + private boolean idleRootCleanupEnabled; + private final Class<?> systemPropertyBaseClass; + + public DefaultApplicationConfiguration(Class<?> systemPropertyBaseClass, + Properties applicationProperties) { + this.applicationProperties = applicationProperties; + this.systemPropertyBaseClass = systemPropertyBaseClass; + + checkProductionMode(); + checkXsrfProtection(); + checkResourceCacheTime(); + checkHeartbeatInterval(); + checkIdleUICleanup(); + } + + @Override + public String getApplicationOrSystemProperty(String propertyName, + String defaultValue) { + String val = null; + + // Try application properties + val = getApplicationProperty(propertyName); + if (val != null) { + return val; + } + + // Try system properties + val = getSystemProperty(propertyName); + if (val != null) { + return val; + } + + return defaultValue; + } + + /** + * Gets an system property value. + * + * @param parameterName + * the Name or the parameter. + * @return String value or null if not found + */ + protected String getSystemProperty(String parameterName) { + String val = null; + + String pkgName; + final Package pkg = systemPropertyBaseClass.getPackage(); + if (pkg != null) { + pkgName = pkg.getName(); + } else { + final String className = systemPropertyBaseClass.getName(); + pkgName = new String(className.toCharArray(), 0, + className.lastIndexOf('.')); + } + val = System.getProperty(pkgName + "." + parameterName); + if (val != null) { + return val; + } + + // Try lowercased system properties + val = System.getProperty(pkgName + "." + parameterName.toLowerCase()); + return val; + } + + /** + * Gets an application property value. + * + * @param parameterName + * the Name or the parameter. + * @return String value or null if not found + */ + public String getApplicationProperty(String parameterName) { + + String val = applicationProperties.getProperty(parameterName); + if (val != null) { + return val; + } + + // Try lower case application properties for backward compatibility with + // 3.0.2 and earlier + val = applicationProperties.getProperty(parameterName.toLowerCase()); + + return val; + } + + /** + * {@inheritDoc} + * + * The default is false. + */ + @Override + public boolean isProductionMode() { + return productionMode; + } + + /** + * {@inheritDoc} + * <p> + * The default is true. + */ + @Override + public boolean isXsrfProtectionEnabled() { + return xsrfProtectionEnabled; + } + + /** + * {@inheritDoc} + * <p> + * The default interval is 3600 seconds (1 hour). + */ + @Override + public int getResourceCacheTime() { + return resourceCacheTime; + } + + /** + * {@inheritDoc} + * <p> + * The default interval is 300 seconds (5 minutes). + */ + @Override + public int getHeartbeatInterval() { + return heartbeatInterval; + } + + @Override + public boolean isIdleUICleanupEnabled() { + return idleRootCleanupEnabled; + } + + /** + * 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 void checkHeartbeatInterval() { + try { + heartbeatInterval = Integer + .parseInt(getApplicationOrSystemProperty( + Constants.SERVLET_PARAMETER_HEARTBEAT_RATE, "300")); + } catch (NumberFormatException e) { + getLogger().warning( + Constants.WARNING_HEARTBEAT_INTERVAL_NOT_NUMERIC); + heartbeatInterval = 300; + } + } + + private void checkIdleUICleanup() { + idleRootCleanupEnabled = getApplicationOrSystemProperty( + Constants.SERVLET_PARAMETER_CLOSE_IDLE_UIS, "false").equals( + "true"); + } + + private Logger getLogger() { + return Logger.getLogger(getClass().getName()); + } + + @Override + public Properties getInitParameters() { + return applicationProperties; + } + +} diff --git a/server/src/com/vaadin/server/AbstractCommunicationManager.java b/server/src/com/vaadin/server/AbstractCommunicationManager.java index 253542db48..3d27dd18b9 100644 --- a/server/src/com/vaadin/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/server/AbstractCommunicationManager.java @@ -1522,9 +1522,7 @@ public abstract class AbstractCommunicationManager implements Serializable { * @return false if the XSRF is turned off, true otherwise */ public boolean isXSRFEnabled(Application application) { - return !"true" - .equals(application - .getProperty(VaadinServlet.SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION)); + return application.getConfiguration().isXsrfProtectionEnabled(); } /** diff --git a/server/src/com/vaadin/server/AbstractDeploymentConfiguration.java b/server/src/com/vaadin/server/AbstractDeploymentConfiguration.java index d1280d29ce..3d7efa6711 100644 --- a/server/src/com/vaadin/server/AbstractDeploymentConfiguration.java +++ b/server/src/com/vaadin/server/AbstractDeploymentConfiguration.java @@ -18,87 +18,28 @@ package com.vaadin.server; import java.lang.reflect.Constructor; import java.util.Iterator; -import java.util.Properties; import java.util.ServiceLoader; -import java.util.logging.Logger; public abstract class AbstractDeploymentConfiguration implements DeploymentConfiguration { - private final Class<?> systemPropertyBaseClass; - private final Properties applicationProperties; private AddonContext addonContext; - private boolean productionMode; - private boolean xsrfProtectionEnabled; - private int resourceCacheTime; - private int heartbeatInterval; - private boolean idleRootCleanupEnabled; + private final ApplicationConfiguration applicationConfiguration; - public AbstractDeploymentConfiguration(Class<?> systemPropertyBaseClass, - Properties applicationProperties) { - this.systemPropertyBaseClass = systemPropertyBaseClass; - this.applicationProperties = applicationProperties; - - checkProductionMode(); - checkXsrfProtection(); - checkResourceCacheTime(); - checkHeartbeatInterval(); - checkIdleUICleanup(); + public AbstractDeploymentConfiguration( + ApplicationConfiguration applicationConfiguration) { + this.applicationConfiguration = applicationConfiguration; } @Override - public String getApplicationOrSystemProperty(String propertyName, - String defaultValue) { - String val = null; - - // Try application properties - val = getApplicationProperty(propertyName); - if (val != null) { - return val; - } - - // Try system properties - val = getSystemProperty(propertyName); - if (val != null) { - return val; - } - - return defaultValue; - } - - /** - * Gets an system property value. - * - * @param parameterName - * the Name or the parameter. - * @return String value or null if not found - */ - protected String getSystemProperty(String parameterName) { - String val = null; - - String pkgName; - final Package pkg = systemPropertyBaseClass.getPackage(); - if (pkg != null) { - pkgName = pkg.getName(); - } else { - final String className = systemPropertyBaseClass.getName(); - pkgName = new String(className.toCharArray(), 0, - className.lastIndexOf('.')); - } - val = System.getProperty(pkgName + "." + parameterName); - if (val != null) { - return val; - } - - // Try lowercased system properties - val = System.getProperty(pkgName + "." + parameterName.toLowerCase()); - return val; + public ApplicationConfiguration getApplicationConfiguration() { + return applicationConfiguration; } @Override public ClassLoader getClassLoader() { - final String classLoaderName = getApplicationOrSystemProperty( - "ClassLoader", null); + final String classLoaderName = getApplicationConfiguration() + .getApplicationOrSystemProperty("ClassLoader", null); ClassLoader classLoader; if (classLoaderName == null) { classLoader = getClass().getClassLoader(); @@ -119,32 +60,6 @@ public abstract class AbstractDeploymentConfiguration implements return classLoader; } - /** - * Gets an application property value. - * - * @param parameterName - * the Name or the parameter. - * @return String value or null if not found - */ - protected String getApplicationProperty(String parameterName) { - - String val = applicationProperties.getProperty(parameterName); - if (val != null) { - return val; - } - - // Try lower case application properties for backward compatibility with - // 3.0.2 and earlier - val = applicationProperties.getProperty(parameterName.toLowerCase()); - - return val; - } - - @Override - public Properties getInitParameters() { - return applicationProperties; - } - @Override public Iterator<AddonContextListener> getAddonContextListeners() { // Called once for init and then no more, so there's no point in caching @@ -163,111 +78,4 @@ public abstract class AbstractDeploymentConfiguration implements public AddonContext getAddonContext() { return addonContext; } - - /** - * {@inheritDoc} - * - * The default is false. - */ - @Override - public boolean isProductionMode() { - return productionMode; - } - - /** - * {@inheritDoc} - * - * The default is true. - */ - @Override - public boolean isXsrfProtectionEnabled() { - return xsrfProtectionEnabled; - } - - /** - * {@inheritDoc} - * - * The default interval is 3600 seconds (1 hour). - */ - @Override - public int getResourceCacheTime() { - return resourceCacheTime; - } - - /** - * {@inheritDoc} - * - * The default interval is 300 seconds (5 minutes). - */ - @Override - public int getHeartbeatInterval() { - return heartbeatInterval; - } - - @Override - public boolean isIdleUICleanupEnabled() { - return idleRootCleanupEnabled; - } - - /** - * 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 void checkHeartbeatInterval() { - try { - heartbeatInterval = Integer - .parseInt(getApplicationOrSystemProperty( - Constants.SERVLET_PARAMETER_HEARTBEAT_RATE, "300")); - } catch (NumberFormatException e) { - getLogger().warning( - Constants.WARNING_HEARTBEAT_INTERVAL_NOT_NUMERIC); - heartbeatInterval = 300; - } - } - - private void checkIdleUICleanup() { - idleRootCleanupEnabled = getApplicationOrSystemProperty( - Constants.SERVLET_PARAMETER_CLOSE_IDLE_UIS, "false").equals( - "true"); - } - - private Logger getLogger() { - return Logger.getLogger(getClass().getName()); - } } diff --git a/server/src/com/vaadin/server/ApplicationConfiguration.java b/server/src/com/vaadin/server/ApplicationConfiguration.java new file mode 100644 index 0000000000..edb33e6c39 --- /dev/null +++ b/server/src/com/vaadin/server/ApplicationConfiguration.java @@ -0,0 +1,99 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.server; + +import java.util.Properties; + + +/** + * A collection of properties configured for all applications as well as a way + * of accessing third party properties not explicitely supported by this class. + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0.0 + */ +public interface ApplicationConfiguration { + /** + * 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(); + + /** + * Returns the number of seconds between heartbeat requests of a UI, or a + * non-positive number if heartbeat is disabled. + * + * @return The time between heartbeats. + */ + public int getHeartbeatInterval(); + + /** + * Returns whether UIs that have no other activity than heartbeat requests + * should be closed after they have been idle the maximum inactivity time + * enforced by the session. + * + * @see ApplicationContext#getMaxInactiveInterval() + * + * @since 7.0.0 + * + * @return True if UIs receiving only heartbeat requests are eventually + * closed; false if heartbeat requests extend UI lifetime + * indefinitely. + */ + public boolean isIdleUICleanupEnabled(); + + /** + * Gets the properties configured for the deployment, e.g. as init + * parameters to the servlet or portlet. + * + * @return properties for the application. + */ + public Properties getInitParameters(); + + /** + * Gets a configured property. The properties are typically read from e.g. + * web.xml or from system properties of the JVM. + * + * @param propertyName + * The simple of the property, in some contexts, lookup might be + * performed using variations of the provided name. + * @param defaultValue + * the default value that should be used if no value has been + * defined + * @return the property value, or the passed default value if no property + * value is found + */ + public String getApplicationOrSystemProperty(String propertyName, + String defaultValue); + +} diff --git a/server/src/com/vaadin/server/BootstrapHandler.java b/server/src/com/vaadin/server/BootstrapHandler.java index 4d200b5063..a793214942 100644 --- a/server/src/com/vaadin/server/BootstrapHandler.java +++ b/server/src/com/vaadin/server/BootstrapHandler.java @@ -463,8 +463,8 @@ public abstract class BootstrapHandler implements RequestHandler { defaults.put("standalone", true); } - defaults.put("heartbeatInterval", - deploymentConfiguration.getHeartbeatInterval()); + defaults.put("heartbeatInterval", deploymentConfiguration + .getApplicationConfiguration().getHeartbeatInterval()); defaults.put("appUri", getAppUri(context)); diff --git a/server/src/com/vaadin/server/DefaultUIProvider.java b/server/src/com/vaadin/server/DefaultUIProvider.java index 93128aad28..b326e3229e 100644 --- a/server/src/com/vaadin/server/DefaultUIProvider.java +++ b/server/src/com/vaadin/server/DefaultUIProvider.java @@ -24,8 +24,8 @@ public class DefaultUIProvider extends AbstractUIProvider { @Override public Class<? extends UI> getUIClass(Application application, WrappedRequest request) { - Object uiClassNameObj = application - .getProperty(Application.UI_PARAMETER); + Object uiClassNameObj = application.getConfiguration() + .getInitParameters().getProperty(Application.UI_PARAMETER); if (uiClassNameObj instanceof String) { String uiClassName = uiClassNameObj.toString(); diff --git a/server/src/com/vaadin/server/DeploymentConfiguration.java b/server/src/com/vaadin/server/DeploymentConfiguration.java index 6150edbafb..1f202eb923 100644 --- a/server/src/com/vaadin/server/DeploymentConfiguration.java +++ b/server/src/com/vaadin/server/DeploymentConfiguration.java @@ -18,7 +18,6 @@ package com.vaadin.server; import java.io.Serializable; import java.util.Iterator; -import java.util.Properties; import javax.portlet.PortletContext; import javax.servlet.ServletContext; @@ -82,22 +81,6 @@ public interface DeploymentConfiguration extends Serializable { public boolean isStandalone(WrappedRequest request); /** - * Gets a configured property. The properties are typically read from e.g. - * web.xml or from system properties of the JVM. - * - * @param propertyName - * The simple of the property, in some contexts, lookup might be - * performed using variations of the provided name. - * @param defaultValue - * the default value that should be used if no value has been - * defined - * @return the property value, or the passed default value if no property - * value is found - */ - public String getApplicationOrSystemProperty(String propertyName, - String defaultValue); - - /** * Get the class loader to use for loading classes loaded by name, e.g. * custom UI classes. <code>null</code> indicates that the default class * loader should be used. @@ -122,12 +105,11 @@ public interface DeploymentConfiguration extends Serializable { public String getMimeType(String resourceName); /** - * Gets the properties configured for the deployment, e.g. as init - * parameters to the servlet or portlet. + * Gets the application configuration. * - * @return properties for the application. + * @return the application configuration */ - public Properties getInitParameters(); + public ApplicationConfiguration getApplicationConfiguration(); public Iterator<AddonContextListener> getAddonContextListeners(); @@ -136,58 +118,6 @@ public interface DeploymentConfiguration extends Serializable { public void setAddonContext(AddonContext vaadinContext); /** - * Returns whether Vaadin is in production mode. - * - * @since 7.0.0 - * - * @return true if in production mode, false otherwise. - */ - public boolean isProductionMode(); - - /** - * Returns whether cross-site request forgery protection is enabled. - * - * @since 7.0.0 - * - * @return true if XSRF protection is enabled, false otherwise. - */ - public boolean isXsrfProtectionEnabled(); - - /** - * Returns the time resources can be cached in the browsers, in seconds. - * - * @since 7.0.0 - * - * @return The resource cache time. - */ - public int getResourceCacheTime(); - - /** - * Returns the number of seconds between heartbeat requests of a UI, or a - * non-positive number if heartbeat is disabled. - * - * @since 7.0.0 - * - * @return The time between heartbeats. - */ - public int getHeartbeatInterval(); - - /** - * Returns whether UIs that have no other activity than heartbeat requests - * should be closed after they have been idle the maximum inactivity time - * enforced by the session. - * - * @see ApplicationContext#getMaxInactiveInterval() - * - * @since 7.0.0 - * - * @return True if UIs receiving only heartbeat requests are eventually - * closed; false if heartbeat requests extend UI lifetime - * indefinitely. - */ - public boolean isIdleUICleanupEnabled(); - - /** * Gets the system messages object * * @return the system messages object diff --git a/server/src/com/vaadin/server/PortletCommunicationManager.java b/server/src/com/vaadin/server/PortletCommunicationManager.java index cb3a8eab80..f7214f108c 100644 --- a/server/src/com/vaadin/server/PortletCommunicationManager.java +++ b/server/src/com/vaadin/server/PortletCommunicationManager.java @@ -130,8 +130,9 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { protected String getMainDivStyle(BootstrapContext context) { DeploymentConfiguration deploymentConfiguration = context .getRequest().getDeploymentConfiguration(); - return deploymentConfiguration.getApplicationOrSystemProperty( - VaadinPortlet.PORTLET_PARAMETER_STYLE, null); + return deploymentConfiguration.getApplicationConfiguration() + .getApplicationOrSystemProperty( + VaadinPortlet.PORTLET_PARAMETER_STYLE, null); } @Override diff --git a/server/src/com/vaadin/server/ServletPortletHelper.java b/server/src/com/vaadin/server/ServletPortletHelper.java index f9ca55b50e..26913d8ba8 100644 --- a/server/src/com/vaadin/server/ServletPortletHelper.java +++ b/server/src/com/vaadin/server/ServletPortletHelper.java @@ -1,6 +1,7 @@ package com.vaadin.server; import java.io.Serializable; +import java.util.Properties; import com.vaadin.Application; import com.vaadin.shared.ApplicationConstants; @@ -43,9 +44,10 @@ class ServletPortletHelper implements Serializable { static Class<? extends Application> getApplicationClass( DeploymentConfiguration deploymentConfiguration) throws ApplicationClassException { - String applicationParameter = deploymentConfiguration - .getInitParameters().getProperty("application"); - String uiParameter = deploymentConfiguration.getInitParameters() + Properties initParameters = deploymentConfiguration + .getApplicationConfiguration().getInitParameters(); + String applicationParameter = initParameters.getProperty("application"); + String uiParameter = initParameters .getProperty(Application.UI_PARAMETER); ClassLoader classLoader = deploymentConfiguration.getClassLoader(); diff --git a/server/src/com/vaadin/server/VaadinPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java index 3d99cf603e..923fcd3b71 100644 --- a/server/src/com/vaadin/server/VaadinPortlet.java +++ b/server/src/com/vaadin/server/VaadinPortlet.java @@ -54,6 +54,7 @@ import com.liferay.portal.kernel.util.PortalClassInvoker; import com.liferay.portal.kernel.util.PropsUtil; import com.vaadin.Application; import com.vaadin.Application.ApplicationStartEvent; +import com.vaadin.DefaultApplicationConfiguration; import com.vaadin.server.AbstractCommunicationManager.Callback; import com.vaadin.server.ServletPortletHelper.ApplicationClassException; import com.vaadin.ui.UI; @@ -76,8 +77,8 @@ public class VaadinPortlet extends GenericPortlet implements Constants { private final VaadinPortlet portlet; public PortletDeploymentConfiguration(VaadinPortlet portlet, - Properties applicationProperties) { - super(portlet.getClass(), applicationProperties); + ApplicationConfiguration applicationConfiguration) { + super(applicationConfiguration); this.portlet = portlet; } @@ -88,8 +89,8 @@ public class VaadinPortlet extends GenericPortlet implements Constants { @Override public String getConfiguredWidgetset(WrappedRequest request) { - String widgetset = getApplicationOrSystemProperty( - PARAMETER_WIDGETSET, null); + String widgetset = getApplicationConfiguration() + .getApplicationOrSystemProperty(PARAMETER_WIDGETSET, null); if (widgetset == null) { // If no widgetset defined for the application, check the @@ -319,15 +320,23 @@ public class VaadinPortlet extends GenericPortlet implements Constants { config.getInitParameter(name)); } - deploymentConfiguration = createDeploymentConfiguration(applicationProperties); + ApplicationConfiguration applicationConfiguration = createApplicationConfiguration(applicationProperties); + deploymentConfiguration = createDeploymentConfiguration(applicationConfiguration); addonContext = new AddonContext(deploymentConfiguration); addonContext.init(); } - protected PortletDeploymentConfiguration createDeploymentConfiguration( + protected ApplicationConfiguration createApplicationConfiguration( Properties applicationProperties) { - return new PortletDeploymentConfiguration(this, applicationProperties); + return new DefaultApplicationConfiguration(getClass(), + applicationProperties); + } + + protected PortletDeploymentConfiguration createDeploymentConfiguration( + ApplicationConfiguration applicationConfiguration) { + return new PortletDeploymentConfiguration(this, + applicationConfiguration); } @Override @@ -384,16 +393,6 @@ public class VaadinPortlet extends GenericPortlet implements Constants { && request.getResourceID().equals("DUMMY"); } - /** - * Returns true if the portlet is running in production mode. Production - * mode disables all debug facilities. - * - * @return true if in production mode, false if in debug mode - */ - public boolean isProductionMode() { - return deploymentConfiguration.isProductionMode(); - } - protected void handleRequest(PortletRequest request, PortletResponse response) throws PortletException, IOException { RequestTimer requestTimer = new RequestTimer(); @@ -769,7 +768,8 @@ public class VaadinPortlet extends GenericPortlet implements Constants { application.setLocale(locale); // No application URL when running inside a portlet application.start(new ApplicationStartEvent(null, - getDeploymentConfiguration(), context)); + getDeploymentConfiguration().getApplicationConfiguration(), + context)); addonContext.fireApplicationStarted(application); } } diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java index 29e473a16a..3cf2c645a0 100644 --- a/server/src/com/vaadin/server/VaadinServlet.java +++ b/server/src/com/vaadin/server/VaadinServlet.java @@ -46,6 +46,7 @@ import javax.servlet.http.HttpSession; import com.vaadin.Application; import com.vaadin.Application.ApplicationStartEvent; +import com.vaadin.DefaultApplicationConfiguration; import com.vaadin.server.AbstractCommunicationManager.Callback; import com.vaadin.server.ServletPortletHelper.ApplicationClassException; import com.vaadin.shared.ApplicationConstants; @@ -60,8 +61,8 @@ public class VaadinServlet extends HttpServlet implements Constants { private final VaadinServlet servlet; public ServletDeploymentConfiguration(VaadinServlet servlet, - Properties applicationProperties) { - super(servlet.getClass(), applicationProperties); + ApplicationConfiguration applicationProperties) { + super(applicationProperties); this.servlet = servlet; } @@ -75,8 +76,9 @@ public class VaadinServlet extends HttpServlet implements Constants { .cast(request); String staticFileLocation; // if property is defined in configurations, use that - staticFileLocation = getApplicationOrSystemProperty( - PARAMETER_VAADIN_RESOURCES, null); + staticFileLocation = getApplicationConfiguration() + .getApplicationOrSystemProperty(PARAMETER_VAADIN_RESOURCES, + null); if (staticFileLocation != null) { return staticFileLocation; } @@ -112,9 +114,10 @@ public class VaadinServlet extends HttpServlet implements Constants { @Override public String getConfiguredWidgetset(WrappedRequest request) { - return getApplicationOrSystemProperty( - VaadinServlet.PARAMETER_WIDGETSET, - VaadinServlet.DEFAULT_WIDGETSET); + return getApplicationConfiguration() + .getApplicationOrSystemProperty( + VaadinServlet.PARAMETER_WIDGETSET, + VaadinServlet.DEFAULT_WIDGETSET); } @Override @@ -201,15 +204,23 @@ public class VaadinServlet extends HttpServlet implements Constants { servletConfig.getInitParameter(name)); } - deploymentConfiguration = createDeploymentConfiguration(applicationProperties); + ApplicationConfiguration applicationConfiguration = createApplicationConfiguration(applicationProperties); + deploymentConfiguration = createDeploymentConfiguration(applicationConfiguration); addonContext = new AddonContext(deploymentConfiguration); addonContext.init(); } - protected ServletDeploymentConfiguration createDeploymentConfiguration( + protected ApplicationConfiguration createApplicationConfiguration( Properties applicationProperties) { - return new ServletDeploymentConfiguration(this, applicationProperties); + return new DefaultApplicationConfiguration(getClass(), + applicationProperties); + } + + protected ServletDeploymentConfiguration createDeploymentConfiguration( + ApplicationConfiguration applicationConfiguration) { + return new ServletDeploymentConfiguration(this, + applicationConfiguration); } @Override @@ -220,26 +231,6 @@ public class VaadinServlet extends HttpServlet implements Constants { } /** - * Returns true if the servlet is running in production mode. Production - * mode disables all debug facilities. - * - * @return true if in production mode, false if in debug mode - */ - public boolean isProductionMode() { - return getDeploymentConfiguration().isProductionMode(); - } - - /** - * Returns the number of seconds the browser should cache a file. Default is - * 1 hour (3600 s). - * - * @return The number of seconds files are cached in the browser - */ - public int getResourceCacheTime() { - return getDeploymentConfiguration().getResourceCacheTime(); - } - - /** * Receives standard HTTP requests from the public service method and * dispatches them. * @@ -917,7 +908,8 @@ public class VaadinServlet extends HttpServlet implements Constants { Locale locale = request.getLocale(); application.setLocale(locale); application.start(new ApplicationStartEvent(applicationUrl, - getDeploymentConfiguration(), webApplicationContext)); + getDeploymentConfiguration().getApplicationConfiguration(), + webApplicationContext)); addonContext.fireApplicationStarted(application); } } @@ -1062,8 +1054,10 @@ public class VaadinServlet extends HttpServlet implements Constants { * cache timeout can be configured by setting the resourceCacheTime * parameter in web.xml */ + int resourceCacheTime = getDeploymentConfiguration() + .getApplicationConfiguration().getResourceCacheTime(); response.setHeader("Cache-Control", - "max-age= " + String.valueOf(getResourceCacheTime())); + "max-age= " + String.valueOf(resourceCacheTime)); } // Write the resource to the client. diff --git a/server/tests/src/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java b/server/tests/src/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java index b936cae1a5..2aa8d04364 100644 --- a/server/tests/src/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java +++ b/server/tests/src/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java @@ -13,6 +13,7 @@ import javax.servlet.http.HttpServletRequest; import junit.framework.TestCase; +import com.vaadin.DefaultApplicationConfiguration; import com.vaadin.server.VaadinServlet.ServletDeploymentConfiguration; public class TestAbstractApplicationServletStaticFilesLocation extends TestCase { @@ -32,7 +33,8 @@ public class TestAbstractApplicationServletStaticFilesLocation extends TestCase .getDeclaredField("deploymentConfiguration"); f.setAccessible(true); f.set(servlet, new ServletDeploymentConfiguration(servlet, - new Properties())); + new DefaultApplicationConfiguration(servlet.getClass(), + new Properties()))); } diff --git a/server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java b/server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java index 89da55a31f..aef35084f8 100644 --- a/server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java +++ b/server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java @@ -10,6 +10,8 @@ import org.easymock.EasyMock; import com.vaadin.Application; import com.vaadin.Application.ApplicationStartEvent; +import com.vaadin.DefaultApplicationConfiguration; +import com.vaadin.server.ApplicationConfiguration; import com.vaadin.server.DefaultUIProvider; import com.vaadin.server.DeploymentConfiguration; import com.vaadin.server.WrappedRequest; @@ -62,15 +64,11 @@ public class CustomUIClassLoader extends TestCase { assertEquals(MyUI.class, uiClass); } - private static DeploymentConfiguration createConfigurationMock() { - DeploymentConfiguration configurationMock = EasyMock - .createMock(DeploymentConfiguration.class); - EasyMock.expect(configurationMock.isProductionMode()).andReturn(false); - EasyMock.expect(configurationMock.getInitParameters()).andReturn( - new Properties()); - - EasyMock.replay(configurationMock); - return configurationMock; + private static ApplicationConfiguration createConfigurationMock() { + Properties properties = new Properties(); + properties.put(Application.UI_PARAMETER, MyUI.class.getName()); + return new DefaultApplicationConfiguration(CustomUIClassLoader.class, + properties); } private static WrappedRequest createRequestMock(ClassLoader classloader) { @@ -117,12 +115,8 @@ public class CustomUIClassLoader extends TestCase { private Application createStubApplication() { return new Application() { @Override - public String getProperty(String name) { - if (name.equals(UI_PARAMETER)) { - return MyUI.class.getName(); - } else { - return super.getProperty(name); - } + public ApplicationConfiguration getConfiguration() { + return createConfigurationMock(); } }; } |