From 9d73de5162b57e85dba00ca8c5f3ebf47b4ed240 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Fri, 28 Sep 2012 14:22:00 +0300 Subject: [PATCH] Ensure there's a service for each session (#9733) Change-Id: I9425c2d33fd09759b18930741344e9181dc79364 --- .../com/vaadin/server/VaadinPortletService.java | 2 +- .../com/vaadin/server/VaadinPortletSession.java | 10 ++++++++++ .../com/vaadin/server/VaadinServiceSession.java | 14 ++++++++++++++ .../com/vaadin/server/VaadinServletService.java | 2 +- .../com/vaadin/server/VaadinServletSession.java | 10 ++++++++++ .../tests/data/converter/ConverterFactory.java | 11 +++++++---- .../tests/server/TestStreamVariableMapping.java | 4 ++-- .../AbstractFieldValueConversions.java | 2 +- .../abstractfield/DefaultConverterFactory.java | 2 +- .../abstractfield/RemoveListenersOnDetach.java | 5 ++--- .../server/component/label/LabelConverters.java | 2 +- .../server/component/root/CustomUIClassLoader.java | 2 +- .../component/window/AddRemoveSubWindow.java | 2 +- .../component/window/AttachDetachWindow.java | 2 +- .../tests/src/com/vaadin/ui/LabelDataSource.java | 2 +- 15 files changed, 54 insertions(+), 18 deletions(-) diff --git a/server/src/com/vaadin/server/VaadinPortletService.java b/server/src/com/vaadin/server/VaadinPortletService.java index 298b875a55..aa81c39d9d 100644 --- a/server/src/com/vaadin/server/VaadinPortletService.java +++ b/server/src/com/vaadin/server/VaadinPortletService.java @@ -208,7 +208,7 @@ public class VaadinPortletService extends VaadinService { @Override protected VaadinServiceSession createVaadinSession(VaadinRequest request) throws ServiceException { - return new VaadinPortletSession(); + return new VaadinPortletSession(this); } @Override diff --git a/server/src/com/vaadin/server/VaadinPortletSession.java b/server/src/com/vaadin/server/VaadinPortletSession.java index 427314975e..6b89342b2b 100644 --- a/server/src/com/vaadin/server/VaadinPortletSession.java +++ b/server/src/com/vaadin/server/VaadinPortletSession.java @@ -66,6 +66,16 @@ public class VaadinPortletSession extends VaadinServiceSession { private final Map sharedParameterActionNameMap = new HashMap(); private final Map sharedParameterActionValueMap = new HashMap(); + /** + * Create a portlet service session for the given portlet service + * + * @param service + * the portlet service to which the new session belongs + */ + public VaadinPortletSession(VaadinPortletService service) { + super(service); + } + public PortletSession getPortletSession() { WrappedSession wrappedSession = getSession(); PortletSession session = ((WrappedPortletSession) wrappedSession) diff --git a/server/src/com/vaadin/server/VaadinServiceSession.java b/server/src/com/vaadin/server/VaadinServiceSession.java index 2b6b651404..c581a1930c 100644 --- a/server/src/com/vaadin/server/VaadinServiceSession.java +++ b/server/src/com/vaadin/server/VaadinServiceSession.java @@ -198,6 +198,16 @@ public class VaadinServiceSession implements HttpSessionBindingListener, private VaadinService service; + /** + * Create a new service session tied to a Vaadin service + * + * @param service + * the Vaadin service for the new session + */ + public VaadinServiceSession(VaadinService service) { + this.service = service; + } + /** * @see javax.servlet.http.HttpSessionBindingListener#valueBound(HttpSessionBindingEvent) */ @@ -1123,4 +1133,8 @@ public class VaadinServiceSession implements HttpSessionBindingListener, return Collections.unmodifiableList(uiProviders); } + public VaadinService getService() { + return service; + } + } diff --git a/server/src/com/vaadin/server/VaadinServletService.java b/server/src/com/vaadin/server/VaadinServletService.java index 5d01c84948..ca894b8a4f 100644 --- a/server/src/com/vaadin/server/VaadinServletService.java +++ b/server/src/com/vaadin/server/VaadinServletService.java @@ -188,7 +188,7 @@ public class VaadinServletService extends VaadinService { @Override protected VaadinServiceSession createVaadinSession(VaadinRequest request) throws ServiceException { - return new VaadinServletSession(); + return new VaadinServletSession(this); } @Override diff --git a/server/src/com/vaadin/server/VaadinServletSession.java b/server/src/com/vaadin/server/VaadinServletSession.java index fa048194c3..78f58d64fe 100644 --- a/server/src/com/vaadin/server/VaadinServletSession.java +++ b/server/src/com/vaadin/server/VaadinServletSession.java @@ -41,6 +41,16 @@ public class VaadinServletSession extends VaadinServiceSession { private transient boolean reinitializingSession = false; + /** + * Create a servlet service session for the given servlet service + * + * @param service + * the servlet service to which the new session belongs + */ + public VaadinServletSession(VaadinServletService service) { + super(service); + } + @Override public void valueUnbound(HttpSessionBindingEvent event) { if (!reinitializingSession) { diff --git a/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java b/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java index 72747dca2d..0ba7779e79 100644 --- a/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java +++ b/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java @@ -66,7 +66,8 @@ public class ConverterFactory extends TestCase { public void testApplicationConverterFactoryInBackgroundThread() { VaadinServiceSession.setCurrent(null); - final VaadinServiceSession appWithCustomIntegerConverter = new VaadinServiceSession(); + final VaadinServiceSession appWithCustomIntegerConverter = new VaadinServiceSession( + null); appWithCustomIntegerConverter .setConverterFactory(new ConverterFactory42()); @@ -83,7 +84,8 @@ public class ConverterFactory extends TestCase { } public void testApplicationConverterFactoryForDetachedComponent() { - final VaadinServiceSession appWithCustomIntegerConverter = new VaadinServiceSession(); + final VaadinServiceSession appWithCustomIntegerConverter = new VaadinServiceSession( + null); appWithCustomIntegerConverter .setConverterFactory(new ConverterFactory42()); VaadinServiceSession.setCurrent(appWithCustomIntegerConverter); @@ -96,10 +98,11 @@ public class ConverterFactory extends TestCase { } public void testApplicationConverterFactoryForDifferentThanCurrentApplication() { - final VaadinServiceSession fieldAppWithCustomIntegerConverter = new VaadinServiceSession(); + final VaadinServiceSession fieldAppWithCustomIntegerConverter = new VaadinServiceSession( + null); fieldAppWithCustomIntegerConverter .setConverterFactory(new ConverterFactory42()); - VaadinServiceSession.setCurrent(new VaadinServiceSession()); + VaadinServiceSession.setCurrent(new VaadinServiceSession(null)); TextField tf = new TextField("", "123") { @Override diff --git a/server/tests/src/com/vaadin/tests/server/TestStreamVariableMapping.java b/server/tests/src/com/vaadin/tests/server/TestStreamVariableMapping.java index 0130086371..5c74077ca9 100644 --- a/server/tests/src/com/vaadin/tests/server/TestStreamVariableMapping.java +++ b/server/tests/src/com/vaadin/tests/server/TestStreamVariableMapping.java @@ -21,7 +21,7 @@ public class TestStreamVariableMapping extends TestCase { @Override protected void setUp() throws Exception { - final VaadinServiceSession application = new VaadinServiceSession(); + final VaadinServiceSession application = new VaadinServiceSession(null); final UI uI = new UI() { @Override protected void init(VaadinRequest request) { @@ -66,7 +66,7 @@ public class TestStreamVariableMapping extends TestCase { } private CommunicationManager createCommunicationManager() { - return new CommunicationManager(new VaadinServiceSession()); + return new CommunicationManager(new VaadinServiceSession(null)); } } diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java index faec1d99a1..8d4cdc3c7c 100644 --- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java +++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java @@ -186,7 +186,7 @@ public class AbstractFieldValueConversions extends TestCase { } public void testNumberDoubleConverterChange() { - final VaadinServiceSession a = new VaadinServiceSession(); + final VaadinServiceSession a = new VaadinServiceSession(null); VaadinServiceSession.setCurrent(a); TextField tf = new TextField() { @Override diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/DefaultConverterFactory.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/DefaultConverterFactory.java index b29876ef3c..43a7d90922 100644 --- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/DefaultConverterFactory.java +++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/DefaultConverterFactory.java @@ -26,7 +26,7 @@ public class DefaultConverterFactory extends TestCase { } public void testDefaultNumberConversion() { - VaadinServiceSession app = new VaadinServiceSession(); + VaadinServiceSession app = new VaadinServiceSession(null); VaadinServiceSession.setCurrent(app); TextField tf = new TextField(); tf.setLocale(new Locale("en", "US")); diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java index bfa79ec9c8..83bb7c4613 100644 --- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java +++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java @@ -18,9 +18,8 @@ public class RemoveListenersOnDetach { int numReadOnlyChanges = 0; AbstractField field = new AbstractField() { - final private VaadinServiceSession application = new VaadinServiceSession() { - - }; + final private VaadinServiceSession application = new VaadinServiceSession( + null); private UI uI = new UI() { @Override diff --git a/server/tests/src/com/vaadin/tests/server/component/label/LabelConverters.java b/server/tests/src/com/vaadin/tests/server/component/label/LabelConverters.java index 37363e7d4b..68e983f8a5 100644 --- a/server/tests/src/com/vaadin/tests/server/component/label/LabelConverters.java +++ b/server/tests/src/com/vaadin/tests/server/component/label/LabelConverters.java @@ -37,7 +37,7 @@ public class LabelConverters extends TestCase { } public void testIntegerDataSource() { - VaadinServiceSession.setCurrent(new VaadinServiceSession()); + VaadinServiceSession.setCurrent(new VaadinServiceSession(null)); Label l = new Label("Foo"); Property ds = new MethodProperty(Person.createTestPerson1(), "age"); diff --git a/server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java b/server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java index 161165cf64..e071c0e484 100644 --- a/server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java +++ b/server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java @@ -113,7 +113,7 @@ public class CustomUIClassLoader extends TestCase { } private VaadinServiceSession createStubApplication() { - return new VaadinServiceSession() { + return new VaadinServiceSession(null) { @Override public DeploymentConfiguration getConfiguration() { return createConfigurationMock(); diff --git a/server/tests/src/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java b/server/tests/src/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java index 19cf69422f..8aac9a9598 100644 --- a/server/tests/src/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java +++ b/server/tests/src/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java @@ -25,7 +25,7 @@ public class AddRemoveSubWindow { @Test public void addSubWindow() { - VaadinServiceSession.setCurrent(new VaadinServiceSession()); + VaadinServiceSession.setCurrent(new VaadinServiceSession(null)); TestApp app = new TestApp(); app.init(); Window subWindow = new Window("Sub window"); diff --git a/server/tests/src/com/vaadin/tests/server/component/window/AttachDetachWindow.java b/server/tests/src/com/vaadin/tests/server/component/window/AttachDetachWindow.java index 5374641bea..a00e5e0996 100644 --- a/server/tests/src/com/vaadin/tests/server/component/window/AttachDetachWindow.java +++ b/server/tests/src/com/vaadin/tests/server/component/window/AttachDetachWindow.java @@ -15,7 +15,7 @@ import com.vaadin.ui.Window; public class AttachDetachWindow { - private VaadinServiceSession testApp = new VaadinServiceSession(); + private VaadinServiceSession testApp = new VaadinServiceSession(null); private interface TestContainer { public boolean attachCalled(); diff --git a/server/tests/src/com/vaadin/ui/LabelDataSource.java b/server/tests/src/com/vaadin/ui/LabelDataSource.java index 30295553a2..506a635814 100644 --- a/server/tests/src/com/vaadin/ui/LabelDataSource.java +++ b/server/tests/src/com/vaadin/ui/LabelDataSource.java @@ -39,7 +39,7 @@ public class LabelDataSource { @Before public void setup() { - vaadinSession = new VaadinServiceSession(); + vaadinSession = new VaadinServiceSession(null); VaadinServiceSession.setCurrent(vaadinSession); label = new Label(); -- 2.39.5