public static void main ( String [ ] args ) { if ( args . length == 0 || args . length > 2 ) { System . err . println ( "\nUsage - java org.browsermob.proxy.jetty.http.HttpServer [<addr>:]<port>" ) ; System . err . println ( "\nUsage - java org.browsermob.proxy.jetty.http.HttpServer -r [savefile]" ) ; System . err . println ( " Serves files from '.' directory" ) ; System . err . println ( " Dump handler for not found requests" ) ; System . err . println ( " Default port is 8080" ) ; System . exit ( 1 ) ; } try { if ( args . length == 1 ) { // Create the server HttpServer server = new HttpServer ( ) ; // Default is no virtual host String host = null ; HttpContext context = server . getContext ( host , "/" ) ; context . setResourceBase ( "." ) ; context . addHandler ( new ResourceHandler ( ) ) ; context . addHandler ( new DumpHandler ( ) ) ; context . addHandler ( new NotFoundHandler ( ) ) ; InetAddrPort address = new InetAddrPort ( args [ 0 ] ) ; server . addListener ( address ) ; server . start ( ) ; } else { Resource resource = Resource . newResource ( args [ 1 ] ) ; ObjectInputStream in = new ObjectInputStream ( resource . getInputStream ( ) ) ; HttpServer server = ( HttpServer ) in . readObject ( ) ; in . close ( ) ; server . start ( ) ; } } catch ( Exception e ) { log . warn ( LogSupport . EXCEPTION , e ) ; } }
Construct server from command line arguments .