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;
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;
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;
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
* 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
.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
}
configuration = new DefaultDeploymentConfiguration(
- getClass(), initParameters);
+ servlet.getClass(), initParameters);
} else {
configuration = originalConfiguration;
}
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(
allOf(startsWith("1. Serialized UI in"),
containsString(" into "), endsWith(" bytes")));
}
+
+ private void serialize() {
+ $(ButtonElement.class).first().click();
+ }
}