Reputation: 553
I am trying to implementing HttpSessionListener interface with embedded jetty with proxy servlet, I have registered SessionListener, but it is not getting invoked at all, here is the code,
public class JettyProxy {
public static void main(String[] args) throws Exception {
Server server = new Server();
CustomProxyServlet customProxyServlet = new CustomProxyServlet();
ServerConnector connector = new ServerConnector(server);
connector.setPort(8888);
server.addConnector(connector);
ConnectHandler proxy = new ConnectHandler();
server.setHandler(proxy);
ServletContextHandler context = new ServletContextHandler(proxy, "/",
ServletContextHandler.SESSIONS);
ServletHolder proxyServlet = new ServletHolder(customProxyServlet);
context.addServlet(proxyServlet, "/*");
if (context.getSessionHandler() == null) {
System.out.println("Session handler is null");
} else {
System.out.println("Session handler is not null");
}
if (context.getSessionHandler().getSessionManager() == null) {
System.out.println("Managaer it null");
} else {
System.out.println("Manager is not null");
}
context.getSessionHandler().addEventListener(new CustomSessionHandler());
server.start();
server.join();
}
}
SessionHandler is not null, session creating events are not getting triggered, please help me, what is the procedure get session events?
Upvotes: 5
Views: 2944
Reputation: 167
you should have a SessionManager. i usually use : org.eclipse.jetty.server.session.HashSessionManager.HashSessionManager() and org.eclipse.jetty.server.session.SessionHandler.SessionHandler(SessionManager manager)
then you should set the handler for the context
context.setHandler(sessionHandler);
sessionHandler.addEventListener("Your Session Listener");
Upvotes: 2