javacookiesjetty

Set Jetty session cookie name programmatically


I'm running in this issue, how can I set session cookie name by code in Jetty 8?

ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
sessionHandler = new SessionHandler();
sessionHandler.getSessionManager().setSessionCookie("JSESSIONID_"+runningPort);
context.setSessionHandler(sessionHandler);

Is wrong, in Jetty8 SessionManager setSessionCookie(String) was removed.


Solution

  • Here is the answer:

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    SessionManager sm = new HashSessionManager();
    ((HashSessionManager)sm).setSessionCookie("JSESSIONID_"+activity.WEB_SERVER_PORT);
    context.setSessionHandler(new SessionHandler(sm));