wicket-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehillen...@apache.org
Subject svn commit: r525436 - in /incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http: AbstractHttpSessionStore.java HttpSessionStore.java SecondLevelCacheSessionStore.java WebApplication.java
Date Wed, 04 Apr 2007 06:22:17 GMT
Author: ehillenius
Date: Tue Apr  3 23:22:16 2007
New Revision: 525436

URL: http://svn.apache.org/viewvc?view=rev&rev=525436
Log:
fixes for stateless session support

Modified:
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/AbstractHttpSessionStore.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/HttpSessionStore.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/SecondLevelCacheSessionStore.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/WebApplication.java

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/AbstractHttpSessionStore.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/AbstractHttpSessionStore.java?view=diff&rev=525436&r1=525435&r2=525436
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/AbstractHttpSessionStore.java
(original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/AbstractHttpSessionStore.java
Tue Apr  3 23:22:16 2007
@@ -46,9 +46,6 @@
 public abstract class AbstractHttpSessionStore implements ISessionStore
 {
 
-	/** log. */
-	protected static Log log = LogFactory.getLog(AbstractHttpSessionStore.class);
-
 	/**
 	 * Reacts on unbinding from the session by cleaning up the session related
 	 * application data.
@@ -66,6 +63,9 @@
 		/** The unique key of the application within this web application. */
 		private final String applicationKey;
 
+		/** Whether it is already unbound. */
+		private boolean unbound = false;
+
 		/**
 		 * Construct.
 		 * 
@@ -93,49 +93,71 @@
 		 */
 		public void valueUnbound(HttpSessionBindingEvent evt)
 		{
-			Application application = Application.get(applicationKey);
-			if (application != null)
+			if (!unbound)
 			{
-				application.getSessionStore().unbind(sessionId);
+				unbound = true;
+				Application application = Application.get(applicationKey);
+				if (application != null)
+				{
+					application.getSessionStore().unbind(sessionId);
+				}
 			}
 		}
 	}
 
+	/** log. */
+	protected static Log log = LogFactory.getLog(AbstractHttpSessionStore.class);
+
+	/** The web application for this store. Is never null. */
 	protected final WebApplication application;
 
 	/**
 	 * Construct.
+	 * 
+	 * @param application
+	 *            The application to construct this store for
 	 */
-	public AbstractHttpSessionStore()
+	public AbstractHttpSessionStore(Application application)
 	{
+		if (application == null)
+		{
+			throw new IllegalArgumentException("the application object must be provided");
+		}
 		// sanity check
-		Application app = Application.get();
-		if (!(app instanceof WebApplication))
+		if (!(application instanceof WebApplication))
 		{
 			throw new IllegalStateException(getClass().getName()
 					+ " can only operate in the context of web applications");
 		}
-		this.application = (WebApplication)app;
+		this.application = (WebApplication)application;
 	}
 
 	/**
-	 * @see wicket.session.ISessionStore#invalidate(Request)
+	 * @see wicket.session.ISessionStore#bind(wicket.Request, wicket.Session)
 	 */
-	public final void invalidate(Request request)
+	public final void bind(Request request, Session newSession)
 	{
+		// call template method
+		onBind(request, newSession);
+
 		WebRequest webRequest = toWebRequest(request);
 		HttpSession httpSession = getHttpSession(webRequest);
-		if (httpSession != null)
-		{
-			try
-			{
-				httpSession.invalidate();
-			}
-			catch (IllegalStateException e)
-			{
-				// Ignore
-			}
-		}
+
+		// register an unbinding listener for cleaning up
+		String applicationKey = application.getApplicationKey();
+		httpSession.setAttribute("Wicket:SessionUnbindingListener-" + applicationKey,
+				new SessionBindingListener(applicationKey, httpSession.getId()));
+
+		// register the session object itself
+		setAttribute(webRequest, Session.SESSION_ATTRIBUTE_NAME, newSession);
+	}
+
+	/**
+	 * @see wicket.session.ISessionStore#destroy()
+	 */
+	public void destroy()
+	{
+		// nop
 	}
 
 	/**
@@ -154,7 +176,7 @@
 		{
 			httpSession = webRequest.getHttpServletRequest().getSession(true);
 			id = httpSession.getId();
-			IRequestLogger logger = Application.get().getRequestLogger();
+			IRequestLogger logger = application.getRequestLogger();
 			if (logger != null)
 				logger.sessionCreated(id);
 		}
@@ -162,32 +184,36 @@
 	}
 
 	/**
-	 * @see wicket.session.ISessionStore#bind(wicket.Request, wicket.Session)
+	 * @see wicket.session.ISessionStore#invalidate(Request)
 	 */
-	public final void bind(Request request, Session newSession)
+	public final void invalidate(Request request)
 	{
-		// call template method
-		onBind(request, newSession);
-
 		WebRequest webRequest = toWebRequest(request);
 		HttpSession httpSession = getHttpSession(webRequest);
+		if (httpSession != null)
+		{
+			String applicationKey = application.getApplicationKey();
+			try
+			{
+				SessionBindingListener l = (SessionBindingListener)httpSession
+						.getAttribute("Wicket:SessionUnbindingListener-" + applicationKey);
+				if (l != null)
+				{
+					l.unbound = true;
+				}
 
-		// register an unbinding listener for cleaning up
-		String applicationKey = application.getApplicationKey();
-		httpSession.setAttribute("Wicket:SessionUnbindingListener-" + applicationKey,
-				new SessionBindingListener(applicationKey, httpSession.getId()));
+				// call unbind
+				unbind(httpSession.getId());
 
-		// register the session object itself
-		setAttribute(webRequest, Session.SESSION_ATTRIBUTE_NAME, newSession);
-	}
+				// tell the app server the session is no longer valid
+				httpSession.invalidate();
+			}
+			catch (IllegalStateException e)
+			{
+				// can safely be ignored
+			}
 
-	/**
-	 * @see wicket.session.ISessionStore#unbind(java.lang.String)
-	 */
-	public final void unbind(String sessionId)
-	{
-		application.sessionDestroyed(sessionId);
-		onUnbind(sessionId);
+		}
 	}
 
 	/**
@@ -205,24 +231,39 @@
 	}
 
 	/**
-	 * Cast {@link Request} to {@link WebRequest}.
+	 * @see wicket.session.ISessionStore#newVersionManager(Page)
+	 */
+	public IPageVersionManager newVersionManager(Page page)
+	{
+		final IPageSettings settings = page.getSession().getApplication().getPageSettings();
+		return new UndoPageVersionManager(page, 20);
+	}
+
+	/**
+	 * Noop implementation. Clients can override this method.
 	 * 
-	 * @param request
-	 *            The request to cast
-	 * @return The web request
+	 * @see wicket.session.ISessionStore#onBeginRequest(wicket.Request)
 	 */
-	protected final WebRequest toWebRequest(Request request)
+	public void onBeginRequest(Request request)
 	{
-		if (request == null)
-		{
-			return null;
-		}
-		if (!(request instanceof WebRequest))
-		{
-			throw new IllegalArgumentException(getClass().getName()
-					+ " can only work with WebRequests");
-		}
-		return (WebRequest)request;
+	}
+
+	/**
+	 * Noop implementation. Clients can override this method.
+	 * 
+	 * @see wicket.session.ISessionStore#onEndRequest(wicket.Request)
+	 */
+	public void onEndRequest(Request request)
+	{
+	}
+
+	/**
+	 * @see wicket.session.ISessionStore#unbind(java.lang.String)
+	 */
+	public final void unbind(String sessionId)
+	{
+		onUnbind(sessionId);
+		application.sessionDestroyed(sessionId);
 	}
 
 	/**
@@ -272,37 +313,23 @@
 	}
 
 	/**
-	 * Noop implementation. Clients can override this method.
-	 * 
-	 * @see wicket.session.ISessionStore#onBeginRequest(wicket.Request)
-	 */
-	public void onBeginRequest(Request request)
-	{
-	}
-
-	/**
-	 * Noop implementation. Clients can override this method.
+	 * Cast {@link Request} to {@link WebRequest}.
 	 * 
-	 * @see wicket.session.ISessionStore#onEndRequest(wicket.Request)
-	 */
-	public void onEndRequest(Request request)
-	{
-	}
-
-	/**
-	 * @see wicket.session.ISessionStore#newVersionManager(Page)
-	 */
-	public IPageVersionManager newVersionManager(Page page)
-	{
-		final IPageSettings settings = page.getSession().getApplication().getPageSettings();
-		return new UndoPageVersionManager(page, 20);
-	}
-
-	/**
-	 * @see wicket.session.ISessionStore#destroy()
+	 * @param request
+	 *            The request to cast
+	 * @return The web request
 	 */
-	public void destroy()
+	protected final WebRequest toWebRequest(Request request)
 	{
-		// nop
+		if (request == null)
+		{
+			return null;
+		}
+		if (!(request instanceof WebRequest))
+		{
+			throw new IllegalArgumentException(getClass().getName()
+					+ " can only work with WebRequests");
+		}
+		return (WebRequest)request;
 	}
 }

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/HttpSessionStore.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/HttpSessionStore.java?view=diff&rev=525436&r1=525435&r2=525436
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/HttpSessionStore.java
(original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/HttpSessionStore.java
Tue Apr  3 23:22:16 2007
@@ -23,6 +23,7 @@
 import javax.servlet.http.HttpSession;
 
 import wicket.AccessStackPageMap;
+import wicket.Application;
 import wicket.IPageMap;
 import wicket.Request;
 import wicket.Session;
@@ -35,6 +36,17 @@
  */
 public class HttpSessionStore extends AbstractHttpSessionStore
 {
+	/**
+	 * Construct.
+	 * 
+	 * @param application
+	 *            The application to construct this store for
+	 */
+	public HttpSessionStore(Application application)
+	{
+		super(application);
+	}
+
 	/**
 	 * @see wicket.session.ISessionStore#createPageMap(java.lang.String,
 	 *      wicket.Session)

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/SecondLevelCacheSessionStore.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/SecondLevelCacheSessionStore.java?view=diff&rev=525436&r1=525435&r2=525436
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/SecondLevelCacheSessionStore.java
(original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/SecondLevelCacheSessionStore.java
Tue Apr  3 23:22:16 2007
@@ -371,12 +371,13 @@
 			s.defaultReadObject();
 			// this is an hack.. when object is read in. It must ignore the
 			// first version bump.
-			
-			// (matej_k) for now, I'm commenting it out. It causes serious trouble with back
+
+			// (matej_k) for now, I'm commenting it out. It causes serious
+			// trouble with back
 			// button, where new versions are not created as they should be
 			// johan promised to look at it soon
-			
-			//versionStarted = true;
+
+			// versionStarted = true;
 		}
 
 	}
@@ -386,10 +387,16 @@
 	/**
 	 * Construct.
 	 * 
+	 * @param application
+	 *            The application for this store
+	 * 
 	 * @param pageStore
+	 *            Page store for keeping page versions
 	 */
-	public SecondLevelCacheSessionStore(final IPageStore pageStore)
+	public SecondLevelCacheSessionStore(Application application, final IPageStore pageStore)
 	{
+		super(application);
+
 		this.pageStore = pageStore;
 
 		// turn automatic multiwindow support off by default, as we don't really

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/WebApplication.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/WebApplication.java?view=diff&rev=525436&r1=525435&r2=525436
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/WebApplication.java
(original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/protocol/http/WebApplication.java
Tue Apr  3 23:22:16 2007
@@ -595,7 +595,7 @@
 	 */
 	protected ISessionStore newSessionStore()
 	{
-		return new SecondLevelCacheSessionStore(new FilePageStore());
+		return new SecondLevelCacheSessionStore(this, new FilePageStore());
 	}
 
 	/**
@@ -671,12 +671,6 @@
 		{
 			// Create session using session factory
 			session = getSessionFactory().newSession(request);
-
-			if (sessionStore.getSessionId(request, false) != null)
-			{
-				// Bind the session to the session store
-				sessionStore.bind(request, session);
-			}
 		}
 
 		WebSession webSession;



Mime
View raw message