Repository: wicket Updated Branches: refs/heads/wicket-7.x d18ae6938 -> 2bb5ad6bc
WICKET-6358 Possibility for each browser tab to have independent wicket session Introduce overrideable methods for setting and getting the Wicket Session in HttpSession (cherry picked from commit d8206a23ca79ca66b3b9a0e53e2ccfe854b94b16) Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/2bb5ad6b Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/2bb5ad6b Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/2bb5ad6b Branch: refs/heads/wicket-7.x Commit: 2bb5ad6bc0845bbde298644c14f906407bdef82f Parents: d18ae69 Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Thu May 11 23:23:11 2017 +0200 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Wed May 31 09:14:51 2017 +0200 ---------------------------------------------------------------------- .../apache/wicket/session/HttpSessionStore.java | 32 +++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/2bb5ad6b/wicket-core/src/main/java/org/apache/wicket/session/HttpSessionStore.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/session/HttpSessionStore.java b/wicket-core/src/main/java/org/apache/wicket/session/HttpSessionStore.java index c73b3a4..fe8523c 100644 --- a/wicket-core/src/main/java/org/apache/wicket/session/HttpSessionStore.java +++ b/wicket-core/src/main/java/org/apache/wicket/session/HttpSessionStore.java @@ -101,7 +101,7 @@ public class HttpSessionStore implements ISessionStore @Override public final void bind(final Request request, final Session newSession) { - if (getAttribute(request, Session.SESSION_ATTRIBUTE_NAME) != newSession) + if (getWicketSession(request) != newSession) { // call template method onBind(request, newSession); @@ -120,7 +120,7 @@ public class HttpSessionStore implements ISessionStore new SessionBindingListener(applicationKey, newSession)); // register the session object itself - setAttribute(request, Session.SESSION_ATTRIBUTE_NAME, newSession); + setWicketSession(request, newSession); } } } @@ -128,14 +128,14 @@ public class HttpSessionStore implements ISessionStore @Override public void flushSession(Request request, Session session) { - if (getAttribute(request, Session.SESSION_ATTRIBUTE_NAME) != session) + if (getWicketSession(request) != session) { // this session is not yet bound, bind it bind(request, session); } else { - setAttribute(request, Session.SESSION_ATTRIBUTE_NAME, session); + setWicketSession(request, session); } } @@ -198,12 +198,34 @@ public class HttpSessionStore implements ISessionStore String sessionId = getSessionId(request, false); if (sessionId != null) { - return (Session)getAttribute(request, Session.SESSION_ATTRIBUTE_NAME); + return getWicketSession(request); } return null; } /** + * Reads the Wicket {@link Session} from the {@link HttpSession}'s attribute + * + * @param request The Wicket request + * @return The Wicket Session or {@code null} + */ + protected Session getWicketSession(final Request request) + { + return (Session) getAttribute(request, Session.SESSION_ATTRIBUTE_NAME); + } + + /** + * Stores the Wicket {@link Session} in an attribute in the {@link HttpSession} + * + * @param request The Wicket request + * @param session The Wicket session + */ + protected void setWicketSession(final Request request, final Session session) + { + setAttribute(request, Session.SESSION_ATTRIBUTE_NAME, session); + } + + /** * Template method that is called when a session is being bound to the session store. It is * called <strong>before</strong> the session object itself is added to this store (which is * done by calling {@link ISessionStore#setAttribute(Request, String, Serializable)} with key
