Search in sources :

Example 56 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project graphql-java by graphql-java.

the class HttpMain method main.

public static void main(String[] args) throws Exception {
    // 
    // This example uses Jetty as an embedded HTTP server
    Server server = new Server(PORT);
    // 
    // In Jetty, handlers are how your get called backed on a request
    HttpMain main_handler = new HttpMain();
    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(false);
    resource_handler.setWelcomeFiles(new String[] { "index.html" });
    resource_handler.setResourceBase("./src/test/resources/httpmain");
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler, main_handler });
    server.setHandler(handlers);
    server.start();
    server.join();
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) Server(org.eclipse.jetty.server.Server) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler)

Example 57 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project selenium_java by sergueik.

the class AngularAndWebDriverTest method before_suite.

@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();
    setupBrowser("chrome");
    driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
    ngWebDriver = new NgWebDriver(driver);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HandlerList(org.eclipse.jetty.server.handler.HandlerList) StdErrLog(org.eclipse.jetty.util.log.StdErrLog) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) MovedContextHandler(org.eclipse.jetty.server.handler.MovedContextHandler) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) BeforeSuite(org.testng.annotations.BeforeSuite)

Example 58 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project yacy_grid_mcp by yacy.

the class APIServer method open.

private static void open(int port, String htmlPath) throws IOException {
    try {
        QueuedThreadPool pool = new QueuedThreadPool();
        pool.setMaxThreads(500);
        server = new Server(pool);
        ServerConnector connector = new ServerConnector(server);
        HttpConfiguration http_config = new HttpConfiguration();
        http_config.setRequestHeaderSize(65536);
        http_config.setResponseHeaderSize(65536);
        connector.addConnectionFactory(new HttpConnectionFactory(http_config));
        connector.setPort(port);
        connector.setName("httpd:" + port);
        // timout in ms when no bytes send / received
        connector.setIdleTimeout(20000);
        server.addConnector(connector);
        server.setStopAtShutdown(true);
        // add services
        ServletContextHandler servletHandler = new ServletContextHandler();
        for (Class<? extends Servlet> service : services) try {
            servletHandler.addServlet(service, ((APIHandler) (service.getConstructor().newInstance())).getAPIPath());
        } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
            Data.logger.warn(service.getName() + " instantiation error", e);
        }
        ErrorHandler errorHandler = new ErrorHandler();
        errorHandler.setShowStacks(true);
        servletHandler.setErrorHandler(errorHandler);
        HandlerList handlerlist2 = new HandlerList();
        if (htmlPath == null) {
            handlerlist2.setHandlers(new Handler[] { servletHandler, new DefaultHandler() });
        } else {
            FileHandler fileHandler = new FileHandler();
            fileHandler.setDirectoriesListed(true);
            fileHandler.setWelcomeFiles(new String[] { "index.html" });
            fileHandler.setResourceBase(htmlPath);
            handlerlist2.setHandlers(new Handler[] { fileHandler, servletHandler, new DefaultHandler() });
        }
        server.setHandler(handlerlist2);
        server.start();
    } catch (Throwable e) {
        throw new IOException(e.getMessage());
    }
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) IOException(java.io.IOException) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 59 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project JsonPath by json-path.

the class Main method main.

public static void main(String[] args) throws Exception {
    String configPort = "8080";
    if (args.length > 0) {
        configPort = args[0];
    }
    String port = System.getProperty("server.http.port", configPort);
    System.out.println("Server started on port: " + port);
    Server server = new Server();
    server.setConnectors(new Connector[] { createConnector(server, Integer.parseInt(port)) });
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
    context.setContextPath("/api");
    ServletHolder servletHolder = new ServletHolder(createJerseyServlet());
    servletHolder.setInitOrder(1);
    context.addServlet(servletHolder, "/*");
    WebAppContext webAppContext = new WebAppContext();
    webAppContext.setServer(server);
    webAppContext.setContextPath("/");
    String resourceBase = System.getProperty("resourceBase");
    if (resourceBase != null) {
        webAppContext.setResourceBase(resourceBase);
    } else {
        webAppContext.setResourceBase(Main.class.getResource("/webapp").toExternalForm());
    }
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { context, webAppContext });
    server.setHandler(handlers);
    server.start();
    server.join();
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 60 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project stagen by wiztools.

the class RunnerRun method run.

@Override
public void run(final File baseDir) throws IOException, ExecutorException {
    // Generate site:
    clean.run(baseDir);
    gen.run(baseDir);
    // Start monitoring service:
    startMonitoring(baseDir);
    // Start server:
    try {
        LOG.log(Level.INFO, "Starting HTTP server at port: {0}", cmd.port);
        Server server = new Server(cmd.port);
        ResourceHandler rh = new ResourceHandler();
        rh.setDirectoriesListed(true);
        rh.setWelcomeFiles(new String[] { "index.html" });
        rh.setResourceBase(Constants.getOutDir(baseDir).getPath());
        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[] { rh, new DefaultHandler() });
        server.setHandler(handlers);
        server.start();
        server.join();
    } catch (Exception ex) {
        throw new ExecutorException(ex);
    }
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) Server(org.eclipse.jetty.server.Server) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) IOException(java.io.IOException) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Aggregations

HandlerList (org.eclipse.jetty.server.handler.HandlerList)71 Server (org.eclipse.jetty.server.Server)44 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)32 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)26 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)21 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)20 ServerConnector (org.eclipse.jetty.server.ServerConnector)16 IOException (java.io.IOException)13 Handler (org.eclipse.jetty.server.Handler)12 File (java.io.File)11 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)10 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)10 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)8 DefaultServlet (org.eclipse.jetty.servlet.DefaultServlet)8 ArrayList (java.util.ArrayList)7 ServletException (javax.servlet.ServletException)6 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)6 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)6 Test (org.junit.Test)6 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)5