实现HttpSessionListener的嵌入式jetty
我正在尝试用代理servlet的嵌入式jetty实现HttpSessionListener接口,我已经注册了SessionListener,但它根本没有被调用,下面是代码实现HttpSessionListener的嵌入式jetty,jetty,embedded-jetty,Jetty,Embedded Jetty,我正在尝试用代理servlet的嵌入式jetty实现HttpSessionListener接口,我已经注册了SessionListener,但它根本没有被调用,下面是代码 public class JettyProxy { public static void main(String[] args) throws Exception { Server server = new Server(); CustomProxyServlet customP
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不为null,未触发会话创建事件,请帮助我,获取会话事件的过程是什么?您应该有一个SessionManager。我通常使用: org.eclipse.jetty.server.session.HashSessionManager.HashSessionManager() 和 org.eclipse.jetty.server.session.SessionHandler.SessionHandler(SessionManager) 然后应该为上下文设置处理程序
context.setHandler(sessionHandler);
sessionHandler.addEventListener("Your Session Listener");