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 ;
4041import org .eclipse .jetty .server .handler .MovedContextHandler ;
4142import org .eclipse .jetty .server .handler .RequestLogHandler ;
4243import org .eclipse .jetty .server .handler .gzip .GzipHandler ;
44+ import org .eclipse .jetty .server .session .SessionHandler ;
4345import org .eclipse .jetty .util .ssl .SslContextFactory ;
4446import org .eclipse .jetty .util .thread .QueuedThreadPool ;
4547import org .eclipse .jetty .util .thread .ScheduledExecutorScheduler ;
@@ -175,7 +177,8 @@ public void start() throws Exception {
175177 createHttpConnector (httpConfig );
176178
177179 // Setup handlers
178- server .setHandler (createHandlers ());
180+ Pair <SessionHandler ,HandlerCollection > pair = createHandlers ();
181+ server .setHandler (pair .second ());
179182
180183 // Extra config options
181184 server .setStopAtShutdown (true );
@@ -184,6 +187,8 @@ public void start() throws Exception {
184187 createHttpsConnector (httpConfig );
185188
186189 server .start ();
190+ // Must set the session timeout after the server has started
191+ pair .first ().setMaxInactiveInterval (sessionTimeout * 60 );
187192 server .join ();
188193 }
189194
@@ -236,11 +241,10 @@ private void createHttpsConnector(final HttpConfiguration httpConfig) {
236241 }
237242 }
238243
239- private HandlerCollection createHandlers () {
244+ private Pair < SessionHandler , HandlerCollection > createHandlers () {
240245 final WebAppContext webApp = new WebAppContext ();
241246 webApp .setContextPath (contextPath );
242247 webApp .setInitParameter ("org.eclipse.jetty.servlet.Default.dirAllowed" , "false" );
243- webApp .getSessionHandler ().setMaxInactiveInterval (sessionTimeout * 60 );
244248
245249 // GZIP handler
246250 final GzipHandler gzipHandler = new GzipHandler ();
@@ -259,14 +263,14 @@ private HandlerCollection createHandlers() {
259263 final RequestLogHandler log = new RequestLogHandler ();
260264 log .setRequestLog (createRequestLog ());
261265
262- // Redirect root context handler
266+ // Redirect root context handler_war
263267 MovedContextHandler rootRedirect = new MovedContextHandler ();
264268 rootRedirect .setContextPath ("/" );
265269 rootRedirect .setNewContextURL (contextPath );
266270 rootRedirect .setPermanent (true );
267271
268272 // Put rootRedirect at the end!
269- return new HandlerCollection (log , gzipHandler , rootRedirect );
273+ return new Pair <>( webApp . getSessionHandler (), new HandlerCollection (log , gzipHandler , rootRedirect ) );
270274 }
271275
272276 private RequestLog createRequestLog () {
0 commit comments