summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-09-21 16:51:20 +0300
committerLeif Åstrand <leif@vaadin.com>2012-09-21 16:51:20 +0300
commitfb8cf5cb457f6fe95bd3b07d2fb1a1fb03a3be8f (patch)
tree60fba1a290003fb9c1d381222d5e83c8d250c170
parent167ff2bcea28bb5ad4a9ccba4f2b5b9819371390 (diff)
downloadvaadin-framework-fb8cf5cb457f6fe95bd3b07d2fb1a1fb03a3be8f.tar.gz
vaadin-framework-fb8cf5cb457f6fe95bd3b07d2fb1a1fb03a3be8f.zip
Allow specifying UIProvider using a servlet parameter (#9628)
-rw-r--r--WebContent/WEB-INF/web.xml17
-rw-r--r--server/src/com/vaadin/server/Constants.java1
-rw-r--r--server/src/com/vaadin/server/ServletPortletHelper.java46
-rw-r--r--uitest/src/com/vaadin/tests/applicationservlet/InitParamUIProvider.java36
-rw-r--r--uitest/src/com/vaadin/tests/applicationservlet/UIProviderInitParameter.html39
5 files changed, 131 insertions, 8 deletions
diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml
index d8a8066edc..6112e5ba1c 100644
--- a/WebContent/WEB-INF/web.xml
+++ b/WebContent/WEB-INF/web.xml
@@ -30,6 +30,18 @@
<param-value>com.vaadin.tests.components.label.MarginsInLabels</param-value>
</init-param>
</servlet>
+ <servlet>
+ <servlet-name>UI provider app</servlet-name>
+ <servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
+ <init-param>
+ <param-name>UIProvider</param-name>
+ <param-value>com.vaadin.tests.applicationservlet.InitParamUIProvider</param-value>
+ </init-param>
+ <init-param>
+ <param-name>UI</param-name>
+ <param-value>com.vaadin.tests.VerifyAssertionsEnabled</param-value>
+ </init-param>
+ </servlet>
<context-param>
<param-name>resourceCacheTime</param-name>
@@ -61,6 +73,11 @@
</servlet-mapping>
<servlet-mapping>
+ <servlet-name>UI provider app</servlet-name>
+ <url-pattern>/uiprovider/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
<servlet-name>VaadinApplicationRunner</servlet-name>
<url-pattern>/run/*</url-pattern>
</servlet-mapping>
diff --git a/server/src/com/vaadin/server/Constants.java b/server/src/com/vaadin/server/Constants.java
index f516b4b9a6..60f7aa03d0 100644
--- a/server/src/com/vaadin/server/Constants.java
+++ b/server/src/com/vaadin/server/Constants.java
@@ -63,6 +63,7 @@ public interface Constants {
static final String SERVLET_PARAMETER_RESOURCE_CACHE_TIME = "resourceCacheTime";
static final String SERVLET_PARAMETER_HEARTBEAT_RATE = "heartbeatRate";
static final String SERVLET_PARAMETER_CLOSE_IDLE_UIS = "closeIdleUIs";
+ static final String SERVLET_PARAMETER_UI_PROVIDER = "UIProvider";
// Configurable parameter names
static final String PARAMETER_VAADIN_RESOURCES = "Resources";
diff --git a/server/src/com/vaadin/server/ServletPortletHelper.java b/server/src/com/vaadin/server/ServletPortletHelper.java
index e504aa53fb..f408fffdb1 100644
--- a/server/src/com/vaadin/server/ServletPortletHelper.java
+++ b/server/src/com/vaadin/server/ServletPortletHelper.java
@@ -119,18 +119,48 @@ class ServletPortletHelper implements Serializable {
public static void initDefaultUIProvider(VaadinSession session,
VaadinService vaadinService) throws ServiceException {
- Properties initParameters = vaadinService.getDeploymentConfiguration()
- .getInitParameters();
- String uiProperty = initParameters
- .getProperty(VaadinSession.UI_PARAMETER);
- if (uiProperty == null) {
- uiProperty = initParameters.getProperty(VaadinSession.UI_PARAMETER
- .toLowerCase());
- }
+ String uiProperty = vaadinService.getDeploymentConfiguration()
+ .getApplicationOrSystemProperty(VaadinSession.UI_PARAMETER,
+ null);
+
+ // Add provider for UI parameter first to give it lower priority
+ // (providers are FILO)
if (uiProperty != null) {
verifyUIClass(uiProperty, vaadinService.getClassLoader());
vaadinService.addUIProvider(session, new DefaultUIProvider());
}
+
+ String uiProviderProperty = vaadinService.getDeploymentConfiguration()
+ .getApplicationOrSystemProperty(
+ Constants.SERVLET_PARAMETER_UI_PROVIDER, null);
+ // Then add custom UI provider if defined
+ if (uiProviderProperty != null) {
+ UIProvider uiProvider = getUIProvider(uiProviderProperty,
+ vaadinService.getClassLoader());
+ vaadinService.addUIProvider(session, uiProvider);
+ }
+ }
+
+ private static UIProvider getUIProvider(String uiProviderProperty,
+ ClassLoader classLoader) throws ServiceException {
+ try {
+ Class<?> providerClass = classLoader.loadClass(uiProviderProperty);
+ Class<? extends UIProvider> subclass = providerClass
+ .asSubclass(UIProvider.class);
+ return subclass.newInstance();
+ } catch (ClassNotFoundException e) {
+ throw new ServiceException("Could not load UIProvider class "
+ + uiProviderProperty, e);
+ } catch (ClassCastException e) {
+ throw new ServiceException("UIProvider class " + uiProviderProperty
+ + " does not extend UIProvider", e);
+ } catch (InstantiationException e) {
+ throw new ServiceException("Could not instantiate UIProvider "
+ + uiProviderProperty, e);
+ } catch (IllegalAccessException e) {
+ throw new ServiceException("Could not instantiate UIProvider "
+ + uiProviderProperty, e);
+ }
}
public static void checkUiProviders(VaadinSession session,
diff --git a/uitest/src/com/vaadin/tests/applicationservlet/InitParamUIProvider.java b/uitest/src/com/vaadin/tests/applicationservlet/InitParamUIProvider.java
new file mode 100644
index 0000000000..6a2f5c500b
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/applicationservlet/InitParamUIProvider.java
@@ -0,0 +1,36 @@
+/*
+ * 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.tests.applicationservlet;
+
+import com.vaadin.server.UIProvider;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.javascriptcomponent.BasicJavaScriptComponent;
+import com.vaadin.ui.UI;
+
+public class InitParamUIProvider extends UIProvider {
+
+ @Override
+ public Class<? extends UI> getUIClass(VaadinRequest request) {
+ String pathInfo = request.getRequestPathInfo();
+ if ("/test".equals(pathInfo)) {
+ return BasicJavaScriptComponent.class;
+ } else {
+ return null;
+ }
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/applicationservlet/UIProviderInitParameter.html b/uitest/src/com/vaadin/tests/applicationservlet/UIProviderInitParameter.html
new file mode 100644
index 0000000000..8a5f89cbad
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/applicationservlet/UIProviderInitParameter.html
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/uiprovider</td>
+ <td></td>
+</tr>
+<!--Test that UI parameter is used by default-->
+<tr>
+ <td>assertText</td>
+ <td>vaadin=uiprovider::/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VLabel[0]</td>
+ <td>Tests whether the testing server is run with assertions enabled.</td>
+</tr>
+<!--Test that UIProvider parameter is more important than UI parameter-->
+<tr>
+ <td>open</td>
+ <td>/uiprovider/test</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=uiprovider::/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VLabel[0]</td>
+ <td>Test for basic JavaScript component functionality.</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>