Java 类org.eclipse.jetty.server.handler.DefaultHandler 实例源码

项目:websocket    文件:WebSocketServer.java   
/**
 * start server
 * 
 * @param port
 * @param path
 * @param handlerClass
 */
public static void startWebSocket(int port, String path, String handlerClass) {
    try {
        Server server = new Server(port);
        HandlerList handlerList = new HandlerList();
        ServletContextHandler context = new ServletContextHandler(
                ServletContextHandler.SESSIONS);
        context.setContextPath("/");
        context.addServlet(new ServletHolder(new Jwservlet(handlerClass)),
                path);
        handlerList.addHandler(context);
        handlerList.addHandler(new DefaultHandler());
        server.setHandler(handlerList);
        server.start();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        LogUtil.LOG("start websocket server error:" + e.getMessage(),
                LogLev.ERROR, WebSocketServer.class);
        System.exit(1);
    }
}
项目:JavaEE    文件:Main.java   
public static void main(String[] args) throws Exception {

        // Create a basic Jetty server object that will listen on port 8080
        Server server = new Server(8080);

        // Create the ResourceHandler. It is the object that will actually
        // handle the request for a given file. It is a Jetty Handler object
        // so it is suitable for chaining with other handlers as you will see
        // in other examples
        ResourceHandler resource_handler = new ResourceHandler();

        // Configure the ResourceHandler. Setting the resource base indicates
        // where the files should be served out of
        resource_handler.setDirectoriesListed(true);
        resource_handler.setWelcomeFiles(new String[]{ "index.html" });
        resource_handler.setResourceBase("src/main/webapp/");

        // Add the ResourceHandler to the server
        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
        server.setHandler(handlers);

        // Start server
        server.start();
        server.join();
    }
项目:Cognizant-Intelligent-Test-Scripter    文件:DashBoardServer.java   
public void prepare() {
    try {
        Tools.verifyLocalPort("DBServer ", port());
        server = new Server();
        DefaultHandler webHandler = new DefaultHandler();
        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[]{getResourceHandler(),
            getUIWSHandler(), webHandler});

        ServerConnector connector = new ServerConnector(server);
        connector.setPort(port());
        server.setConnectors(new Connector[]{connector});
        server.setHandler(handlers);

        LOG.log(Level.INFO, "DB Server on : http://{0}:{1}",
                new Object[]{Tools.IP(), port() + ""});

    } catch (Exception ex) {
        LOG.log(Level.SEVERE, ex.getMessage(), ex);
    }
}
项目:incubator-pulsar    文件:ServerManager.java   
public void start() throws Exception {
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    Slf4jRequestLog requestLog = new Slf4jRequestLog();
    requestLog.setExtended(true);
    requestLog.setLogTimeZone(TimeZone.getDefault().getID());
    requestLog.setLogLatency(true);
    requestLogHandler.setRequestLog(requestLog);
    handlers.add(0, new ContextHandlerCollection());
    handlers.add(requestLogHandler);

    ContextHandlerCollection contexts = new ContextHandlerCollection();
    contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));

    HandlerCollection handlerCollection = new HandlerCollection();
    handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
    server.setHandler(handlerCollection);

    server.start();

    log.info("Server started at end point {}", getServiceUri());
}
项目:incubator-pulsar    文件:ProxyServer.java   
public void start() throws PulsarServerException {
    log.info("Starting web socket proxy at port {}", conf.getWebServicePort());
    try {
        RequestLogHandler requestLogHandler = new RequestLogHandler();
        Slf4jRequestLog requestLog = new Slf4jRequestLog();
        requestLog.setExtended(true);
        requestLog.setLogTimeZone(TimeZone.getDefault().getID());
        requestLog.setLogLatency(true);
        requestLogHandler.setRequestLog(requestLog);
        handlers.add(0, new ContextHandlerCollection());
        handlers.add(requestLogHandler);

        ContextHandlerCollection contexts = new ContextHandlerCollection();
        contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));

        HandlerCollection handlerCollection = new HandlerCollection();
        handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
        server.setHandler(handlerCollection);

        server.start();
    } catch (Exception e) {
        throw new PulsarServerException(e);
    }
}
项目:incubator-pulsar    文件:WebService.java   
public void start() throws PulsarServerException {
    try {
        RequestLogHandler requestLogHandler = new RequestLogHandler();
        Slf4jRequestLog requestLog = new Slf4jRequestLog();
        requestLog.setExtended(true);
        requestLog.setLogTimeZone(TimeZone.getDefault().getID());
        requestLog.setLogLatency(true);
        requestLogHandler.setRequestLog(requestLog);
        handlers.add(0, new ContextHandlerCollection());
        handlers.add(requestLogHandler);

        ContextHandlerCollection contexts = new ContextHandlerCollection();
        contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));

        HandlerCollection handlerCollection = new HandlerCollection();
        handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
        server.setHandler(handlerCollection);

        server.start();

        log.info("Web Service started at {}", pulsar.getWebServiceAddress());
    } catch (Exception e) {
        throw new PulsarServerException(e);
    }
}
项目:incubator-pulsar    文件:WebServer.java   
public void start() throws Exception {
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    Slf4jRequestLog requestLog = new Slf4jRequestLog();
    requestLog.setExtended(true);
    requestLog.setLogTimeZone(TimeZone.getDefault().getID());
    requestLog.setLogLatency(true);
    requestLogHandler.setRequestLog(requestLog);
    handlers.add(0, new ContextHandlerCollection());
    handlers.add(requestLogHandler);

    ContextHandlerCollection contexts = new ContextHandlerCollection();
    contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));

    HandlerCollection handlerCollection = new HandlerCollection();
    handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
    server.setHandler(handlerCollection);

    server.start();

    log.info("Server started at end point {}", getServiceUri());
}
项目:apt-graph    文件:FileServer.java   
/**
 * Start the file server (blocking).
 *
 * @throws Exception If server cannot start
 */
