Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Configuring Session Cache

Traditionally Sessions belong to a specific ServletContext.

The handler mechanism alone has no ServletContext.

The specialized handler ServletContextHandler does however.

And that is where Servlet / Filters / Listener / Sessions etc are all added to.
The constructor of the ServletContextHandler has an option to turn on Session handling support (not enabled by default).

ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

If you want to configure the Session handling for different caches, different storage, etc..
That's done via the SessionManager on the ServletContextHandler.

See https://github.com/eclipse/jetty.project/blob/jetty-9.4.x/examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneServletContextWithSession.java

Joakim Erdfelt / joakim@xxxxxxxxxxx


On Fri, Jan 10, 2020 at 2:42 PM Glen Peterson <glen.k.peterson@xxxxxxxxx> wrote:
Thank you for Jetty.  You all know I'm a fan.

I read this:
"In the absence of any explicit configuration, Jetty will instantiate an instance of the DefaultSessionCache per context."

But when I go to handle a request in an AbstractHandler implementation:

    override fun handle(
                        target: String,
                        baseRequest: Request,
                        request: HttpServletRequest,
                        response: HttpServletResponse
     ) {
         request.getSession(true)


I get an exception:
java.lang.IllegalStateException: No SessionManager
at org.eclipse.jetty.server.Request.getSession(Request.java:1605)

Does it actually need to be configured, or am I doing something else wrong?  Also, can it be configured in code (Java/Kotlin)?

This wasn't something I ever thought about with Tomcat.  Is this because I'm extending AbstractHandler instead of HttpServlet?

--
Glen K. Peterson
(828) 393-0081
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users

Back to the top