From 8f9c7386521c48885eabf09d72594c71552c07c5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Tue, 8 Nov 2011 13:57:39 +0200 Subject: [PATCH] Merge the functionality of the wrapped Session into WrappedRequest --- src/com/vaadin/terminal/WrappedRequest.java | 6 +++ .../server/AbstractCommunicationManager.java | 48 +++-------------- .../gwt/server/CommunicationManager.java | 52 +++++-------------- .../server/PortletCommunicationManager.java | 50 +++++------------- 4 files changed, 37 insertions(+), 119 deletions(-) diff --git a/src/com/vaadin/terminal/WrappedRequest.java b/src/com/vaadin/terminal/WrappedRequest.java index 0676818699..96d78b5561 100644 --- a/src/com/vaadin/terminal/WrappedRequest.java +++ b/src/com/vaadin/terminal/WrappedRequest.java @@ -9,4 +9,10 @@ public interface WrappedRequest { public String getRequestPathInfo(); + public int getSessionMaxInactiveInterval(); + + public Object getSessionAttribute(String name); + + public void setSessionAttribute(String name, Object attribute); + } diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 07547124fa..6e4cce6614 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -110,16 +110,6 @@ public abstract class AbstractCommunicationManager implements */ public interface Request extends WrappedRequest { - /** - * Gets a {@link Session} wrapper implementation representing the - * session for which this request was sent. - * - * Multiple Vaadin applications can be associated with a single session. - * - * @return Session - */ - public Session getSession(); - /** * Are the applications in this session running in a portlet or directly * as servlets. @@ -228,32 +218,6 @@ public abstract class AbstractCommunicationManager implements } - /** - * Generic wrapper interface for a (HTTP or Portlet) session. - * - * Several applications can be associated with a single session. - * - * TODO Document me! - * - * @see javax.servlet.http.HttpSession - * @see javax.portlet.PortletSession - * - * @author peholmst - */ - protected interface Session { - - public boolean isNew(); - - public Object getAttribute(String name); - - public void setAttribute(String name, Object o); - - public int getMaxInactiveInterval(); - - public Object getWrappedSession(); - - } - /** * TODO Document me! * @@ -707,7 +671,7 @@ public abstract class AbstractCommunicationManager implements InvalidUIDLSecurityKeyException { requestThemeName = request.getParameter("theme"); - maxInactiveInterval = request.getSession().getMaxInactiveInterval(); + maxInactiveInterval = request.getSessionMaxInactiveInterval(); // repaint requested or session has timed out and new one is created boolean repaintAll; final OutputStream out; @@ -891,11 +855,11 @@ public abstract class AbstractCommunicationManager implements .getAttribute(WRITE_SECURITY_TOKEN_FLAG); if (writeSecurityTokenFlag != null) { - String seckey = (String) request.getSession().getAttribute( - ApplicationConnection.UIDL_SECURITY_TOKEN_ID); + String seckey = (String) request + .getSessionAttribute(ApplicationConnection.UIDL_SECURITY_TOKEN_ID); if (seckey == null) { seckey = UUID.randomUUID().toString(); - request.getSession().setAttribute( + request.setSessionAttribute( ApplicationConnection.UIDL_SECURITY_TOKEN_ID, seckey); } outWriter.print("\"" + ApplicationConnection.UIDL_SECURITY_TOKEN_ID @@ -1289,8 +1253,8 @@ public abstract class AbstractCommunicationManager implements } else { // ApplicationServlet has stored the security token in the // session; check that it matched the one sent in the UIDL - String sessId = (String) request.getSession().getAttribute( - ApplicationConnection.UIDL_SECURITY_TOKEN_ID); + String sessId = (String) request + .getSessionAttribute(ApplicationConnection.UIDL_SECURITY_TOKEN_ID); if (sessId == null || !sessId.equals(bursts[0])) { throw new InvalidUIDLSecurityKeyException( diff --git a/src/com/vaadin/terminal/gwt/server/CommunicationManager.java b/src/com/vaadin/terminal/gwt/server/CommunicationManager.java index 16d44e6771..68e74145fa 100644 --- a/src/com/vaadin/terminal/gwt/server/CommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/CommunicationManager.java @@ -15,7 +15,6 @@ import java.util.UUID; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; import com.vaadin.Application; import com.vaadin.terminal.Paintable; @@ -80,10 +79,6 @@ public class CommunicationManager extends AbstractCommunicationManager { return "RequestURL:" + request.getRequestURI(); } - public Session getSession() { - return new HttpSessionWrapper(request.getSession()); - } - public Object getWrappedRequest() { return request; } @@ -99,6 +94,18 @@ public class CommunicationManager extends AbstractCommunicationManager { public String getRequestPathInfo() { return servlet.getRequestPathInfo(request); } + + public int getSessionMaxInactiveInterval() { + return request.getSession().getMaxInactiveInterval(); + } + + public Object getSessionAttribute(String name) { + return request.getSession().getAttribute(name); + } + + public void setSessionAttribute(String name, Object attribute) { + request.getSession().setAttribute(name, attribute); + } } /** @@ -140,41 +147,6 @@ public class CommunicationManager extends AbstractCommunicationManager { } - /** - * Concrete wrapper class for {@link HttpSession}. - * - * @see Session - */ - private static class HttpSessionWrapper implements Session { - - private final HttpSession session; - - public HttpSessionWrapper(HttpSession session) { - this.session = session; - } - - public Object getAttribute(String name) { - return session.getAttribute(name); - } - - public int getMaxInactiveInterval() { - return session.getMaxInactiveInterval(); - } - - public Object getWrappedSession() { - return session; - } - - public boolean isNew() { - return session.isNew(); - } - - public void setAttribute(String name, Object o) { - session.setAttribute(name, o); - } - - } - private static class AbstractApplicationServletWrapper implements Callback { private final AbstractApplicationServlet servlet; diff --git a/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java index f428a46643..cf77ce0cae 100644 --- a/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java @@ -15,7 +15,6 @@ import javax.portlet.ClientDataRequest; import javax.portlet.MimeResponse; import javax.portlet.PortletRequest; import javax.portlet.PortletResponse; -import javax.portlet.PortletSession; import javax.portlet.ResourceRequest; import javax.portlet.ResourceResponse; import javax.portlet.ResourceURL; @@ -86,10 +85,6 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { return "WindowID:" + request.getWindowID(); } - public Session getSession() { - return new PortletSessionWrapper(request.getPortletSession()); - } - public Object getWrappedRequest() { return request; } @@ -112,6 +107,18 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { } } + public int getSessionMaxInactiveInterval() { + return request.getPortletSession().getMaxInactiveInterval(); + } + + public Object getSessionAttribute(String name) { + return request.getPortletSession().getAttribute(name); + } + + public void setSessionAttribute(String name, Object attribute) { + request.getPortletSession().setAttribute(name, attribute); + } + } private static class PortletResponseWrapper implements Response { @@ -148,36 +155,6 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { } } - private static class PortletSessionWrapper implements Session { - - private final PortletSession session; - - public PortletSessionWrapper(PortletSession session) { - this.session = session; - } - - public Object getAttribute(String name) { - return session.getAttribute(name); - } - - public int getMaxInactiveInterval() { - return session.getMaxInactiveInterval(); - } - - public Object getWrappedSession() { - return session; - } - - public boolean isNew() { - return session.isNew(); - } - - public void setAttribute(String name, Object o) { - session.setAttribute(name, o); - } - - } - private static class AbstractApplicationPortletWrapper implements Callback { private final AbstractApplicationPortlet portlet; @@ -315,8 +292,7 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { } public boolean handleApplicationRequest(PortletRequest request, - PortletResponse response) - throws IOException { + PortletResponse response) throws IOException { return handleApplicationRequest(new PortletRequestWrapper(request), new PortletResponseWrapper(response)); } -- 2.39.5