public final void start() throws Exception {
    LOGGER.info("Starting web interface at http://localhost:8000");

    Server server = new Server(8000);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[]{"index.html"});
    resource_handler.setResourceBase("../website");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(
            new Handler[]{
                resource_handler,
                new DefaultHandler()});
    server.setHandler(handlers);

    server.start();
}
项目:little_mitm    文件:PerformanceServer.java   
public void run(int port) throws Exception {
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    server.addConnector(connector);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[] { "index.html" });

    resource_handler.setResourceBase("./performance/site/");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler,
            new DefaultHandler() });
    server.setHandler(handlers);

    server.start();
    System.out.println("Started performance file server at port: " + port);
    server.join();
}
项目:Learning    文件:EmbeddedServer.java   
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );


    server.start();
    server.join();
}
项目:Learning    文件:EmbeddedServer.java   
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );


    server.start();
    server.join();
}
项目:Learning    文件:EmbeddedServer.java   
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );


    server.start();
    server.join();
}
项目:Camel    文件:Olingo2SampleServer.java   
/**
 * 
 * @param port
 * @param resourcePath
 */
public Olingo2SampleServer(int port, String resourcePath) {
    this.port = port;
    server = new org.eclipse.jetty.server.Server(port);

    WebAppContext webappcontext = new WebAppContext();
    String contextPath = null;
    try {
        contextPath = Olingo2SampleServer.class.getResource(resourcePath).toURI().getPath();
    } catch (URISyntaxException e) {
        LOG.error("Unable to read the resource at {}", resourcePath, e);
    }
    webappcontext.setContextPath("/");

    webappcontext.setWar(contextPath);

    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers(new Handler[] {webappcontext, new DefaultHandler()});
    server.setHandler(handlers);
}
项目:LittleProxy    文件:PerformanceServer.java   
public void run(int port) throws Exception {
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    server.addConnector(connector);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[] { "index.html" });

    resource_handler.setResourceBase("./performance/site/");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler,
            new DefaultHandler() });
    server.setHandler(handlers);

    server.start();
    System.out.println("Started performance file server at port: " + port);
    server.join();
}
项目:jaxrs    文件:EmbeddedServer.java   
public static void main(String[] args) throws Exception {
    URI baseUri = UriBuilder.fromUri("http://localhost").port(SERVER_PORT)
            .build();
    ResourceConfig config = new ResourceConfig(Calculator.class);
    Server server = JettyHttpContainerFactory.createServer(baseUri, config,
            false);

    ContextHandler contextHandler = new ContextHandler("/rest");
    contextHandler.setHandler(server.getHandler());

    ProtectionDomain protectionDomain = EmbeddedServer.class
            .getProtectionDomain();
    URL location = protectionDomain.getCodeSource().getLocation();

    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setWelcomeFiles(new String[] { "index.html" });
    resourceHandler.setResourceBase(location.toExternalForm());
    System.out.println(location.toExternalForm());
    HandlerCollection handlerCollection = new HandlerCollection();
    handlerCollection.setHandlers(new Handler[] { resourceHandler,
            contextHandler, new DefaultHandler() });
    server.setHandler(handlerCollection);
    server.start();
    server.join();
}
项目:performance-test-harness-for-geoevent    文件:WebsocketServerEventProducer.java   
private void setup(int port) {
    if (server == null) {
        server = new Server(port);
        ServletHandler servletHandler = new ServletHandler();
        webSocketServlet = new WebsocketOutboundServlet();
        ServletHolder holder = new ServletHolder(webSocketServlet);
        servletHandler.addServletWithMapping(holder, uri + URI_SUFFIX);

        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setBaseResource(Resource.newClassPathResource("com/example/docroot/"));

        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[]{servletHandler, resourceHandler, new DefaultHandler()});
        server.setHandler(handlers);
        try {
            server.start();
            String url = "ws://localhost:" + port + uri;
            System.out.println(ImplMessages.getMessage("WS_SERVER_START_MSG", url));
            // add the shutdown hook
            Runtime.getRuntime().addShutdownHook(new Thread(() -> shutdown()));
        } catch (Exception error) {
            System.out.println(ImplMessages.getMessage("INIT_FAILURE", getClass().getName(), error.getMessage()));
            error.printStackTrace();
        }
    }
}
项目:performance-test-harness-for-geoevent    文件:WebsocketServerEventConsumer.java   
private void setup(int port) {
    if (server == null) {
        server = new Server(port);
        ServletHandler servletHandler = new ServletHandler();
        webSocketServlet = new WebsocketOutboundServlet(message -> receive(message));
        ServletHolder holder = new ServletHolder(webSocketServlet);
        servletHandler.addServletWithMapping(holder, uri + URI_SUFFIX);

        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setBaseResource(Resource.newClassPathResource("com/example/docroot/"));

        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[]{servletHandler, resourceHandler, new DefaultHandler()});
        server.setHandler(handlers);
        try {
            server.start();
            String url = "ws://localhost:" + port + uri;
            System.out.println(ImplMessages.getMessage("WS_SERVER_START_MSG", url));
            // add the shutdown hook
            Runtime.getRuntime().addShutdownHook(new Thread(() -> shutdown()));
        } catch (Exception error) {
            System.out.println(ImplMessages.getMessage("INIT_FAILURE", getClass().getName(), error.getMessage()));
            error.printStackTrace();
        }
    }
}
项目:armeria    文件:JettyServiceTest.java   
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.port(0, SessionProtocol.HTTP);
    sb.port(0, SessionProtocol.HTTPS);
    sb.sslContext(SessionProtocol.HTTPS,
                  certificate.certificateFile(),
                  certificate.privateKeyFile());

    sb.serviceUnder(
            "/jsp/",
            new JettyServiceBuilder()
                    .handler(newWebAppContext())
                    .configurator(s -> jettyBeans.addAll(s.getBeans()))
                    .build()
                    .decorate(LoggingService.newDecorator()));

    sb.serviceUnder(
            "/default/",
            new JettyServiceBuilder().handler(new DefaultHandler()).build());

    final ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setResourceBase(webAppRoot().getPath());
    sb.serviceUnder(
            "/resources/",
            new JettyServiceBuilder().handler(resourceHandler).build());
}
项目:xdocreport.samples    文件:EmbeddedServer.java   
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );


    server.start();
    server.join();
}
项目:xdocreport.samples    文件:EmbeddedServer.java   
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );


    server.start();
    server.join();
}
项目:xdocreport.samples    文件:EmbeddedServer.java   
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );


    server.start();
    server.join();
}
项目:tachyon-rdma    文件:UIWebServer.java   
/**
 * Constructor that pairs urls with servlets and sets the webapp folder.
 * 
 * @param serverName
 *          Name of the server
 * @param address
 *          Address of the server
 * @param masterInfo
 *          MasterInfo for the tachyon filesystem this UIWebServer supports
 * @return A new UIWebServer
 */
