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

项目:otus_java_2017_06    文件:Main.java   
public static void main(String[] args) throws Exception {

        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setResourceBase(PUBLIC_HTML);

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

        //page reloaded by the timer
        context.addServlet(TimerServlet.class, "/timer");
        //part of a page reloaded by the timer
        context.addServlet(AjaxTimerServlet.class, "/server-time");
        //long-polling waits till a message
        context.addServlet(new ServletHolder(new MessengerServlet()), "/messenger");
        //web chat
        context.addServlet(WebSocketChatServlet.class, "/chat");

        Server server = new Server(PORT);
        server.setHandler(new HandlerList(resourceHandler, context));

        server.start();
        server.join();
    }
项目: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();
    }
项目:otus_java_2017_06    文件:Main.java   
private void start() throws Exception {
    resourcesExample();

    ResourceHandler resourceHandler = new ResourceHandler();
    Resource resource = Resource.newClassPathResource(PUBLIC_HTML);
    resourceHandler.setBaseResource(resource);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

    context.addServlet(new ServletHolder(new TimerServlet()), "/timer");

    Server server = new Server(PORT);
    server.setHandler(new HandlerList(resourceHandler, context));

    server.start();
    server.join();
}
项目:otus_java_2017_06    文件:Main.java   
public static void main(String[] args) throws Exception {

        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setResourceBase(PUBLIC_HTML);

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

        context.addServlet(new ServletHolder(new LoginServlet("anonymous")), "/login");
        context.addServlet(AdminServlet.class, "/admin");
        context.addServlet(TimerServlet.class, "/timer");

        Server server = new Server(PORT);
        server.setHandler(new HandlerList(resourceHandler, context));

        server.start();
        server.join();
    }
