Browse Source

Allow specifying UIProvider using a servlet parameter (#9628)

tags/7.0.0.beta2
Leif Åstrand 11 years ago
parent
commit
fb8cf5cb45

+ 17
- 0
WebContent/WEB-INF/web.xml View File

@@ -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>
@@ -60,6 +72,11 @@
<url-pattern>/embed2/*</url-pattern>
</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>

+ 1
- 0
server/src/com/vaadin/server/Constants.java View File

@@ -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";

+ 38
- 8
server/src/com/vaadin/server/ServletPortletHelper.java View File

@@ -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,

+ 36
- 0
uitest/src/com/vaadin/tests/applicationservlet/InitParamUIProvider.java View File

@@ -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;
}
}

}

+ 39
- 0
uitest/src/com/vaadin/tests/applicationservlet/UIProviderInitParameter.html View File

@@ -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>

Loading…
Cancel
Save