4141
4242import com .cloud .consoleproxy .util .Logger ;
4343import com .cloud .utils .PropertiesUtil ;
44+ import org .eclipse .jetty .server .Handler ;
45+ import org .eclipse .jetty .server .Server ;
46+ import org .eclipse .jetty .server .handler .ContextHandler ;
47+ import org .eclipse .jetty .server .handler .ContextHandlerCollection ;
4448
4549/**
4650 *
@@ -345,27 +349,6 @@ public static void start(Properties conf) {
345349 cthread .start ();
346350 }
347351
348- private static void startupHttpMain () {
349- try {
350- ConsoleProxyServerFactory factory = getHttpServerFactory ();
351- if (factory == null ) {
352- s_logger .error ("Unable to load HTTP server factory" );
353- System .exit (1 );
354- }
355-
356- HttpServer server = factory .createHttpServerInstance (httpListenPort );
357- server .createContext ("/getscreen" , new ConsoleProxyThumbnailHandler ());
358- server .createContext ("/resource/" , new ConsoleProxyResourceHandler ());
359- server .createContext ("/ajax" , new ConsoleProxyAjaxHandler ());
360- server .createContext ("/ajaximg" , new ConsoleProxyAjaxImageHandler ());
361- server .setExecutor (new ThreadExecutor ()); // creates a default executor
362- server .start ();
363- } catch (Exception e ) {
364- s_logger .error (e .getMessage (), e );
365- System .exit (1 );
366- }
367- }
368-
369352 private static void startupHttpCmdPort () {
370353 try {
371354 s_logger .info ("Listening for HTTP CMDs on port " + httpCmdListenPort );
@@ -379,7 +362,61 @@ private static void startupHttpCmdPort() {
379362 }
380363 }
381364
382- public static void main (String [] argv ) {
365+ private static void startupHttpMain () {
366+ try {
367+ ConsoleProxyServerFactory factory = getHttpServerFactory ();
368+ if (factory == null ) {
369+ s_logger .error ("Unable to load HTTP server factory" );
370+ System .exit (1 );
371+ }
372+ Server webServer = factory .
373+ createHttpServerInstance (httpListenPort );
374+ Handler [] handlerList = new Handler [6 ];
375+ ContextHandler contextHandlerForScreen = new ContextHandler ();
376+ contextHandlerForScreen .setContextPath ("/getscreen/" );
377+ contextHandlerForScreen .setHandler (new ConsoleProxyThumbnailHandler ());
378+ handlerList [0 ] = contextHandlerForScreen ;
379+
380+ ContextHandler contextHandlerForResources = new ContextHandler ();
381+ contextHandlerForScreen .setContextPath ("/resource/" );
382+ contextHandlerForScreen .setHandler (new ConsoleProxyResourceHandler ());
383+ handlerList [1 ] = contextHandlerForResources ;
384+
385+
386+ ContextHandler contextHandlerForAjax = new ContextHandler ();
387+ contextHandlerForAjax .setContextPath ("/ajax/" );
388+ contextHandlerForAjax .setHandler (new ConsoleProxyAjaxHandler ());
389+ handlerList [2 ] = contextHandlerForAjax ;
390+
391+
392+ ContextHandler contextHandlerForAjaxImage = new ContextHandler ();
393+ contextHandlerForAjaxImage .setContextPath ("/ajaximg/" );
394+ contextHandlerForAjaxImage .setHandler (new ConsoleProxyAjaxImageHandler ());
395+ handlerList [3 ] = contextHandlerForAjaxImage ;
396+
397+
398+ ContextHandler contextHandlerForNoVnc = new ContextHandler ();
399+ contextHandlerForNoVnc .setContextPath ("/novnc/" );
400+ contextHandlerForNoVnc .setHandler (new NoVncConsoleHandler ());
401+ handlerList [4 ] = contextHandlerForNoVnc ;
402+
403+
404+ ContextHandler contextHandlerForWebSockify = new ContextHandler ();
405+ contextHandlerForWebSockify .setContextPath ("/websockify/" );
406+ contextHandlerForWebSockify .setHandler (new WebSocketHandlerForNovnc ());
407+ handlerList [5 ] = contextHandlerForWebSockify ;
408+
409+ ContextHandlerCollection contexts = new ContextHandlerCollection ();
410+ contexts .setHandlers (handlerList );
411+ webServer .setHandler (contexts );
412+ webServer .start ();
413+ } catch (Exception e ) {
414+ s_logger .error (" could not start webserver at " + httpListenPort , e );
415+ throw new RuntimeException ("could not start webserver at " + httpListenPort );
416+ }
417+ }
418+
419+ public static void main (String [] argv ) throws Exception {
383420 standaloneStart = true ;
384421 configLog4j ();
385422 Logger .setFactory (new ConsoleProxyLoggerFactory ());
0 commit comments