public UIWebServer(String serverName, InetSocketAddress address, MasterInfo masterInfo) {
  mAddress = address;
  mServerName = serverName;
  mServer = new Server(mAddress);

  WebAppContext webappcontext = new WebAppContext();

  webappcontext.setContextPath(Constants.PATH_SEPARATOR);
  File warPath = new File(CommonConf.get().WEB_RESOURCES);
  webappcontext.setWar(warPath.getAbsolutePath());
  HandlerList handlers = new HandlerList();
  webappcontext.addServlet(new ServletHolder(new WebInterfaceGeneralServlet(masterInfo)),
      "/home");
  webappcontext.addServlet(new ServletHolder(new WebInterfaceConfigurationServlet(masterInfo)),
      "/configuration");
  webappcontext.addServlet(new ServletHolder(new WebInterfaceBrowseServlet(masterInfo)),
      "/browse");
  webappcontext.addServlet(new ServletHolder(new WebInterfaceMemoryServlet(masterInfo)),
      "/memory");
  webappcontext.addServlet(new ServletHolder(new WebInterfaceDependencyServlet(masterInfo)),
      "/dependency");

  handlers.setHandlers(new Handler[] { webappcontext, new DefaultHandler() });
  mServer.setHandler(handlers);
}
项目:iif-resultsrepository    文件:ServerStarter.java   
public static void startWebServer(int port) throws Exception {
    webServer = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    webServer.addConnector(connector);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    //resource_handler.setWelcomeFiles(new String[] { "index.html" });

    String serverRoot = ServerStarter.class.getResource("/").getFile();

    resource_handler.setResourceBase(serverRoot);

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler,
            new DefaultHandler() });
    webServer.setHandler(handlers);

    webServer.start();

}
项目:pdi-agile-bi-plugin    文件:JettyServer.java   
public void startServer() throws Exception {
  server = new Server();

  WebAppContext pentahoContext = new WebAppContext();
  pentahoContext.setClassLoader(getClass().getClassLoader());
  pentahoContext.setContextPath("/pentaho"); //$NON-NLS-1$
  pentahoContext.setWar(webappsFolder + "/pentaho"); //$NON-NLS-1$

  pentahoContext.setParentLoaderPriority(true);

  HandlerCollection handlers= new HandlerCollection();
  handlers.setHandlers(new Handler[]{pentahoContext, new DefaultHandler()});

  server.setHandler(handlers);

  // Start execution
  createListeners();

  server.start();
}
项目:Zong    文件:Webserver.java   
/**
 * Starts the server.
 */