项目:otus_java_2017_04    文件:Main.java   
public static void main(String[] args) throws Exception {

        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setResourceBase(PUBLIC_HTML);

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

        context.addServlet(new ServletHolder(new LoginServlet("anonymous")), "/login");
        context.addServlet(AdminServlet.class, "/admin");
        context.addServlet(TimerServlet.class, "/timer");

        Server server = new Server(PORT);
        server.setHandler(new HandlerList(resourceHandler, context));

        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);
    }
}
项目:paul0-application-server    文件:HomeServerConfig.java   
private HandlerList getAllServices() throws Exception{
    // File server & Context Handler for root, also setting the index.html
    // to be the "welcome file", i.e, autolink on root addresses.
    ContextHandler rootContext = new ContextHandler();
    rootContext.setContextPath("/*");
    rootContext.setHandler(getResourceHandlers());

    // Possible servlet lists, for all servlets or custom services you want to access later.
    // Warning, it might become a little bit nested if you add to many classes.
    ServletHandler questionHandler = new ServletHandler();
    questionHandler.addServletWithMapping(QuestionHandler.class, "/question");

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

    return handlers;
}
项目:JDHttpAPI    文件:HttpAPIExtension.java   
private void startServer() {
    HttpAPIConfig cfg = getSettings();
    server = new Server(cfg.getPort());
    HandlerList lst = new HandlerList();
    LinkController ctr = new JDLinkController(LinkCollector.getInstance());
    if(cfg.getUsePassword() && cfg.getPassword() != null && !cfg.getPassword().equals("")) {
        lst.addHandler(new AuthorizationHandler(cfg.getPassword()));
    }
    lst.addHandler(new AjaxHandler(cfg.getAllowGet()));
    if(cfg.getAllowGet()) {
        lst.addHandler(new JDServerGETHandler(ctr));
    }
    lst.addHandler(new JDServerPOSTHandler(ctr));
    server.setHandler(lst);
    try {
        server.start();
    }
    catch(Exception e) {
        logger.log(new LogRecord(Level.SEVERE, e.getMessage()));
    }
}
项目:JDHttpAPI    文件:Program.java   
public static void main(String[] args) {
    int port = 8297;
    HandlerList lst = new HandlerList();

    String password = null;//"pass";
    Server server = new Server(port);
    JDServerPOSTHandler hnd;
    LinkController ctr = new SampleLinkController();
    if(password != null) {
        lst.addHandler(new AuthorizationHandler(password));
    }
    lst.addHandler(new AjaxHandler(true));
    lst.addHandler(new JDServerGETHandler(ctr));
    lst.addHandler(new JDServerPOSTHandler(ctr));
    server.setHandler(lst);
    try {
        server.start();
        server.join();
    }
    catch(Exception e) {
        System.out.println(e);
    }
}
项目:leopard    文件:WebappDaoImpl.java   
protected Handler getHandlerList(List<String> hostList) {
    // jettyServer.getWebappService().addHandler(new HostResourceHandler("fshop.leopard.io", "/data/src/fshop_html/"));
    // jettyServer.getWebappService().addHandler(new HostResourceHandler("ftrade.leopard.io", "/data/src/ftrade_html/"));
    if (hostList.contains("fshop.leopard.io")) {
        if (false) {
            return new HostResourceHandler("fshop.leopard.io", "/data/src/fshop_html/");
        }
        HandlerList handlerList = new HandlerList();
        handlerList.addHandler(new HostResourceHandler("fshop.leopard.io", "/data/src/fshop_html/"));
        handlerList.addHandler(new HostResourceHandler("ftrade.leopard.io", "/data/src/ftrade_html/"));
        try {
            handlerList.start();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return handlerList;
    }
    return null;
}
项目:tired    文件:WebServer.java   
public void start() {
    try {
        final ServerConnector httpConnector = new ServerConnector(server);

        httpConnector.setHost(root.host);
        httpConnector.setPort(root.port);
        httpConnector.setIdleTimeout(config.getInt("web.idle-timeout"));
        server.addConnector(httpConnector);

        final HandlerList handlers = new HandlerList();

        handlers.addHandler(inContext("/static", newResourcesHandler()));
        handlers.addHandler(inContext("/", new RootHandler(version, routes)));

        server.setHandler(handlers);
        server.start();

        log.info("Web Server started on http://" + root.host + ":" + root.port);
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
        throw new RuntimeException(ex);
    }
}
项目:megaphone    文件:RedirectTest.java   
@BeforeClass
@Override
public void setUpGlobal() throws Exception {
    port1 = findFreePort();
    port2 = findFreePort();

    server = newJettyHttpServer(port1);
    addHttpConnector(server, port2);

    HandlerList list = new HandlerList();
    list.addHandler(new AbstractHandler() {
        @Override
        public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
            if (request.getLocalPort() == port2) {
                httpServletResponse.sendRedirect(getTargetUrl());
            }
        }
    });
    list.addHandler(getWebSocketHandler());
    server.setHandler(list);

    server.start();
    logger.info("Local HTTP server started successfully");
}
项目: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();
}
项目:stepic-java-web-service    文件:Main.java   
public static void main(String[] args) throws Exception {
    AccountService accountService = new AccountService();

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new SingUpServlet(accountService)), "/signup");
    context.addServlet(new ServletHolder(new SignInServlet(accountService)), "/signin");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setResourceBase("public_html");

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

    Server server = new Server(8080);
    server.setHandler(handlers);

    server.start();
    System.out.println("Server started");
    server.join();
}
项目:stepic-java-web-service    文件:Main.java   
public static void main(String[] args) throws Exception {
    AccountService accountService = new AccountService();

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new SingUpServlet(accountService)), "/signup");
    context.addServlet(new ServletHolder(new SignInServlet(accountService)), "/signin");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setResourceBase("public_html");

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

    Server server = new Server(8080);
    server.setHandler(handlers);

    server.start();
    System.out.println("Server started");
    server.join();
}
项目:ismv-server    文件:Server.java   
public int run() throws Exception {
    org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(port);
    HandlerList handlerList = new HandlerList();

    ServletContextHandler servletContextHandler = new ServletContextHandler();
    FilterHolder cof = new FilterHolder(new CrossOriginFilter());
    cof.setInitParameter(
            CrossOriginFilter.EXPOSED_HEADERS_PARAM,
            "Date");
    servletContextHandler.addFilter(cof, "/*", EnumSet.of(DispatcherType.INCLUDE, DispatcherType.REQUEST));
    servletContextHandler.addServlet(new ServletHolder(new SmoothStreamingServlet(dataDir)), "/*");
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setBaseResource(Resource.newClassPathResource("supportfiles"));
    handlerList.addHandler(resourceHandler);
    handlerList.addHandler(servletContextHandler);
    server.setHandler(handlerList);

    server.start();
    server.dumpStdErr();
    server.join();
    return 0;
}
项目:bartleby    文件:JettyFixtureBase.java   
public void start() throws Exception {
  server = new Server();
  Connector connector = new SelectChannelConnector();
  connector.setPort(port);
  server.setConnectors(new Connector[]{connector});

  RequestLogHandler requestLogHandler = new RequestLogHandler();
  configureRequestLogImpl();
  requestLogHandler.setRequestLog(requestLogImpl);

  HandlerList handlers = new HandlerList();
  handlers.addHandler(requestLogHandler);
  handlers.addHandler(getRequestHandler());

  server.setHandler(handlers);
  server.start();
}
项目: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();
}
项目:homework_tester    文件:Main.java   
public static void main(String[] args) throws Exception {
    Server server = new Server(8080);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

    context.addServlet(new ServletHolder(new WebSocketChatServlet()), "/chat");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setResourceBase("public_html");

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

    server.start();
    System.out.println("Server started!");
    server.join();
}
项目:javatra    文件:YuckServer.java   
public void start() {
    try {
        server = new Server();
        ServerConnector connector = new ServerConnector(server);
        connector.setPort(port);
        connector.setIdleTimeout(idleTimeout);
        server.setConnectors(new Connector[] { connector });
        HandlerList handlers = new HandlerList();
        handlers.addHandler(handler);
        server.setHandler(handlers);
        server.start();
        server.join();
    } catch (Exception e) {
        // TODO : log here
        System.exit(1);
    }
}
项目:scheduling    文件:JettyStarter.java   
private void addWarsToHandlerList(HandlerList handlerList, String[] virtualHost) {
    File warFolder = new File(getSchedulerHome() + FOLDER_TO_DEPLOY);
    File[] warFolderContent = warFolder.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return !"getstarted".equals(name);
        }
    });

    if (warFolderContent != null) {
        for (File fileToDeploy : warFolderContent) {
            if (isExplodedWebApp(fileToDeploy)) {
                addExplodedWebApp(handlerList, fileToDeploy, virtualHost);
            } else if (isWarFile(fileToDeploy)) {
                addWarFile(handlerList, fileToDeploy, virtualHost);
            } else if (isStaticFolder(fileToDeploy)) {
                addStaticFolder(handlerList, fileToDeploy, virtualHost);
            }
        }
    }

    addGetStartedApplication(handlerList, new File(warFolder, "getstarted"), virtualHost);
}
项目:jersey-guice-jetty-angular-seed    文件:Main.java   
public void startServer() throws Exception {
    int serverPort = propertiesConfiguration.getInt("server.port.http");
    Server server = new Server(serverPort);

    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setBaseResource(Resource.newClassPathResource("/web"));

    ServletContextHandler servletContextHandler = new ServletContextHandler(server, "/api");
    servletContextHandler.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));

    initGuiceInjector();

    HandlerList handlerList = new HandlerList();
    handlerList.addHandler(resourceHandler);
    handlerList.addHandler(servletContextHandler);
    server.setHandler(handlerList);

    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();
        }
    }
}
项目:stepic_java_webserver    文件:Main.java   
public static void main(String[] args) throws Exception {
    AccountService accountService = new AccountService();

    accountService.addNewUser(new UserProfile("admin"));
    accountService.addNewUser(new UserProfile("test"));

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new UsersServlet(accountService)), "/api/v1/users");
    context.addServlet(new ServletHolder(new SessionsServlet(accountService)), "/api/v1/sessions");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setResourceBase("public_html");

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

    Server server = new Server(8080);
    server.setHandler(handlers);

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

    context.addServlet(new ServletHolder(new WebSocketChatServlet()), "/chat");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setResourceBase("public_html");

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

    server.start();
    server.join();
}
项目:chaos-http-proxy    文件:ChaosHttpProxy.java   
public ChaosHttpProxy(URI endpoint, ChaosConfig config)
        throws Exception {
    setChaosConfig(config);

    Supplier<Failure> supplier = new RandomFailureSupplier(
            config.getFailures());

    requireNonNull(endpoint);

    client = new HttpClient();

    server = new Server();
    HttpConnectionFactory httpConnectionFactory =
            new HttpConnectionFactory();
    // TODO: SSL
    ServerConnector connector = new ServerConnector(server,
            httpConnectionFactory);
    connector.setHost(endpoint.getHost());
    connector.setPort(endpoint.getPort());
    server.addConnector(connector);
    this.handler = new ChaosHttpProxyHandler(client, supplier);
    HandlerList handlers = new HandlerList();
    handlers.addHandler(new ChaosApiHandler(this, handler));
    handlers.addHandler(handler);
    server.setHandler(handlers);
}
项目:tp_java_2015_02    文件:Main.java   
public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.out.append("Use port as the first argument");
        System.exit(1);
    }

    String portString = args[0];
    int port = Integer.valueOf(portString);
    System.out.append("Starting at port: ").append(portString).append('\n');

    Server server = new Server(port);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new AdminPageServlet()), AdminPageServlet.adminPageURL);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setResourceBase("static");

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

    server.start();
    server.join();
}
项目:flow    文件:JettyServer.java   
public static void start(@Nonnull Config config, @Nonnull List<Handler> extraHandlers,
        @Nonnull WebSocketCreator creator) throws Exception {
    checkNotNull(config);
    checkNotNull(creator);

    long idleTimeout = config.getTime("webserver.idleTimeout", "10m");
    int maxTextMessageSize = config.getInt("webserver.maxTextMessageSize", 1024 * 1024);

    HandlerList handlers = new HandlerList();
    handlers.addHandler(new WebSocketHandler() {
        @Override
        public void configure(WebSocketServletFactory factory) {
            factory.getPolicy().setIdleTimeout(idleTimeout);
            factory.getPolicy().setMaxTextMessageSize(maxTextMessageSize);
            factory.setCreator(creator);
        }
    });
    for (Handler handler : extraHandlers) {
        handlers.addHandler(handler);
    }

    Server server = new Server(config.getInt("webserver.port", 8034));
    server.setHandler(handlers);
    server.start();
}
项目:druid-hadoop-utils    文件:OverlordTestServer.java   
public void start() throws Exception
{
  logger.info("Starting OverlordTestServer................");

  port = findFreePort(port);
  server = new Server(port);
  ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
  root.addServlet(SegmentListerServlet.class, "/druid/indexer/v1/action");

  HandlerList handlerList = new HandlerList();
  handlerList.setHandlers(new Handler[]{root});
  server.setHandler(handlerList);

  server.start();
  logger.info("Started OverlordTestServer................");
}
项目:mesos-hbase    文件:ConfigServer.java   
@Inject
public ConfigServer(HBaseFrameworkConfig hbaseFrameworkConfig,
    IPersistentStateStore persistenceStore) {
  this.hbaseFrameworkConfig = hbaseFrameworkConfig;
  this.persistenceStore = persistenceStore;
  engine = new Engine();
  server = new Server(hbaseFrameworkConfig.getConfigServerPort());
  ResourceHandler resourceHandler = new ResourceHandler();
  resourceHandler.setResourceBase(hbaseFrameworkConfig.getExecutorPath());
  HandlerList handlers = new HandlerList();
  handlers.setHandlers(new Handler[]{
      resourceHandler, new ServeHbaseConfigHandler()});
  server.setHandler(handlers);

  try {
    server.start();

  } catch (Exception e) {
    final String msg = "Unable to start jetty server";
    log.error(msg, e);
    throw new ConfigServerException(msg, e);
  }
}
项目:stepic-java-web-service    文件:Main.java   
public static void main(String[] args) throws Exception {
    AccountService accountService = new AccountService();

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new SingUpServlet(accountService)), "/signup");
    context.addServlet(new ServletHolder(new SignInServlet(accountService)), "/signin");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setResourceBase("public_html");

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

    Server server = new Server(8080);
    server.setHandler(handlers);

    server.start();
    System.out.println("Server started");
    server.join();
}
项目:stepic-java-web-service    文件:Main.java   
public static void main(String[] args) throws Exception {
    AccountService accountService = new AccountService();

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new SingUpServlet(accountService)), "/signup");
    context.addServlet(new ServletHolder(new SignInServlet(accountService)), "/signin");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setResourceBase("public_html");

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

    Server server = new Server(8080);
    server.setHandler(handlers);

    server.start();
    System.out.println("Server started");
    server.join();
}
项目:scale.commons    文件:ServletServerBuilder.java   
/**
 * Builds a {@link Server} object from the parameters passed to the
 * {@link ServletServerBuilder}.
 *
 * @return
 */
