Jetty 8 set "session-timeout" without web.xml?

HolySamosa picture HolySamosa · Dec 20, 2013 · Viewed 11.9k times · Source

I'm trying to set the session-timeout value in an embedded Jetty 8 instance.

With embedded Jetty, how can I programmatically set the session-timeout value that would otherwise be set in the web.xml as follows:

 <session-config>
     <session-timeout>15</session-timeout>
 </session-config>

Thanks!

Answer

Joakim Erdfelt picture Joakim Erdfelt · Dec 21, 2013

Access the session handling / management on your WebAppContext and set it.

WebAppContext app = new WebAppContext(....);
... 
app.getSessionHandler().getSessionManager().setMaxInactiveInterval(timeout);

This is how Jetty itself does it.

Note: SessionManager.setMaxInactiveInterval(int) is in seconds, not milliseconds.