2424import java .net .URL ;
2525import java .util .Properties ;
2626
27+ import com .cloud .utils .Pair ;
2728import org .apache .commons .daemon .Daemon ;
2829import org .apache .commons .daemon .DaemonContext ;
2930import org .eclipse .jetty .jmx .MBeanContainer ;
@@ -176,7 +177,8 @@ public void start() throws Exception {
176177 createHttpConnector (httpConfig );
177178
178179 // Setup handlers
179- server .setHandler (createHandlers ());
180+ Pair <SessionHandler ,HandlerCollection > pair = createHandlers ();
181+ server .setHandler (pair .second ());
180182
181183 // Extra config options
182184 server .setStopAtShutdown (true );
@@ -185,6 +187,8 @@ public void start() throws Exception {
185187 createHttpsConnector (httpConfig );
186188
187189 server .start ();
190+ // Must set the session timeout after the server has started
191+ pair .first ().setMaxInactiveInterval (sessionTimeout * 60 );
188192 server .join ();
189193 }
190194
@@ -237,15 +241,11 @@ private void createHttpsConnector(final HttpConfiguration httpConfig) {
237241 }
238242 }
239243
240- private HandlerCollection createHandlers () {
244+ private Pair < SessionHandler , HandlerCollection > createHandlers () {
241245 final WebAppContext webApp = new WebAppContext ();
242246 webApp .setContextPath (contextPath );
243247 webApp .setInitParameter ("org.eclipse.jetty.servlet.Default.dirAllowed" , "false" );
244248
245- final SessionHandler sessionHandler = new SessionHandler ();
246- sessionHandler .setMaxInactiveInterval (sessionTimeout * 60 );
247- webApp .setSessionHandler (sessionHandler );
248-
249249 // GZIP handler
250250 final GzipHandler gzipHandler = new GzipHandler ();
251251 gzipHandler .addIncludedMimeTypes ("text/html" , "text/xml" , "text/css" , "text/plain" , "text/javascript" , "application/javascript" , "application/json" , "application/xml" );
@@ -263,14 +263,14 @@ private HandlerCollection createHandlers() {
263263 final RequestLogHandler log = new RequestLogHandler ();
264264 log .setRequestLog (createRequestLog ());
265265
266- // Redirect root context handler
266+ // Redirect root context handler_war
267267 MovedContextHandler rootRedirect = new MovedContextHandler ();
268268 rootRedirect .setContextPath ("/" );
269269 rootRedirect .setNewContextURL (contextPath );
270270 rootRedirect .setPermanent (true );
271271
272272 // Put rootRedirect at the end!
273- return new HandlerCollection (log , gzipHandler , rootRedirect );
273+ return new Pair <>( webApp . getSessionHandler (), new HandlerCollection (log , gzipHandler , rootRedirect ) );
274274 }
275275
276276 private RequestLog createRequestLog () {
0 commit comments