Author: hlship
Date: Fri Jan  7 22:06:22 2011
New Revision: 1056532

URL: http://svn.apache.org/viewvc?rev=1056532&view=rev
Log:
TAP5-891: Handle the case where the HttpSession is invalidated seperately form 
the Tapestry Session

Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RequestImplTest.java

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestImpl.java?rev=1056532&r1=1056531&r2=1056532&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestImpl.java
 Fri Jan  7 22:06:22 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2010 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2010, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -43,7 +43,9 @@ public class RequestImpl implements Requ
 
     private boolean encodingSet;
 
-    private Session session;
+    HttpSession hsession;
+
+    Session session;
 
     public RequestImpl(HttpServletRequest request, String requestEncoding, 
SessionPersistedObjectAnalyzer analyzer)
     {
@@ -103,9 +105,22 @@ public class RequestImpl implements Requ
 
     public Session getSession(boolean create)
     {
+        if (session != null)
+        {
+            // The easy case is when the session was invalidated through the 
Tapestry Session
+            // object. The hard case is when the HttpSession was invalidated 
outside of Tapestry,
+            // in which case, request.getSession() will return a new 
HttpSession instance (or null)
+
+            if (session.isInvalidated() || hsession != 
request.getSession(false))
+            {
+                session = null;
+                hsession = null;
+            }
+        }
+
         if (session == null)
         {
-            HttpSession hsession = request.getSession(create);
+            hsession = request.getSession(create);
 
             if (hsession != null)
             {
@@ -113,9 +128,6 @@ public class RequestImpl implements Requ
             }
         }
 
-        if (!create && session != null && session.isInvalidated())
-            return null;
-
         return session;
     }
 

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RequestImplTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RequestImplTest.java?rev=1056532&r1=1056531&r2=1056532&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RequestImplTest.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RequestImplTest.java
 Fri Jan  7 22:06:22 2011
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 2011 The Apache Software Foundation
 //
 // 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
+// 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,
@@ -128,8 +128,12 @@ public class RequestImplTest extends Int
     @DataProvider
     public Object[][] xhr_inputs()
     {
-        return new Object[][] { { null, false }, { "", false }, { "some other 
value", false },
-                { "XMLHttpRequest", true } };
+        return new Object[][]
+        {
+        { null, false },
+        { "", false },
+        { "some other value", false },
+        { "XMLHttpRequest", true } };
     }
 
     @Test
@@ -195,28 +199,35 @@ public class RequestImplTest extends Int
     public void get_session_returns_null_if_invalid()
     {
         HttpServletRequest sr = mockHttpServletRequest();
-        HttpSession hsession = mockHttpSession();
-
-        train_getSession(sr, true, hsession);
+        HttpSession hsession1 = mockHttpSession();
+        HttpSession hsession2 = mockHttpSession();
 
-        hsession.invalidate();
+        train_getSession(sr, true, hsession1);
 
         replay();
 
         Request request = new RequestImpl(sr, CHARSET, null);
 
-        Session session = request.getSession(true);
+        Session session1 = request.getSession(true);
 
-        session.invalidate();
+        verify();
 
-        assertNull(request.getSession(false));
+        hsession1.invalidate();
 
-        assertSame(request.getSession(true), session);
+        train_getSession(sr, false, hsession2);
+        train_getSession(sr, true, hsession2);
 
-        verify(); 
-    }
+        replay();
+
+        session1.invalidate();
+
+        Session session2 = request.getSession(true);
 
+        assertNotSame(session2, session1);
+        assertSame(request.getSession(true), session2);
 
+        verify();
+    }
 
     protected final void train_getPathInfo(HttpServletRequest request, String 
pathInfo)
     {


Reply via email to