public void start() {
    try {
        //Handler setzen
        HandlerList handlerList = new HandlerList();
        for (Handler handler : handlers)
            handlerList.addHandler(handler);
        handlerList.addHandler(new DefaultHandler());
        server.setHandler(handlerList);
        //Server starten
        server.start();
        String log = "Server started. Listening on port " + port + ".";
        System.out.println(log);
        log(remark(log));
    } catch (Exception ex) {
        handle(fatal(ex));
    }
}
项目:iif-generic-soap-client    文件:ServerStarter.java   
public static void startWebServer(int port) throws Exception {
    webServer = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    webServer.addConnector(connector);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    //resource_handler.setWelcomeFiles(new String[] { "index.html" });

    String serverRoot = ServerStarter.class.getResource("/").getFile();

    resource_handler.setResourceBase(serverRoot);

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler,
            new DefaultHandler() });
    webServer.setHandler(handlers);

    webServer.start();

}
项目:ngWebDriver    文件:AngularAndWebDriverTest.java   
@BeforeSuite
public void before_suite() throws Exception {

    // Launch Protractor's own test app on http://localhost:8080
    ((StdErrLog) Log.getRootLogger()).setLevel(StdErrLog.LEVEL_OFF);
    webServer = new Server(new QueuedThreadPool(6));
    ServerConnector connector = new ServerConnector(webServer, new HttpConnectionFactory());
    connector.setPort(8080);
    webServer.addConnector(connector);
    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[]{"index.html"});
    resource_handler.setResourceBase("src/test/webapp");
    HandlerList handlers = new HandlerList();
    MovedContextHandler effective_symlink = new MovedContextHandler(webServer, "/lib/angular", "/lib/angular_v1.2.9");
    handlers.setHandlers(new Handler[] { effective_symlink, resource_handler, new DefaultHandler() });
    webServer.setHandler(handlers);
    webServer.start();

    driver = new ChromeDriver();
    driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
    ngWebDriver = new NgWebDriver(driver);
}
项目:jbake-rtl-jalaali    文件:JettyServer.java   
/**
 * Run Jetty web server serving out supplied path on supplied port
 * 
 * @param path
 * @param port
 */