public Server build() {
    // build base server
    Server server = this.baseServerBuilder.build();

    // build each servlet to be published
    HandlerList servletHandlers = new HandlerList();
    for (ServletDefinition servletDefinition : this.servletDefinitions) {
        // create the servlet request handler
        ServletContextHandler servletHandler = createServletHandler(servletDefinition);

        // add security handler if security settings were specified
        if (servletDefinition.isRequireHttps() || servletDefinition.isRequireBasicAuth()) {
            ConstraintSecurityHandler securityHandler = createSecurityHandler(server, servletDefinition);
            servletHandler.setSecurityHandler(securityHandler);
        }
        if (servletDefinition.isSupportCors()) {
            addCrossOriginFilter(servletHandler);
        }
        servletHandlers.addHandler(servletHandler);
    }
    server.setHandler(servletHandlers);

    return server;
}
项目:nomcat    文件:Main.java   
private static void startServer(String workingDir, List<String> specificWARs) throws Exception
{
    Server server = new Server(port);

    List<ContextHandler> warHandlers = createWarHandlers(workingDir, specificWARs);
    Handler indexHandler = createIndexContext(warHandlers);

    List<Handler> allHandlers = new ArrayList<Handler>();
    allHandlers.addAll(warHandlers);
    allHandlers.add(indexHandler);
    HandlerList handlerList = new HandlerList();
    handlerList.setHandlers(allHandlers.toArray(new Handler[]{}));
    server.setHandler(handlerList);

    server.start();

    info("\n##############################\n# Server up on port " + port + "!\n##############################");

    server.join();
}
项目:Eemory    文件:JettyCallback.java   
@Override
public void ready() throws Exception {
    server = new Server();

    http = new ServerConnector(server);
    http.setHost(HttpUtil.LOCALHOST);
    http.setPort(0);
    server.addConnector(http);

    BundledResourceHandler resourceHandler = new BundledResourceHandler();
    resourceHandler.setLoadingClass(getClass());
    resourceHandler.setResourceBase(Constants.OAUTH_RESOURCE_BASE);
    resourceHandler.setWelcomeFiles(ArrayUtils.toArray(Constants.OAUTH_DEFAULT_HTML));

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(ArrayUtils.toArray(this, resourceHandler, new DefaultHandler()));
    server.setHandler(handlers);

    server.start();
}
项目:bkbc-tools    文件:JettyCrosServer.java   
public JettyCrosServer() throws Exception {
    server = new Server(80);
    HandlerList handlers = new HandlerList();
       ResourceHandler resource_handler = new ResourceHandler();
       resource_handler.setDirectoriesListed(true);
       resource_handler.setWelcomeFiles(new String[] { "index.html" });
       resource_handler.setBaseResource(Resource.newClassPathResource("web"));

       ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
       context.setContextPath("/");
       context.setInitParameter("maxInterval", "1000");
       context.setInitParameter("logLevel", "2");

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

       server.setHandler(handlers);


       FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
       filterHolder.getInitParameters().put(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "X-Requested-With,Content-Type,Accept,Origin,Authorization");
       context.addFilter(filterHolder, "/*", EnumSet.allOf(DispatcherType.class));

       context.addServlet(new ServletHolder(new JsonServlet()), "/t.json");
       context.addServlet(new ServletHolder(new DefaultServlet()), "/*");

}
项目: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);
}