Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 475
HolySamosa Avatar asked Dec 20 '13 21:12

HolySamosa


2 Answers

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.

like image 141
Joakim Erdfelt Avatar answered Sep 18 '22 22:09

Joakim Erdfelt


2019-05-11

For Jetty version 9.4.12.v20180830 with the following ServletContextHandler setup, this is:

ServletContextHandler webappContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
... 
webappContext.getSessionHandler().setMaxInactiveInterval(timeout_in_sec);

(There is no intermediate call to getSessionManager())

like image 39
Z3d4s Avatar answered Sep 17 '22 22:09

Z3d4s