You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2013/02/19 08:55:29 UTC

[12/19] git commit: WICKET-5040 aligned #exists() with #get(), i.e. check session store for session if none is set to ThreadContext yet

WICKET-5040 aligned #exists() with #get(), i.e. check session store for
session if none is set to ThreadContext yet


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/2672f886
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/2672f886
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/2672f886

Branch: refs/heads/reference-guide
Commit: 2672f886c528ba655c1662f1b08cc48c84b5f485
Parents: 3a3aed9
Author: svenmeier <sv...@apache.org>
Authored: Thu Feb 14 15:42:55 2013 +0100
Committer: svenmeier <sv...@apache.org>
Committed: Thu Feb 14 15:42:55 2013 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/wicket/Session.java   |   26 ++++++++++++---
 1 files changed, 21 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/2672f886/wicket-core/src/main/java/org/apache/wicket/Session.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/Session.java b/wicket-core/src/main/java/org/apache/wicket/Session.java
index fa2b655..7551b58 100644
--- a/wicket-core/src/main/java/org/apache/wicket/Session.java
+++ b/wicket-core/src/main/java/org/apache/wicket/Session.java
@@ -38,9 +38,9 @@ import org.apache.wicket.request.Request;
 import org.apache.wicket.request.cycle.RequestCycle;
 import org.apache.wicket.session.ISessionStore;
 import org.apache.wicket.settings.IApplicationSettings;
-import org.apache.wicket.util.io.IClusterable;
 import org.apache.wicket.util.IProvider;
 import org.apache.wicket.util.LazyInitializer;
+import org.apache.wicket.util.io.IClusterable;
 import org.apache.wicket.util.lang.Objects;
 import org.apache.wicket.util.tester.BaseWicketTester;
 import org.apache.wicket.util.time.Duration;
@@ -125,17 +125,33 @@ public abstract class Session implements IClusterable, IEventSink
 	private final IProvider<PageAccessSynchronizer> pageAccessSynchronizer;
 
 	/**
-	 * Checks if the <code>Session</code> threadlocal is set in this thread
+	 * Checks existence of a <code>Session</code> associated with the current thread.
 	 * 
-	 * @return true if {@link Session#get()} can return the instance of session, false otherwise
+	 * @return {@code true} if {@link Session#get()} can return the instance of session,
+	 *         {@code false} otherwise
 	 */
 	public static boolean exists()
 	{
-		return ThreadContext.getSession() != null;
+		Session session = ThreadContext.getSession();
+
+		if (session == null)
+		{
+			// no session is available via ThreadContext, so lookup in session store
+			RequestCycle requestCycle = RequestCycle.get();
+			if (requestCycle != null)
+			{
+				session = Application.get().getSessionStore().lookup(requestCycle.getRequest());
+				if (session != null)
+				{
+					ThreadContext.setSession(session);
+				}
+			}
+		}
+		return session != null;
 	}
 
 	/**
-	 * Returns session associated to current thread. Should always return a session during a request
+	 * Returns session associated to current thread. Always returns a session during a request
 	 * cycle, even though the session might be temporary
 	 * 
 	 * @return session.