356726 Instead of the sessionDestroyed called sessionCreated after invalidate session

This commit is contained in:
Jan Bartel 2011-09-06 09:15:26 +10:00
parent b1f95541de
commit 44204a2e5b
2 changed files with 39 additions and 1 deletions

View File

@ -734,7 +734,7 @@ public abstract class AbstractSessionManager extends AbstractLifeCycle implement
{
HttpSessionEvent event=new HttpSessionEvent(session);
for (HttpSessionListener listener : _sessionListeners)
listener.sessionCreated(event);
listener.sessionDestroyed(event);
}
}
}

View File

@ -3,12 +3,16 @@ package org.eclipse.jetty.server.session;
import static org.junit.Assert.*;
import java.io.IOException;
import java.util.EventListener;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionActivationListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import org.eclipse.jetty.client.ContentExchange;
import org.eclipse.jetty.client.HttpClient;
@ -30,6 +34,8 @@ public abstract class AbstractRemoveSessionTest
AbstractTestServer server = createServer(0, 1, scavengePeriod);
ServletContextHandler context = server.addContext(contextPath);
context.addServlet(TestServlet.class, servletMapping);
TestEventListener testListener = new TestEventListener();
context.getSessionHandler().addEventListener(testListener);
server.start();
int port = server.getPort();
try
@ -49,6 +55,8 @@ public abstract class AbstractRemoveSessionTest
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
//ensure sessionCreated listener is called
assertTrue (testListener.isCreated());
//now delete the session
exchange = new ContentExchange(true);
@ -58,6 +66,8 @@ public abstract class AbstractRemoveSessionTest
client.send(exchange);
exchange.waitForDone();
assertEquals(HttpServletResponse.SC_OK,exchange.getResponseStatus());
//ensure sessionDestroyed listener is called
assertTrue(testListener.isDestroyed());
// The session is not there anymore, but we present an old cookie
@ -106,4 +116,32 @@ public abstract class AbstractRemoveSessionTest
}
}
public static class TestEventListener implements HttpSessionListener
{
boolean wasCreated;
boolean wasDestroyed;
public void sessionCreated(HttpSessionEvent se)
{
wasCreated = true;
}
public void sessionDestroyed(HttpSessionEvent se)
{
wasDestroyed = true;
}
public boolean isDestroyed()
{
return wasDestroyed;
}
public boolean isCreated()
{
return wasCreated;
}
}
}