0

I have an application using Jetty 8.1.8 (I can't upgrade it to the most current 9.4 at this time although I did also try the latest 8.1.22) as an embedded server started programmatically. It's been working great for a number of years and we haven't had to change any of it until now, however we now have need of basic user sessions so we're adding that.

Unfortunately, when we try to extract the session to use it in our handlers with HttpSession session = request.getSession(true); we get the following exception:

java.lang.IllegalStateException: No SessionManager
    at org.eclipse.jetty.server.Request.getSession(Request.java:1270)

I've dug through all the documentation and many SO posts such as this and this and cannot get this to work without throwing the above exception.

Here is the code we are currently using after many variations attempting to add the sessions.

Server server = new Server(Port);
server.setGracefulShutdown(5000);
server.setStopAtShutdown(true);

HandlerCollection handlers = new HandlerCollection();

// MainHandler inherits from Jetty's AbstractHandler and just contains a couple of additional simple variables that get updated when `handle` is called             
MainHandler main = new MainHandler(...);

// *** Session additions begin here         
HashSessionIdManager idManager = new HashSessionIdManager();
server.setSessionIdManager(idManager);

HashSessionManager sessionManager = new HashSessionManager();
SessionHandler sessions = new SessionHandler(sessionManager);

ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.setHandler(sessions);

handlers.setHandlers(new Handler[] { main, context });
// *** Session additions end here   

server.setHandler(handlers);
//server.setHandler(main); // this is how it was set previously

server.start();

Does anyone have ideas on what might be wrong with this? Hopefully it's something simple that we're overlooking.

Kettch19
  • 394
  • 8
  • 25
  • [Jetty 8 is EOL (End of Life)](https://dev.eclipse.org/mhonarc/lists/jetty-announce/msg00069.html) – Joakim Erdfelt Apr 06 '18 at 11:37
  • I fully understand v8 is EOL but like I said, we cannot change it at this time because we still have to support Java 6 (also can't change that yet either because some of the dependencies have changed so much over the years it would cause a massive number of breaking changes). Surely basic session management has been done enough in v8 that a solution is available. – Kettch19 Apr 06 '18 at 13:02
  • When the Jetty project declares a release EOL, its because its no longer suitable for the general internet. (technologies have moved on, specs have been updated to the point that they break past implementations, browser updates with stricter behaviors, SSL/TLS changes that cannot be supported, etc). Jetty 8 is only suitable in highly controlled environments anymore (think private networks). If you are using Jetty 8 on the general internet please start tracking your requests/responses/connections you'll see an ever increasing set of failures that you cannot fix without heavy customization. – Joakim Erdfelt Apr 06 '18 at 15:40
  • Definitely understand, we're going to be updating it later this year for these same reasons we just cant update right this moment for this particular fix. Our app is commercial with on-premise installation on private networks. – Kettch19 Apr 06 '18 at 15:49

0 Answers0