diff options
Diffstat (limited to 'uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java')
-rw-r--r-- | uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java | 95 |
1 files changed, 74 insertions, 21 deletions
diff --git a/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java index 1f72495596..e2b93ab7d2 100644 --- a/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java +++ b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java @@ -17,6 +17,7 @@ package com.vaadin.launcher; import java.io.File; import java.io.IOException; +import java.io.Serializable; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; @@ -45,10 +46,16 @@ import com.vaadin.server.LegacyVaadinServlet; import com.vaadin.server.ServiceException; import com.vaadin.server.SessionInitEvent; import com.vaadin.server.SessionInitListener; +import com.vaadin.server.SystemMessages; +import com.vaadin.server.SystemMessagesInfo; +import com.vaadin.server.SystemMessagesProvider; import com.vaadin.server.UIClassSelectionEvent; import com.vaadin.server.UIProvider; import com.vaadin.server.VaadinRequest; +import com.vaadin.server.VaadinService; +import com.vaadin.server.VaadinServlet; import com.vaadin.server.VaadinServletRequest; +import com.vaadin.server.VaadinServletService; import com.vaadin.server.VaadinSession; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.UI; @@ -57,6 +64,9 @@ import com.vaadin.util.CurrentInstance; @SuppressWarnings("serial") public class ApplicationRunnerServlet extends LegacyVaadinServlet { + public static String CUSTOM_SYSTEM_MESSAGES_PROPERTY = "custom-" + + SystemMessages.class.getName(); + /** * The name of the application class currently used. Only valid within one * request. @@ -184,6 +194,29 @@ public class ApplicationRunnerServlet extends LegacyVaadinServlet { return getApplicationRunnerURIs(request).applicationClassname; } + private final static class ProxyDeploymentConfiguration implements + InvocationHandler, Serializable { + private final DeploymentConfiguration originalConfiguration; + + private ProxyDeploymentConfiguration( + DeploymentConfiguration originalConfiguration) { + this.originalConfiguration = originalConfiguration; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) + throws Throwable { + if (method.getDeclaringClass() == DeploymentConfiguration.class) { + // Find the configuration instance to delegate to + DeploymentConfiguration configuration = findDeploymentConfiguration(originalConfiguration); + + return method.invoke(configuration, args); + } else { + return method.invoke(proxy, args); + } + } + } + private static final class ApplicationRunnerUIProvider extends UIProvider { private final Class<?> classToRun; @@ -309,23 +342,38 @@ public class ApplicationRunnerServlet extends LegacyVaadinServlet { return (DeploymentConfiguration) Proxy.newProxyInstance( DeploymentConfiguration.class.getClassLoader(), new Class[] { DeploymentConfiguration.class }, - new InvocationHandler() { - @Override - public Object invoke(Object proxy, Method method, - Object[] args) throws Throwable { - if (method.getDeclaringClass() == DeploymentConfiguration.class) { - // Find the configuration instance to delegate to - DeploymentConfiguration configuration = findDeploymentConfiguration(originalConfiguration); - - return method.invoke(configuration, args); - } else { - return method.invoke(proxy, args); - } - } - }); + new ProxyDeploymentConfiguration(originalConfiguration)); + } + + @Override + protected VaadinServletService createServletService( + DeploymentConfiguration deploymentConfiguration) + throws ServiceException { + VaadinServletService service = super + .createServletService(deploymentConfiguration); + final SystemMessagesProvider provider = service + .getSystemMessagesProvider(); + service.setSystemMessagesProvider(new SystemMessagesProvider() { + + @Override + public SystemMessages getSystemMessages( + SystemMessagesInfo systemMessagesInfo) { + if (systemMessagesInfo.getRequest() == null) { + return provider.getSystemMessages(systemMessagesInfo); + } + Object messages = systemMessagesInfo.getRequest().getAttribute( + CUSTOM_SYSTEM_MESSAGES_PROPERTY); + if (messages instanceof SystemMessages) { + return (SystemMessages) messages; + } + return provider.getSystemMessages(systemMessagesInfo); + } + + }); + return service; } - private DeploymentConfiguration findDeploymentConfiguration( + private static DeploymentConfiguration findDeploymentConfiguration( DeploymentConfiguration originalConfiguration) throws Exception { // First level of cache DeploymentConfiguration configuration = CurrentInstance @@ -344,16 +392,19 @@ public class ApplicationRunnerServlet extends LegacyVaadinServlet { * request. */ - HttpServletRequest currentRequest = request.get(); + HttpServletRequest currentRequest = VaadinServletService + .getCurrentServletRequest(); if (currentRequest != null) { HttpSession httpSession = currentRequest.getSession(false); if (httpSession != null) { Map<Class<?>, CurrentInstance> oldCurrent = CurrentInstance .setCurrent((VaadinSession) null); try { - session = getService().findVaadinSession( - new VaadinServletRequest(currentRequest, - getService())); + VaadinServletService service = (VaadinServletService) VaadinService + .getCurrent(); + session = service + .findVaadinSession(new VaadinServletRequest( + currentRequest, service)); } finally { /* * Clear some state set by findVaadinSession to @@ -377,9 +428,11 @@ public class ApplicationRunnerServlet extends LegacyVaadinServlet { .getAttribute(name); if (configuration == null) { + ApplicationRunnerServlet servlet = (ApplicationRunnerServlet) VaadinServlet + .getCurrent(); Class<?> classToRun; try { - classToRun = getClassToRun(); + classToRun = servlet.getClassToRun(); } catch (ClassNotFoundException e) { /* * This happens e.g. if the UI class defined in the @@ -402,7 +455,7 @@ public class ApplicationRunnerServlet extends LegacyVaadinServlet { } configuration = new DefaultDeploymentConfiguration( - getClass(), initParameters); + servlet.getClass(), initParameters); } else { configuration = originalConfiguration; } |