public void run(String path, String port) {
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
       connector.setPort(Integer.parseInt(port));
       server.addConnector(connector);

       ResourceHandler resource_handler = new ResourceHandler();
       resource_handler.setDirectoriesListed(true);
       resource_handler.setWelcomeFiles(new String[]{ "index.html" });

       resource_handler.setResourceBase(path);

       HandlerList handlers = new HandlerList();
       handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
       server.setHandler(handlers);

       LOGGER.info("Serving out contents of: [{}] on http://localhost:{}/", path, port);
       LOGGER.info("(To stop server hit CTRL-C)");

       try {
        server.start();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:websocket    文件:Jetty9Ws.java   
/**
 * @param args
 */
public static void main(String[] args) {
    Properties p = PropertyUtil.loadProperties("/ws.properties");
    System.out.println(JsonUtil.toJsonStr(p));
    Server server = new Server(Integer.parseInt(p
            .getProperty("webSocketPort")));
    try {
        HandlerList handlerList = new HandlerList();

        /* websocket */
        ServletContextHandler context = new ServletContextHandler(
                ServletContextHandler.SESSIONS);
        context.setContextPath("/");
        context.addServlet(
                new ServletHolder(new Jwservlet(p
                        .getProperty("handlerClass"))), p
                        .getProperty("webSocketPath"));

        /* webapp */
        WebAppContext c = new WebAppContext();
        c.setContextPath("/w");
        c.setDescriptor("../websockets/WebRoot/WEB-INF/web.xml");
        c.setResourceBase("../websockets/WebRoot");

        handlerList.addHandler(c);
        handlerList.addHandler(context);
        handlerList.addHandler(new DefaultHandler());
        server.setHandler(handlerList);
        server.start();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:graphouse    文件:GraphouseWebServer.java   
private void startServer() throws Exception {

        log.info("Starting http server on port " + httpPort);
        Server server = new Server(new QueuedThreadPool(threadCount));
        ServerConnector serverConnector = new ServerConnector(server);
        serverConnector.setPort(httpPort);
        if (!Strings.isNullOrEmpty(httpBindAddress)) {
            serverConnector.setHost(httpBindAddress);
        }
        server.setConnectors(new Connector[]{serverConnector});
        ServletContextHandler context = new ServletContextHandler();
        context.setMaxFormContentSize(maxFormContextSizeBytes);
        context.setContextPath("/");

        ServletHolder metricSearchServletHolder = new ServletHolder(metricSearchServlet);
        context.addServlet(metricSearchServletHolder, "/search/*");
        context.addServlet(metricSearchServletHolder, "/ban/*");
        context.addServlet(metricSearchServletHolder, "/multiBan/*");
        context.addServlet(metricSearchServletHolder, "/approve/*");
        context.addServlet(metricSearchServletHolder, "/multiApprove/*");
        context.addServlet(metricSearchServletHolder, "/hide/*");
        context.addServlet(metricSearchServletHolder, "/multiHide/*");

        ServletHolder monitoringServletHolder = new ServletHolder(monitoringServlet);
        context.addServlet(monitoringServletHolder, "/ping");
        context.addServlet(monitoringServletHolder, "/monitoring");

        ServletHolder metricDataServletHolder = new ServletHolder(metricDataServiceServlet);
        context.addServlet(metricDataServletHolder, "/metricData");

        HandlerCollection handlers = new HandlerCollection();
        handlers.setHandlers(new Handler[]{context, new DefaultHandler()});
        server.setHandler(handlers);
        server.start();

        log.info("Web server started on port " + httpPort);
    }
项目:apache-archiva    文件:RemoteRepositoryConnectivityCheckTest.java   
protected Server buildStaticServer( File path )
{
    Server repoServer = new Server( 0 );

    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed( true );
    resourceHandler.setWelcomeFiles( new String[]{ "index.html" } );
    resourceHandler.setResourceBase( path.getAbsolutePath() );

    HandlerList handlers = new HandlerList();
    handlers.setHandlers( new Handler[]{ resourceHandler, new DefaultHandler() } );
    repoServer.setHandler( handlers );

    return repoServer;
}
项目:allure2    文件:Commands.java   
/**
 * Set up Jetty server to serve Allure Report
 */
protected Server setUpServer(final String host, final int port, final Path reportDirectory) {
    final Server server = Objects.isNull(host)
            ? new Server(port)
            : new Server(new InetSocketAddress(host, port));
    ResourceHandler handler = new ResourceHandler();
    handler.setRedirectWelcome(true);
    handler.setDirectoriesListed(true);
    handler.setResourceBase(reportDirectory.toAbsolutePath().toString());
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[]{handler, new DefaultHandler()});
    server.setStopAtShutdown(true);
    server.setHandler(handlers);
    return server;
}
项目:sonar-scanner-maven    文件:Proxy.java   
public int startProxy() throws Exception {
  seenByProxy.clear();
  InetAddress address = InetAddress.getLoopbackAddress();
  httpProxyPort = NetworkUtils.getNextAvailablePort(address);

  // Setup Threadpool
  QueuedThreadPool threadPool = new QueuedThreadPool();
  threadPool.setMaxThreads(500);

  server = new Server(threadPool);

  // HTTP Configuration
  HttpConfiguration httpConfig = new HttpConfiguration();
  httpConfig.setSecureScheme("https");
  httpConfig.setSendServerVersion(true);
  httpConfig.setSendDateHeader(false);

  // Handler Structure
  HandlerCollection handlers = new HandlerCollection();
  handlers.setHandlers(new Handler[] {proxyHandler(), new DefaultHandler()});
  server.setHandler(handlers);

  ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
  http.setPort(httpProxyPort);
  server.addConnector(http);
  server.start();

  return httpProxyPort;
}
项目:saito    文件:JettyPlugin.java   
/**
 * Run Jetty web server serving out supplied path on the supplied port on SaitoConfig
 *
 */
@Override
public void start(Saito saito, List<? extends SaitoFile> sources) {
    String dir = saito.getWorkingDir().resolve("build").toString();

    server = new Server();
    ServerConnector connector = new ServerConnector(server);

    connector.setPort(cfg.getPort());
    server.addConnector(connector);

    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed(true);
    resourceHandler.setWelcomeFiles(new String[]{"index.html"});
    resourceHandler.setResourceBase(dir);

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[]{resourceHandler, new DefaultHandler()});
    server.setHandler(handlers);

    log.info("Serving out contents of: [{}] on http://localhost:{}/", dir, cfg.getPort());
    log.info("(To stop server hit CTRL-C)");

    try {
        server.start();
        openBrowserIfPossible(cfg.getPort());
        server.join();
    } catch (Exception e) {
        log.error("Problems with Jetty Server", e);
    }
}
项目:tracing-framework    文件:WebServer.java   
private static Server setupServer() throws Exception {
    // String webDir = "target/classes/webui";
    // String webDir = "src/main/resources/webui";
    String webDir = WebServer.class.getClassLoader().getResource("webui").toExternalForm();
    log.info("Base webdir is {}", webDir);

    int httpPort = ConfigFactory.load().getInt("resource-reporting.visualization.webui-port");
    log.info("Resource reporting web ui port is ", httpPort);

    // Create Jetty server
    Server server = new Server(httpPort);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[] { "filter.html" });
    resource_handler.setResourceBase(webDir);

    WebSocketHandler wsHandler = new WebSocketHandler.Simple(PubSubProxyWebSocket.class);

    ContextHandler context = new ContextHandler();
    context.setContextPath("/ws");
    context.setHandler(wsHandler);

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { context, resource_handler, new DefaultHandler() });

    server.setHandler(handlers);

    ClusterResources.subscribeToAll(callback);

    return server;
}
项目:quick-csv-streamer    文件:HttpStreamTest.java   
@Override
protected void before() throws Throwable {
    server = new Server(0);

    ResourceHandler rh = new ResourceHandler();
       rh.setResourceBase("src/test/resources");

       HandlerList handlers = new HandlerList();
       handlers.setHandlers(new Handler[] { rh, new DefaultHandler() });
       server.setHandler(handlers);

       server.start();
}
项目:ZkPortal    文件:JettyZk.java   
/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    try {
        Server server = new Server(PORT);

        // Handler for multiple web apps
        HandlerCollection handlers = new HandlerCollection();

        // Creating the first web application context
        WebAppContext webcontext = new WebAppContext();
        webcontext.setResourceBase("src/com/delarosa/portal/web/");
        webcontext.setDefaultsDescriptor("src/com/delarosa/portal/webdefault.xml");

        ResourceHandler handler = new ResourceHandler();
        handler.setResourceBase("src/com/delarosa/portal/web/staticfiles/");

        handlers.addHandler(handler);
        handlers.addHandler(webcontext);
        handlers.addHandler(new DefaultHandler());

        // Adding the handlers to the server
        server.setHandler(handlers);

        // Starting the Server
        server.start();

        showBrowser();

        server.join();
    } catch (Exception ex) {
        Logger.getLogger(JettyZk.class.getName()).log(Level.SEVERE, null, ex);
    }
}
项目:forplay    文件:GameServer.java   
public GameServer(int port) {
  server = new Server(port);

  servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
  servletHandler.setContextPath("/rpc");

  resourceHandler = new ResourceHandler();
  resourceHandler.setDirectoriesListed(true);
  resourceHandler.setWelcomeFiles(new String[] {"index.html"});
  resourceHandler.setResourceBase("www");

  HandlerList list = new HandlerList();
  list.setHandlers(new Handler[] {resourceHandler, servletHandler, new DefaultHandler()});
  server.setHandler(list);
}
项目:go-maven-poller    文件:MavenRepositoryPollerTest.java   
@BeforeClass
public static void setUpLocalWebServer() throws Exception {
    server = new Server();

    final SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(0);
    server.addConnector(connector);

    final ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed(true);
    resourceHandler.setResourceBase(new File("src/test/resources/web").getAbsolutePath());

    final HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[]{resourceHandler, new DefaultHandler()});
    server.setHandler(handlers);

    final Thread serverThread = new Thread() {
        @Override
        public void run() {
            try {
                server.start();
                runningPort = server.getConnectors()[0].getLocalPort();
                server.join();
            } catch (final Exception e) {
                e.printStackTrace();
            }

        }
    };
    Executors.newSingleThreadExecutor().submit(serverThread);
}
项目:go-maven-poller    文件:MavenRepositoryMaterialTest.java   
@BeforeClass
public static void setUpLocalWebServer() throws Exception {
    server = new Server();

    final SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(0);
    server.addConnector(connector);

    final ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed(true);
    resourceHandler.setResourceBase(new File("src/test/resources/web").getAbsolutePath());

    final HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[]{resourceHandler, new DefaultHandler()});
    server.setHandler(handlers);

    final Thread serverThread = new Thread() {
        @Override
        public void run() {
            try {
                server.start();
                runningPort = server.getConnectors()[0].getLocalPort();
                server.join();
            } catch (final Exception e) {
                e.printStackTrace();
            }

        }
    };
    Executors.newSingleThreadExecutor().submit(serverThread);
}