From: Leif Åstrand Date: Fri, 28 Sep 2012 12:31:03 +0000 (+0300) Subject: Remove VaadinServletSession (#9638) X-Git-Tag: 7.0.0.beta3~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c057cf73a79e670a4d5458b03fe49c35ecd54675;p=vaadin-framework.git Remove VaadinServletSession (#9638) Change-Id: I0e25ba1a6d258b8601c009f6dc062b3f4bd3dbce --- diff --git a/server/src/com/vaadin/server/CommunicationManager.java b/server/src/com/vaadin/server/CommunicationManager.java index f876e748f8..5f61079261 100644 --- a/server/src/com/vaadin/server/CommunicationManager.java +++ b/server/src/com/vaadin/server/CommunicationManager.java @@ -110,8 +110,9 @@ public class CommunicationManager extends AbstractCommunicationManager { @Override protected InputStream getThemeResourceAsStream(UI uI, String themeName, String resource) { - VaadinServletSession session = (VaadinServletSession) uI.getSession(); - ServletContext servletContext = session.getHttpSession() + VaadinServletService service = (VaadinServletService) uI.getSession() + .getService(); + ServletContext servletContext = service.getServlet() .getServletContext(); return servletContext.getResourceAsStream("/" + VaadinServlet.THEME_DIRECTORY_PATH + themeName + "/" diff --git a/server/src/com/vaadin/server/GAEVaadinServlet.java b/server/src/com/vaadin/server/GAEVaadinServlet.java index 6c9c1882ea..c68f25a282 100644 --- a/server/src/com/vaadin/server/GAEVaadinServlet.java +++ b/server/src/com/vaadin/server/GAEVaadinServlet.java @@ -361,11 +361,18 @@ public class GAEVaadinServlet extends VaadinServlet { * * @param request */ - private void cleanSession(HttpServletRequest request) { - HttpSession session = request.getSession(false); - if (session != null) { - session.removeAttribute(VaadinServletSession.class.getName()); + private void cleanSession(VaadinServletRequest request) { + // Should really be replaced with a session storage API... + WrappedSession wrappedSession = request.getWrappedSession(false); + if (wrappedSession == null) { + return; + } + VaadinServiceSession serviceSession = VaadinServiceSession + .getForSession(getService(), wrappedSession); + if (serviceSession == null) { + return; } + serviceSession.removeFromSession(getService()); } /** diff --git a/server/src/com/vaadin/server/VaadinService.java b/server/src/com/vaadin/server/VaadinService.java index add32bf57b..c56d6caeb5 100644 --- a/server/src/com/vaadin/server/VaadinService.java +++ b/server/src/com/vaadin/server/VaadinService.java @@ -437,8 +437,10 @@ public abstract class VaadinService implements Serializable { * @throws ServletException * @throws MalformedURLException */ - protected abstract VaadinServiceSession createVaadinSession( - VaadinRequest request) throws ServiceException; + protected VaadinServiceSession createVaadinSession(VaadinRequest request) + throws ServiceException { + return new VaadinServiceSession(this); + } private void onVaadinSessionStarted(VaadinRequest request, VaadinServiceSession session) throws ServiceException { diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java index 7f664be6fb..e73be682c2 100644 --- a/server/src/com/vaadin/server/VaadinServlet.java +++ b/server/src/com/vaadin/server/VaadinServlet.java @@ -232,7 +232,7 @@ public class VaadinServlet extends HttpServlet implements Constants { return; } - VaadinServletSession vaadinSession = null; + VaadinServiceSession vaadinSession = null; try { // If a duplicate "close application" URL is received for an @@ -254,8 +254,7 @@ public class VaadinServlet extends HttpServlet implements Constants { } // Find out the service session this request is related to - vaadinSession = (VaadinServletSession) getService() - .findVaadinSession(request); + vaadinSession = getService().findVaadinSession(request); if (vaadinSession == null) { return; } diff --git a/server/src/com/vaadin/server/VaadinServletService.java b/server/src/com/vaadin/server/VaadinServletService.java index ca894b8a4f..d746ee2303 100644 --- a/server/src/com/vaadin/server/VaadinServletService.java +++ b/server/src/com/vaadin/server/VaadinServletService.java @@ -185,12 +185,6 @@ public class VaadinServletService extends VaadinService { return (VaadinServletResponse) VaadinService.getCurrentResponse(); } - @Override - protected VaadinServiceSession createVaadinSession(VaadinRequest request) - throws ServiceException { - return new VaadinServletSession(this); - } - @Override public String getServiceName() { return getServlet().getServletName(); diff --git a/server/src/com/vaadin/server/VaadinServletSession.java b/server/src/com/vaadin/server/VaadinServletSession.java deleted file mode 100644 index aa31a19c1b..0000000000 --- a/server/src/com/vaadin/server/VaadinServletSession.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.server; - -import javax.servlet.http.HttpSession; -import javax.servlet.http.HttpSessionBindingListener; - -/** - * Web application context for Vaadin applications. - * - * This is automatically added as a {@link HttpSessionBindingListener} when - * added to a {@link HttpSession}. - * - * @author Vaadin Ltd. - * @since 3.1 - * - * @deprecated might be refactored or removed before 7.0.0 - */ -@Deprecated -@SuppressWarnings("serial") -public class VaadinServletSession extends VaadinServiceSession { - - /** - * 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); - } - - /** - * Gets the http-session application is running in. - * - * @return HttpSession this application context resides in. - */ - public HttpSession getHttpSession() { - WrappedSession session = getSession(); - return ((WrappedHttpSession) session).getHttpSession(); - } - -} diff --git a/server/src/com/vaadin/server/WrappedHttpSession.java b/server/src/com/vaadin/server/WrappedHttpSession.java index e13a63635b..65db010ba9 100644 --- a/server/src/com/vaadin/server/WrappedHttpSession.java +++ b/server/src/com/vaadin/server/WrappedHttpSession.java @@ -88,4 +88,9 @@ public class WrappedHttpSession implements WrappedSession { session.invalidate(); } + @Override + public String getId() { + return session.getId(); + } + } diff --git a/server/src/com/vaadin/server/WrappedPortletSession.java b/server/src/com/vaadin/server/WrappedPortletSession.java index 03c1d7ba1f..f4a6003ed5 100644 --- a/server/src/com/vaadin/server/WrappedPortletSession.java +++ b/server/src/com/vaadin/server/WrappedPortletSession.java @@ -74,4 +74,9 @@ public class WrappedPortletSession implements WrappedSession { public void invalidate() { session.invalidate(); } + + @Override + public String getId() { + return session.getId(); + } } diff --git a/server/src/com/vaadin/server/WrappedSession.java b/server/src/com/vaadin/server/WrappedSession.java index 34443239c7..cf0b1a2fbd 100644 --- a/server/src/com/vaadin/server/WrappedSession.java +++ b/server/src/com/vaadin/server/WrappedSession.java @@ -86,4 +86,11 @@ public interface WrappedSession { * @see PortletSession#invalidate() */ public void invalidate(); + + /** + * Gets a string with a unique identifier for the session. + * + * @return a unique session id string + */ + public String getId(); } diff --git a/uitest/src/com/vaadin/tests/applicationcontext/ChangeSessionId.java b/uitest/src/com/vaadin/tests/applicationcontext/ChangeSessionId.java index 4495b343d0..fa0f13e172 100644 --- a/uitest/src/com/vaadin/tests/applicationcontext/ChangeSessionId.java +++ b/uitest/src/com/vaadin/tests/applicationcontext/ChangeSessionId.java @@ -1,7 +1,6 @@ package com.vaadin.tests.applicationcontext; import com.vaadin.server.VaadinService; -import com.vaadin.server.VaadinServletSession; import com.vaadin.tests.components.AbstractTestCase; import com.vaadin.tests.util.Log; import com.vaadin.ui.Button; @@ -30,15 +29,13 @@ public class ChangeSessionId extends AbstractTestCase { })); setMainWindow(mainWindow); - loginButton.addListener(new ClickListener() { + loginButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { - VaadinServletSession context = ((VaadinServletSession) getContext()); - - String oldSessionId = context.getHttpSession().getId(); - context.getService().reinitializeSession( - VaadinService.getCurrentRequest()); - String newSessionId = context.getHttpSession().getId(); + String oldSessionId = getSessionId(); + VaadinService.reinitializeSession(VaadinService + .getCurrentRequest()); + String newSessionId = getSessionId(); if (oldSessionId.equals(newSessionId)) { log.log("FAILED! Both old and new session id is " + newSessionId); @@ -57,7 +54,7 @@ public class ChangeSessionId extends AbstractTestCase { } protected String getSessionId() { - return ((VaadinServletSession) getContext()).getHttpSession().getId(); + return getContext().getSession().getId(); } @Override