After upgrading to jetty 9.4 I notice a ClassNotFoundException for org.eclipse.jetty.server.session.HashSessionManager
.
I think I need to use a FileSessionDataStore
but I don't see how that is suppose to be set on a SessionHandler
.
The configuration I currently have is:
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
...
<Set name="sessionHandler">
<New class="org.eclipse.jetty.server.session.SessionHandler">
<Arg>
<New class="org.eclipse.jetty.server.session.HashSessionManager">
<Set name="storeDirectory">my/store/path</Set>
</New>
</Arg>
</New>
</Set>
</Configure>
I don't see what I need to do, SessionHandler
doesn't take a SessionDataStore
, but a SessionCache
can be set on it but it looks like the implementations of SessionCache
want a SessionHandler
in the constructor, I don't see how to do that in XML.
In the jetty-9.4 session architecture, you have SessionHandler
takes a SessionCache
, which optionally takes a SessionDataStore
.
See OneServletContextWithSession
for a programmatic example.
That example uses the NullSessionDataStore
, but the principle is the same as the FileSessionDataStore
, which is the replacement for the old HashSessionManager
ability to store sessions to disk.
The Jetty Documentation contains information on changes from previous versions of Jetty session management to the 9.4 style.
If you follow links in the documentation, you'll also find detailed info on the new session architecture.
As the documentation explains, the easiest way to configure sessions in jetty-9.4 when running in the distribution is to enable the appropriate module. However, if you're running embedded, or you just want to set up session management for a particular webapp in xml, here's some example code of setting up the FileSessionDataStore
:
<Get id="sh" name="sessionHandler">
<Set name="sessionCache">
<New class="org.eclipse.jetty.server.session.DefaultSessionCache">
<Arg><Ref id="sh"/></Arg>
<Set name="sessionDataStore">
<New class="org.eclipse.jetty.server.session.FileSessionDataStore">
<Set name="storeDir">/tmp/sessions</Set>
</New>
</Set>
</New>
</Set>
</Get>
Ah I think I worked it out, it is not pretty it ended up as:
<Set name="sessionHandler">
<New class="org.eclipse.jetty.server.session.SessionHandler">
</New>
</Set>
<Call name="getSessionHandler" id="sessionHandler" />
<Ref refid="sessionHandler">
<Set name="SessionCache">
<New class="org.eclipse.jetty.server.session.DefaultSessionCache">
<Arg>
<Ref refid="sessionHandler"/>
</Arg>
<Set name="SessionDataStore">
<New class="org.eclipse.jetty.server.session.FileSessionDataStore">
<Set name="StoreDir">my/store/path</Set>
</New>
</Set>
</New>
</Set>
</Ref>
I followed the easier to read pure java example I found at http://useof.org/java-open-source/org.eclipse.jetty.server.session.FileSessionDataStore
If this doesn't look correct to a Jetty expert I am happy to edit the answer so as not to mislead others.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With