You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2008/12/30 00:44:24 UTC
svn commit: r730017 - 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/
main/java/org/apache/tapestry5/test/ test/jav...
Author: hlship
Date: Mon Dec 29 15:44:24 2008
New Revision: 730017
URL: http://svn.apache.org/viewvc?rev=730017&view=rev
Log:
TAP5-413: Invaliding the session may cause an exception at the end of the request if there is a "dirty" ASO
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/services/SessionApplicationStatePersistenceStrategy.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SessionImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/PageTesterSession.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Session.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategyTest.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=730017&r1=730016&r2=730017&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 Dec 29 15:44:24 2008
@@ -40,6 +40,8 @@
private boolean encodingSet;
+ private Session session;
+
public RequestImpl(HttpServletRequest request, String requestEncoding)
{
this.request = request;
@@ -96,9 +98,14 @@
public Session getSession(boolean create)
{
- HttpSession session = request.getSession(create);
+ if (session == null)
+ {
+ HttpSession hsession = request.getSession(create);
- return session == null ? null : new SessionImpl(session);
+ if (hsession != null) session = new SessionImpl(hsession);
+ }
+
+ return session;
}
public Locale getLocale()
@@ -162,5 +169,4 @@
{
return request.getServerName();
}
-
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategy.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategy.java?rev=730017&r1=730016&r2=730017&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategy.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategy.java Mon Dec 29 15:44:24 2008
@@ -115,6 +115,12 @@
{
Map<String, Object> map = getASOMap();
+ if (map.isEmpty()) return;
+
+ Session session = request.getSession(false);
+
+ if (session != null && session.isInvalidated()) return;
+
for (String key : map.keySet())
{
Object aso = map.get(key);
@@ -123,7 +129,12 @@
if (needsRestore(aso))
{
- Session session = request.getSession(true);
+ if (session == null)
+ session = request.getSession(true);
+
+ // Don't need to check invalidated as a session that gets created here
+ // can't have been invalidated yet ... but then again, how did the ASO get
+ // created then?
// It is expected that the ASO implements HttpSessionBindingListener and
// can clear its dirty flag as it is saved.
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SessionImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SessionImpl.java?rev=730017&r1=730016&r2=730017&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SessionImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SessionImpl.java Mon Dec 29 15:44:24 2008
@@ -30,6 +30,8 @@
{
private final HttpSession session;
+ private boolean invalidated = false;
+
public SessionImpl(HttpSession session)
{
this.session = session;
@@ -74,12 +76,18 @@
public void invalidate()
{
+ invalidated = true;
+
session.invalidate();
}
+ public boolean isInvalidated()
+ {
+ return invalidated;
+ }
+
public void setMaxInactiveInterval(int seconds)
{
session.setMaxInactiveInterval(seconds);
}
-
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/PageTesterSession.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/PageTesterSession.java?rev=730017&r1=730016&r2=730017&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/PageTesterSession.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/PageTesterSession.java Mon Dec 29 15:44:24 2008
@@ -56,7 +56,6 @@
{
attributes.put(name, value);
}
-
}
private void nyi(String name)
@@ -77,9 +76,13 @@
nyi("invalidate");
}
+ public boolean isInvalidated()
+ {
+ return false;
+ }
+
public void setMaxInactiveInterval(int seconds)
{
nyi("setMaxInactiveInterval");
}
-
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Session.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Session.java?rev=730017&r1=730016&r2=730017&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Session.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Session.java Mon Dec 29 15:44:24 2008
@@ -64,4 +64,12 @@
* @throws IllegalStateException if this method is called on an already invalidated session
*/
void invalidate();
+
+ /**
+ * Checks to see if the session has been invalidated. Note: this only catches calls to {@link #invalidate()}, not
+ * calls to {@link javax.servlet.http.HttpSession#invalidate()}.
+ *
+ * @since 5.1.0.0
+ */
+ boolean isInvalidated();
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java?rev=730017&r1=730016&r2=730017&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java Mon Dec 29 15:44:24 2008
@@ -1185,4 +1185,9 @@
{
expect(model.isAllowNull()).andReturn(allowNull).atLeastOnce();
}
+
+ protected final void train_isInvalidated(Session session, boolean invalidated)
+ {
+ expect(session.isInvalidated()).andReturn(invalidated);
+ }
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategyTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategyTest.java?rev=730017&r1=730016&r2=730017&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategyTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategyTest.java Mon Dec 29 15:44:24 2008
@@ -206,11 +206,15 @@
{
Request request = mockRequest();
Map<String, Object> asoMap = CollectionFactory.newMap();
+ Session session = mockSession();
asoMap.put("some.key", null);
+ train_isInvalidated(session, false);
train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);
+ train_getSession(request, false, session);
+
replay();
EndOfRequestListener strategy = new SessionApplicationStatePersistenceStrategy(request);
@@ -234,7 +238,10 @@
asoMap.put(key, aso);
train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);
- train_getSession(request, true, session);
+
+ train_getSession(request, false, session);
+ train_isInvalidated(session, false);
+
session.setAttribute(key, aso);
replay();
@@ -259,7 +266,39 @@
asoMap.put(key, aso);
train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);
+
+ train_getSession(request, false, session);
+ train_isInvalidated(session, false);
+
+ session.setAttribute(key, aso);
+
+ replay();
+
+ EndOfRequestListener strategy = new SessionApplicationStatePersistenceStrategy(request);
+
+ strategy.requestDidComplete();
+
+ verify();
+ }
+
+ @Test
+ public void need_to_create_session_to_restore_optimized_object()
+ {
+ Request request = mockRequest();
+ Session session = mockSession();
+ Map<String, Object> asoMap = CollectionFactory.newMap();
+
+ String key = "foo:bar";
+ OptimizedApplicationStateObject aso = mockOptimizedApplicationStateObject(true);
+
+ asoMap.put(key, aso);
+
+ train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);
+
+ train_getSession(request, false, null);
+
train_getSession(request, true, session);
+
session.setAttribute(key, aso);
replay();
@@ -272,6 +311,33 @@
}
@Test
+ public void session_invalidated()
+ {
+ Request request = mockRequest();
+ Session session = mockSession();
+ Map<String, Object> asoMap = CollectionFactory.newMap();
+
+ String key = "foo:bar";
+ Object aso = new Object();
+
+ asoMap.put(key, aso);
+
+ train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);
+
+ train_getSession(request, false, session);
+
+ train_isInvalidated(session, true);
+
+ replay();
+
+ EndOfRequestListener strategy = new SessionApplicationStatePersistenceStrategy(request);
+
+ strategy.requestDidComplete();
+
+ verify();
+ }
+
+ @Test
public void restore_optimized_object_is_clean()
{
Request request = mockRequest();
@@ -285,6 +351,9 @@
train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);
+ train_getSession(request, false, session);
+ train_isInvalidated(session, false);
+
replay();
EndOfRequestListener strategy = new SessionApplicationStatePersistenceStrategy(request);
@@ -296,7 +365,6 @@
private OptimizedApplicationStateObject mockOptimizedApplicationStateObject(boolean dirty)
{
-
OptimizedApplicationStateObject object = newMock(OptimizedApplicationStateObject.class);
expect(object.isApplicationStateObjectDirty()).andReturn(dirty);