diff options
author | Leif Åstrand <leif@vaadin.com> | 2014-12-30 10:22:44 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-01-07 08:09:32 +0000 |
commit | c0b90c7e3aed4b283d6202ee6cee764631540100 (patch) | |
tree | ea7ecd51668498f722269cfa547deef1ce9fb9d5 | |
parent | 0c9625d05c829a66b2b42fb5c3f14384d8c0f4a8 (diff) | |
download | vaadin-framework-c0b90c7e3aed4b283d6202ee6cee764631540100.tar.gz vaadin-framework-c0b90c7e3aed4b283d6202ee6cee764631540100.zip |
Fix serialization with ApplicationRunnerServlet
Make the InvocationHandler used by the DeploymentConfiguration proxying
feature serializable. Also make findDeploymentConfiguration static to
avoid serializing an ApplicatinRunnerServlet instance.
Change-Id: I360276ae42a875e9227df34e8aabf8ce2a697bc2
-rw-r--r-- | uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java | 61 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/components/ui/UISerializationTest.java | 25 |
2 files changed, 56 insertions, 30 deletions
diff --git a/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java index 1f72495596..1cbb1aa039 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; @@ -48,7 +49,10 @@ import com.vaadin.server.SessionInitListener; 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; @@ -184,6 +188,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 +336,10 @@ 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)); } - private DeploymentConfiguration findDeploymentConfiguration( + private static DeploymentConfiguration findDeploymentConfiguration( DeploymentConfiguration originalConfiguration) throws Exception { // First level of cache DeploymentConfiguration configuration = CurrentInstance @@ -344,16 +358,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 +394,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 +421,7 @@ public class ApplicationRunnerServlet extends LegacyVaadinServlet { } configuration = new DefaultDeploymentConfiguration( - getClass(), initParameters); + servlet.getClass(), initParameters); } else { configuration = originalConfiguration; } diff --git a/uitest/src/com/vaadin/tests/components/ui/UISerializationTest.java b/uitest/src/com/vaadin/tests/components/ui/UISerializationTest.java index f499f29b9b..649f48c9ce 100644 --- a/uitest/src/com/vaadin/tests/components/ui/UISerializationTest.java +++ b/uitest/src/com/vaadin/tests/components/ui/UISerializationTest.java @@ -1,21 +1,24 @@ package com.vaadin.tests.components.ui; -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.tests.tb3.SingleBrowserTest; -import org.junit.Ignore; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.startsWith; +import static org.junit.Assert.assertThat; + import org.junit.Test; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThat; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.SingleBrowserTest; public class UISerializationTest extends SingleBrowserTest { @Test - @Ignore - // Broken on all browsers since 9696e6c3e7e952b66ac3f5c9ddc3dfca4233451e - public void tb2test() throws Exception { + public void uiIsSerialized() throws Exception { openTestURL(); - $(ButtonElement.class).first().click(); + + serialize(); + assertThat(getLogRow(0), startsWith("3. Diff states match, size: ")); assertThat(getLogRow(1), startsWith("2. Deserialized UI in ")); assertThat( @@ -23,4 +26,8 @@ public class UISerializationTest extends SingleBrowserTest { allOf(startsWith("1. Serialized UI in"), containsString(" into "), endsWith(" bytes"))); } + + private void serialize() { + $(ButtonElement.class).first().click(); + } } |