I've found plenty of references to this issue on google but no answers. I'm using the latest version of jetty (8.1.2.v20120308) and I can't seem to get an embedded servlet to be able to use sessions. The example is in scala of course, but it should be readable to any java programmer.
val server = new Server();
val connector = new SelectChannelConnector()
connector.setPort(Integer.getInteger("jetty.port", 8080).intValue())
server.setConnectors(Array(connector))
val webapp = new ServletContextHandler(ServletContextHandler.SESSIONS)
webapp.setContextPath("/")
webapp.setResourceBase(webDir)
webapp.setServer(server)
val brzyServ = new ServletHolder(new BrzyDynamicServlet())
webapp.addServlet(brzyServ, "*.brzy")
server.setHandler(webapp);
server.start()
in my servlet code:
...
log.debug("session manager: {}",req.asInstanceOf[Request].getSessionManager)
val session = req.getSession
...
The req.getSession throws this exception, and the debug line before it, is always null.
java.lang.IllegalStateException: No SessionManager
at org.eclipse.jetty.server.Request.getSession(Request.java:1173)
In the log I can see this:
DEBUG org.eclipse.jetty.server.session - sessionManager=org.eclipse.jetty.server.session.HashSessionManager@2a8ceeea
DEBUG org.eclipse.jetty.server.session - session=null
I'm not sure if that's relevant, but it would appear that there is a session manager but it's not available on the request.
I've tried this with the WebAppContext with the same result. Not to mention explicitly setting the sessionManager in a dozen different ways.