aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2012-08-17 16:54:35 +0300
committerJohannes Dahlström <johannesd@vaadin.com>2012-08-17 17:02:50 +0300
commite69c4908ba61b1fd09f0b50ecbc2e0ec11cd06f5 (patch)
tree5e2cb0efb239adaa8d2d9b20acac9c982252a096 /server
parent47a0326c2fb2d6d8621e7a6fbfa2f011a48e15a4 (diff)
downloadvaadin-framework-e69c4908ba61b1fd09f0b50ecbc2e0ec11cd06f5.tar.gz
vaadin-framework-e69c4908ba61b1fd09f0b50ecbc2e0ec11cd06f5.zip
Bugfixes: pass application properties to AbstractDeploymentConfiguration constructor so they are properly parsed and checked; properly use deploymentConfiguration in AbstractApplicationPortlet.isProductionMode(); return correct value from isXsrfProtectionEnabled() (#9340)
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java183
-rw-r--r--server/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java77
-rw-r--r--server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java8
3 files changed, 136 insertions, 132 deletions
diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java b/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
index 06ed54990a..bd39504237 100644
--- a/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
+++ b/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
@@ -217,99 +217,13 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
// TODO Can we close the application when the portlet is removed? Do we know
// when the portlet is removed?
- private boolean productionMode = false;
-
- private DeploymentConfiguration deploymentConfiguration = new AbstractDeploymentConfiguration(
- getClass()) {
- @Override
- public String getConfiguredWidgetset(WrappedRequest request) {
-
- String widgetset = getApplicationOrSystemProperty(
- PARAMETER_WIDGETSET, null);
-
- if (widgetset == null) {
- // If no widgetset defined for the application, check the
- // portal
- // property
- widgetset = WrappedPortletRequest.cast(request)
- .getPortalProperty(PORTAL_PARAMETER_VAADIN_WIDGETSET);
- }
-
- if (widgetset == null) {
- // If no widgetset defined for the portal, use the default
- widgetset = DEFAULT_WIDGETSET;
- }
-
- return widgetset;
- }
-
- @Override
- public String getConfiguredTheme(WrappedRequest request) {
-
- // is the default theme defined by the portal?
- String themeName = WrappedPortletRequest.cast(request)
- .getPortalProperty(Constants.PORTAL_PARAMETER_VAADIN_THEME);
-
- if (themeName == null) {
- // no, using the default theme defined by Vaadin
- themeName = DEFAULT_THEME_NAME;
- }
-
- return themeName;
- }
-
- @Override
- public boolean isStandalone(WrappedRequest request) {
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * com.vaadin.terminal.DeploymentConfiguration#getStaticFileLocation
- * (com.vaadin.terminal.WrappedRequest)
- *
- * Return the URL from where static files, e.g. the widgetset and the
- * theme, are served. In a standard configuration the VAADIN folder
- * inside the returned folder is what is used for widgetsets and themes.
- *
- * @return The location of static resources (inside which there should
- * be a VAADIN directory). Does not end with a slash (/).
- */
-
- @Override
- public String getStaticFileLocation(WrappedRequest request) {
- String staticFileLocation = WrappedPortletRequest.cast(request)
- .getPortalProperty(
- Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH);
- if (staticFileLocation != null) {
- // remove trailing slash if any
- while (staticFileLocation.endsWith(".")) {
- staticFileLocation = staticFileLocation.substring(0,
- staticFileLocation.length() - 1);
- }
- return staticFileLocation;
- } else {
- // default for Liferay
- return "/html";
- }
- }
-
- @Override
- public String getMimeType(String resourceName) {
- return getPortletContext().getMimeType(resourceName);
- }
- };
-
- private final AddonContext addonContext = new AddonContext(
- getDeploymentConfiguration());
+ private DeploymentConfiguration deploymentConfiguration;
+ private AddonContext addonContext;
@Override
public void init(PortletConfig config) throws PortletException {
super.init(config);
- Properties applicationProperties = getDeploymentConfiguration()
- .getInitParameters();
+ Properties applicationProperties = new Properties();
// Read default parameters from the context
final PortletContext context = config.getPortletContext();
@@ -328,6 +242,93 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
config.getInitParameter(name));
}
+ deploymentConfiguration = new AbstractDeploymentConfiguration(
+ getClass(), applicationProperties) {
+ @Override
+ public String getConfiguredWidgetset(WrappedRequest request) {
+
+ String widgetset = getApplicationOrSystemProperty(
+ PARAMETER_WIDGETSET, null);
+
+ if (widgetset == null) {
+ // If no widgetset defined for the application, check the
+ // portal property
+ widgetset = WrappedPortletRequest.cast(request)
+ .getPortalProperty(
+ PORTAL_PARAMETER_VAADIN_WIDGETSET);
+ }
+
+ if (widgetset == null) {
+ // If no widgetset defined for the portal, use the default
+ widgetset = DEFAULT_WIDGETSET;
+ }
+
+ return widgetset;
+ }
+
+ @Override
+ public String getConfiguredTheme(WrappedRequest request) {
+
+ // is the default theme defined by the portal?
+ String themeName = WrappedPortletRequest.cast(request)
+ .getPortalProperty(
+ Constants.PORTAL_PARAMETER_VAADIN_THEME);
+
+ if (themeName == null) {
+ // no, using the default theme defined by Vaadin
+ themeName = DEFAULT_THEME_NAME;
+ }
+
+ return themeName;
+ }
+
+ @Override
+ public boolean isStandalone(WrappedRequest request) {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.terminal.DeploymentConfiguration#getStaticFileLocation
+ * (com.vaadin.terminal.WrappedRequest)
+ *
+ * Return the URL from where static files, e.g. the widgetset and
+ * the theme, are served. In a standard configuration the VAADIN
+ * folder inside the returned folder is what is used for widgetsets
+ * and themes.
+ *
+ * @return The location of static resources (inside which there
+ * should be a VAADIN directory). Does not end with a slash (/).
+ */
+
+ @Override
+ public String getStaticFileLocation(WrappedRequest request) {
+ String staticFileLocation = WrappedPortletRequest
+ .cast(request)
+ .getPortalProperty(
+ Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH);
+ if (staticFileLocation != null) {
+ // remove trailing slash if any
+ while (staticFileLocation.endsWith(".")) {
+ staticFileLocation = staticFileLocation.substring(0,
+ staticFileLocation.length() - 1);
+ }
+ return staticFileLocation;
+ } else {
+ // default for Liferay
+ return "/html";
+ }
+ }
+
+ @Override
+ public String getMimeType(String resourceName) {
+ return getPortletContext().getMimeType(resourceName);
+ }
+ };
+
+ addonContext = new AddonContext(deploymentConfiguration);
addonContext.init();
}
@@ -384,13 +385,13 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
}
/**
- * Returns true if the servlet is running in production mode. Production
+ * 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 productionMode;
+ return deploymentConfiguration.isProductionMode();
}
protected void handleRequest(PortletRequest request,
diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
index 8857c0e964..062ba6cdf7 100644
--- a/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
+++ b/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
@@ -99,43 +99,9 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
private final String resourcePath = null;
- private DeploymentConfiguration deploymentConfiguration = new AbstractDeploymentConfiguration(
- getClass()) {
+ private DeploymentConfiguration deploymentConfiguration;
- @Override
- public String getStaticFileLocation(WrappedRequest request) {
- HttpServletRequest servletRequest = WrappedHttpServletRequest
- .cast(request);
- return AbstractApplicationServlet.this
- .getStaticFilesLocation(servletRequest);
- }
-
- @Override
- public String getConfiguredWidgetset(WrappedRequest request) {
- return getApplicationOrSystemProperty(
- AbstractApplicationServlet.PARAMETER_WIDGETSET,
- AbstractApplicationServlet.DEFAULT_WIDGETSET);
- }
-
- @Override
- public String getConfiguredTheme(WrappedRequest request) {
- // Use the default
- return AbstractApplicationServlet.getDefaultTheme();
- }
-
- @Override
- public boolean isStandalone(WrappedRequest request) {
- return true;
- }
-
- @Override
- public String getMimeType(String resourceName) {
- return getServletContext().getMimeType(resourceName);
- }
- };
-
- private final AddonContext addonContext = new AddonContext(
- getDeploymentConfiguration());
+ private AddonContext addonContext;
/**
* Called by the servlet container to indicate to a servlet that the servlet
@@ -152,8 +118,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
public void init(javax.servlet.ServletConfig servletConfig)
throws javax.servlet.ServletException {
super.init(servletConfig);
- Properties applicationProperties = getDeploymentConfiguration()
- .getInitParameters();
+ Properties applicationProperties = new Properties();
// Read default parameters from server.xml
final ServletContext context = servletConfig.getServletContext();
@@ -172,6 +137,42 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
servletConfig.getInitParameter(name));
}
+ deploymentConfiguration = new AbstractDeploymentConfiguration(
+ getClass(), applicationProperties) {
+
+ @Override
+ public String getStaticFileLocation(WrappedRequest request) {
+ HttpServletRequest servletRequest = WrappedHttpServletRequest
+ .cast(request);
+ return AbstractApplicationServlet.this
+ .getStaticFilesLocation(servletRequest);
+ }
+
+ @Override
+ public String getConfiguredWidgetset(WrappedRequest request) {
+ return getApplicationOrSystemProperty(
+ AbstractApplicationServlet.PARAMETER_WIDGETSET,
+ AbstractApplicationServlet.DEFAULT_WIDGETSET);
+ }
+
+ @Override
+ public String getConfiguredTheme(WrappedRequest request) {
+ // Use the default
+ return AbstractApplicationServlet.getDefaultTheme();
+ }
+
+ @Override
+ public boolean isStandalone(WrappedRequest request) {
+ return true;
+ }
+
+ @Override
+ public String getMimeType(String resourceName) {
+ return getServletContext().getMimeType(resourceName);
+ }
+ };
+
+ addonContext = new AddonContext(deploymentConfiguration);
addonContext.init();
}
diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java b/server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java
index a8e4cdfaca..ad5acad5e9 100644
--- a/server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java
+++ b/server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java
@@ -28,14 +28,16 @@ public abstract class AbstractDeploymentConfiguration implements
DeploymentConfiguration {
private final Class<?> systemPropertyBaseClass;
- private final Properties applicationProperties = new Properties();
+ private final Properties applicationProperties;
private AddonContext addonContext;
private boolean productionMode;
private boolean xsrfProtectionEnabled;
private int resourceCacheTime;
- public AbstractDeploymentConfiguration(Class<?> systemPropertyBaseClass) {
+ public AbstractDeploymentConfiguration(Class<?> systemPropertyBaseClass,
+ Properties applicationProperties) {
this.systemPropertyBaseClass = systemPropertyBaseClass;
+ this.applicationProperties = applicationProperties;
checkProductionMode();
checkXsrfProtection();
@@ -192,7 +194,7 @@ public abstract class AbstractDeploymentConfiguration implements
* Log a warning if cross-site request forgery protection is disabled.
*/
private void checkXsrfProtection() {
- xsrfProtectionEnabled = getApplicationOrSystemProperty(
+ xsrfProtectionEnabled = !getApplicationOrSystemProperty(
Constants.SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION, "false")
.equals("true");
if (!xsrfProtectionEnabled) {