Issue #622
This commit is contained in:
parent
c8c4677e4d
commit
f86d72696a
|
@ -102,7 +102,7 @@ public abstract class NoSqlSessionManager extends AbstractSessionManager impleme
|
||||||
__log.debug("session loaded ", idInCluster);
|
__log.debug("session loaded ", idInCluster);
|
||||||
|
|
||||||
//check if the session we just loaded has actually expired, maybe while we weren't running
|
//check if the session we just loaded has actually expired, maybe while we weren't running
|
||||||
if (getMaxInactiveInterval() > 0 && session.getAccessed() > 0 && ((getMaxInactiveInterval()*1000L)+session.getAccessed()) < System.currentTimeMillis())
|
if (session.getMaxInactiveInterval() > 0 && session.getAccessed() > 0 && ((session.getMaxInactiveInterval()*1000L)+session.getAccessed()) < System.currentTimeMillis())
|
||||||
{
|
{
|
||||||
__log.debug("session expired ", idInCluster);
|
__log.debug("session expired ", idInCluster);
|
||||||
expire(idInCluster);
|
expire(idInCluster);
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.nosql.mongodb;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -239,6 +240,69 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRequestForSessionWithChangedTimeout () throws Exception
|
||||||
|
{
|
||||||
|
String contextPath = "";
|
||||||
|
String servletMapping = "/server";
|
||||||
|
int inactivePeriod = 5;
|
||||||
|
int scavengePeriod = 1;
|
||||||
|
AbstractTestServer server1 = createServer(0, inactivePeriod, scavengePeriod);
|
||||||
|
ChangeTimeoutServlet servlet = new ChangeTimeoutServlet();
|
||||||
|
ServletHolder holder = new ServletHolder(servlet);
|
||||||
|
ServletContextHandler context = server1.addContext(contextPath);
|
||||||
|
context.addServlet(holder, servletMapping);
|
||||||
|
TestHttpSessionListener listener = new TestHttpSessionListener();
|
||||||
|
|
||||||
|
context.getSessionHandler().addEventListener(listener);
|
||||||
|
|
||||||
|
server1.start();
|
||||||
|
int port1 = server1.getPort();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpClient client = new HttpClient();
|
||||||
|
client.start();
|
||||||
|
String url = "http://localhost:" + port1 + contextPath + servletMapping;
|
||||||
|
|
||||||
|
//make a request to set up a session on the server with the session manager's inactive timeout
|
||||||
|
ContentResponse response = client.GET(url + "?action=init");
|
||||||
|
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
||||||
|
String sessionCookie = response.getHeaders().get("Set-Cookie");
|
||||||
|
assertTrue(sessionCookie != null);
|
||||||
|
// Mangle the cookie, replacing Path with $Path, etc.
|
||||||
|
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
|
||||||
|
|
||||||
|
|
||||||
|
//make another request to change the session timeout to a larger value
|
||||||
|
int newInactivePeriod = 100;
|
||||||
|
Request request = client.newRequest(url + "?action=change&val="+newInactivePeriod);
|
||||||
|
request.getHeaders().add("Cookie", sessionCookie);
|
||||||
|
response = request.send();
|
||||||
|
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
||||||
|
|
||||||
|
//stop and restart the session manager to ensure it needs to reload the session
|
||||||
|
context.stop();
|
||||||
|
context.start();
|
||||||
|
|
||||||
|
//wait until the session manager timeout has passed and re-request the session
|
||||||
|
//which should still be valid
|
||||||
|
Thread.currentThread().sleep(inactivePeriod*1000L);
|
||||||
|
|
||||||
|
request = client.newRequest(url + "?action=check");
|
||||||
|
request.getHeaders().add("Cookie", sessionCookie);
|
||||||
|
response = request.send();
|
||||||
|
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
||||||
|
String sessionCookie2 = response.getHeaders().get("Set-Cookie");
|
||||||
|
assertNull(sessionCookie2);
|
||||||
|
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
server1.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void verifySessionTimeout (DBCollection sessions, String id, int sec) throws Exception
|
public void verifySessionTimeout (DBCollection sessions, String id, int sec) throws Exception
|
||||||
{
|
{
|
||||||
|
@ -315,6 +379,11 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest
|
||||||
assertNotNull(session);
|
assertNotNull(session);
|
||||||
session.setMaxInactiveInterval(val);
|
session.setMaxInactiveInterval(val);
|
||||||
}
|
}
|
||||||
|
else if ("check".equals(action))
|
||||||
|
{
|
||||||
|
HttpSession session = request.getSession(false);
|
||||||
|
assertNotNull(session);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue