tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r1241222 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/internal/services/ main/java/org/apache/tapestry5/internal/test/ main/java/org/apache/tapestry5/services/ test/java/org/apache/tapestry5/internal/serv...
Date Mon, 06 Feb 2012 22:26:31 GMT
Author: hlship
Date: Mon Feb  6 22:26:30 2012
New Revision: 1241222

URL: http://svn.apache.org/viewvc?rev=1241222&view=rev
Log:
TAP5-1840: Add method Request.isSessionInvalidated()

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/TestableRequestImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/DelegatingRequest.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Request.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=1241222&r1=1241221&r2=1241222&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
Mon Feb  6 22:26:30 2012
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2010, 2011 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2010, 2011, 2012 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.
@@ -25,7 +25,8 @@ import java.util.Locale;
 
 /**
  * Basic implementation of {@link org.apache.tapestry5.services.Request} that wraps around
an
- * {@link javax.servlet.http.HttpServletRequest}.
+ * {@link javax.servlet.http.HttpServletRequest}. This is not threadsafe, nor should it need
to be (each Request is
+ * handled by its own Thread).
  */
 public class RequestImpl implements Request
 {
@@ -102,6 +103,18 @@ public class RequestImpl implements Requ
         return request.getContextPath();
     }
 
+
+    public boolean isSessionInvalidated()
+    {
+        // Double check to ensure that the session exists, but don't create it.
+        if (session == null)
+        {
+            session = sessionFactory.getSession(false);
+        }
+
+        return session != null && session.isInvalidated();
+    }
+
     public Session getSession(boolean create)
     {
         if (session != null && session.isInvalidated())
@@ -196,4 +209,5 @@ public class RequestImpl implements Requ
     {
         return request.getRemoteHost();
     }
+
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/TestableRequestImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/TestableRequestImpl.java?rev=1241222&r1=1241221&r2=1241222&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/TestableRequestImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/TestableRequestImpl.java
Mon Feb  6 22:26:30 2012
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2009, 2010, 2011 The Apache Software Foundation
+// Copyright 2007, 2008, 2009, 2010, 2011, 2012 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.
@@ -259,4 +259,9 @@ public class TestableRequestImpl impleme
     {
         return "localhost";
     }
+
+    public boolean isSessionInvalidated()
+    {
+        return false;
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/DelegatingRequest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/DelegatingRequest.java?rev=1241222&r1=1241221&r2=1241222&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/DelegatingRequest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/DelegatingRequest.java
Mon Feb  6 22:26:30 2012
@@ -1,4 +1,4 @@
-// Copyright 2009, 2010, 2011 The Apache Software Foundation
+// Copyright 2009, 2010, 2011, 2012 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.
@@ -156,4 +156,9 @@ public class DelegatingRequest implement
     {
         return request.getRemoteHost();
     }
+
+    public boolean isSessionInvalidated()
+    {
+        return request.isSessionInvalidated();
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Request.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Request.java?rev=1241222&r1=1241221&r2=1241222&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Request.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Request.java
Mon Feb  6 22:26:30 2012
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2011 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2011, 2012 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.
@@ -21,7 +21,6 @@ import java.util.Locale;
  * Generic version of {@link javax.servlet.http.HttpServletRequest}, used to encapsulate
the Servlet API version, and to
  * help bridge the differences between Servlet API and Porlet API.
  * <p/>
- * <p/>
  * The Request service is a {@linkplain org.apache.tapestry5.ioc.services.PropertyShadowBuilder
shadow} of the current
  * thread's request.
  */
@@ -29,7 +28,8 @@ public interface Request
 {
     /**
      * Gets the {@link Session}. If create is false and the session has not be created previously,
returns null. Also,
-     * if the session is invalidated and create is false, returns null.
+     * if the session is invalidated and create is false, returns null. Invoking this method
with true, when the session exists but has
+     * been invalidated, will force the creation of a new session.
      *
      * @param create true to force the creation of the session
      * @return the session (or null if create is false the session has not been previously
created)
@@ -190,4 +190,12 @@ public interface Request
      * @since 5.3
      */
     String getRemoteHost();
+
+    /**
+     * Returns true if the request specified a session, and that session has been invalidated.
+     *
+     * @return true if session was invalidated during this request
+     * @since 5.4
+     */
+    boolean isSessionInvalidated();
 }

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=1241222&r1=1241221&r2=1241222&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
Mon Feb  6 22:26:30 2012
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009, 2011 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 2011, 2012 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.
@@ -239,4 +239,62 @@ public class RequestImplTest extends Int
     {
         expect(request.getPathInfo()).andReturn(pathInfo).atLeastOnce();
     }
+
+    @Test
+    public void isSessionInvalidated_is_false_when_no_session_at_all()
+    {
+        HttpServletRequest sr = mockHttpServletRequest();
+
+        TapestrySessionFactory sf = newMock(TapestrySessionFactory.class);
+
+        expect(sf.getSession(false)).andReturn(null);
+
+        replay();
+
+        Request request = new RequestImpl(sr, CHARSET, sf);
+
+        assertFalse(request.isSessionInvalidated());
+
+        verify();
+    }
+
+    @Test
+    public void isSessionInvalidated_is_false_when_session_exists_and_is_valid()
+    {
+        HttpServletRequest sr = mockHttpServletRequest();
+        Session session = mockSession();
+
+        TapestrySessionFactory sf = newMock(TapestrySessionFactory.class);
+
+        expect(sf.getSession(false)).andReturn(session);
+        expect(session.isInvalidated()).andReturn(false);
+
+        replay();
+
+        Request request = new RequestImpl(sr, CHARSET, sf);
+
+        assertFalse(request.isSessionInvalidated());
+
+        verify();
+    }
+
+    @Test
+    public void isSessionInvalidated_is_true_when_session_is_invalid()
+    {
+        HttpServletRequest sr = mockHttpServletRequest();
+        Session session = mockSession();
+
+        TapestrySessionFactory sf = newMock(TapestrySessionFactory.class);
+
+        expect(sf.getSession(false)).andReturn(session);
+        expect(session.isInvalidated()).andReturn(true);
+
+        replay();
+
+        Request request = new RequestImpl(sr, CHARSET, sf);
+
+        assertTrue(request.isSessionInvalidated());
+
+        verify();
+    }
 }



Mime
View raw message