Add info to IllegalStateException on check for invalid session

This commit is contained in:
Jan Bartel 2016-03-16 11:45:19 +11:00
parent 3cd568c9b1
commit 6261150167
3 changed files with 24 additions and 2 deletions

View File

@ -117,8 +117,17 @@ public class NoSqlSession extends MemSession
//reinflate it if necessary
if (!isDeIdleFailed() && _manager.getIdlePeriod() > 0 && isIdle())
deIdle();
super.checkValid();
try
{
super.checkValid();
}
catch (IllegalStateException e)
{
throw new IllegalStateException (e.getMessage()+" idle="+_idle+" deidleFailed="+_deIdleFailed+" version="+_version, e);
}
}
/* ------------------------------------------------------------ */
@Override

View File

@ -103,7 +103,7 @@ public abstract class AbstractSession implements AbstractSessionManager.SessionI
protected void checkValid() throws IllegalStateException
{
if (_invalid)
throw new IllegalStateException();
throw new IllegalStateException("id="+_clusterId+" created="+_created+" accessed="+_accessed+" lastaccessed="+_lastAccessed+" maxInactiveMs="+_maxIdleMs);
}
/* ------------------------------------------------------------- */

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.server.session;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@ -186,6 +187,18 @@ public abstract class AbstractSessionInvalidateAndCreateTest
//invalidate existing session
session.invalidate();
//now try to access the invalid session
try
{
session.getAttribute("identity");
fail("Session should be invalid");
}
catch (IllegalStateException e)
{
assertNotNull(e.getMessage());
assertTrue(e.getMessage().contains("id"));
}
//now make a new session
session = request.getSession(true);
session.setAttribute("identity", "session2");