Search in sources :

Example 21 with Handler

use of org.eclipse.jetty.server.Handler in project airpal by airbnb.

the class AirpalApplicationBase method run.

@Override
public void run(T config, Environment environment) throws Exception {
    this.injector = Guice.createInjector(Stage.PRODUCTION, getModules(config, environment));
    System.setProperty(IO_BUFFER_SIZE, String.valueOf(config.getBufferSize().toBytes()));
    environment.healthChecks().register("presto", injector.getInstance(PrestoHealthCheck.class));
    environment.jersey().register(injector.getInstance(ExecuteResource.class));
    environment.jersey().register(injector.getInstance(QueryResource.class));
    environment.jersey().register(injector.getInstance(QueriesResource.class));
    environment.jersey().register(injector.getInstance(UserResource.class));
    environment.jersey().register(injector.getInstance(UsersResource.class));
    environment.jersey().register(injector.getInstance(TablesResource.class));
    environment.jersey().register(injector.getInstance(HealthResource.class));
    environment.jersey().register(injector.getInstance(PingResource.class));
    environment.jersey().register(injector.getInstance(SessionResource.class));
    environment.jersey().register(injector.getInstance(FilesResource.class));
    environment.jersey().register(injector.getInstance(ResultsPreviewResource.class));
    environment.jersey().register(injector.getInstance(S3FilesResource.class));
    environment.jersey().register(injector.getInstance(AirpalUserFactory.class));
    // Setup SSE (Server Sent Events)
    ServletRegistration.Dynamic sseServlet = environment.servlets().addServlet("updates", injector.getInstance(SSEEventSourceServlet.class));
    sseServlet.setAsyncSupported(true);
    sseServlet.addMapping("/api/updates/subscribe");
    // Disable GZIP content encoding for SSE endpoints
    environment.lifecycle().addServerLifecycleListener(server -> {
        for (Handler handler : server.getChildHandlersByClass(BiDiGzipHandler.class)) {
            ((BiDiGzipHandler) handler).addExcludedMimeTypes(SERVER_SENT_EVENTS);
        }
    });
}
Also used : SSEEventSourceServlet(com.airbnb.airpal.resources.sse.SSEEventSourceServlet) SessionResource(com.airbnb.airpal.resources.SessionResource) QueryResource(com.airbnb.airpal.resources.QueryResource) PrestoHealthCheck(com.airbnb.airpal.core.health.PrestoHealthCheck) UserResource(com.airbnb.airpal.resources.UserResource) Handler(org.eclipse.jetty.server.Handler) BiDiGzipHandler(io.dropwizard.jetty.BiDiGzipHandler) FilesResource(com.airbnb.airpal.resources.FilesResource) S3FilesResource(com.airbnb.airpal.resources.S3FilesResource) PingResource(com.airbnb.airpal.resources.PingResource) AirpalUserFactory(com.airbnb.airpal.core.AirpalUserFactory) ResultsPreviewResource(com.airbnb.airpal.resources.ResultsPreviewResource) ExecuteResource(com.airbnb.airpal.resources.ExecuteResource) ServletRegistration(javax.servlet.ServletRegistration) QueriesResource(com.airbnb.airpal.resources.QueriesResource) TablesResource(com.airbnb.airpal.resources.TablesResource) UsersResource(com.airbnb.airpal.resources.UsersResource) S3FilesResource(com.airbnb.airpal.resources.S3FilesResource) HealthResource(com.airbnb.airpal.resources.HealthResource) BiDiGzipHandler(io.dropwizard.jetty.BiDiGzipHandler)

Example 22 with Handler

use of org.eclipse.jetty.server.Handler in project spark by perwendel.

the class EmbeddedJettyServer method ignite.

/**
     * {@inheritDoc}
     */
@Override
public int ignite(String host, int port, SslStores sslStores, int maxThreads, int minThreads, int threadIdleTimeoutMillis) {
    if (port == 0) {
        try (ServerSocket s = new ServerSocket(0)) {
            port = s.getLocalPort();
        } catch (IOException e) {
            logger.error("Could not get first available port (port set to 0), using default: {}", SPARK_DEFAULT_PORT);
            port = SPARK_DEFAULT_PORT;
        }
    }
    server = JettyServer.create(maxThreads, minThreads, threadIdleTimeoutMillis);
    ServerConnector connector;
    if (sslStores == null) {
        connector = SocketConnectorFactory.createSocketConnector(server, host, port);
    } else {
        connector = SocketConnectorFactory.createSecureSocketConnector(server, host, port, sslStores);
    }
    server = connector.getServer();
    server.setConnectors(new Connector[] { connector });
    ServletContextHandler webSocketServletContextHandler = WebSocketServletContextHandlerFactory.create(webSocketHandlers, webSocketIdleTimeoutMillis);
    // Handle web socket routes
    if (webSocketServletContextHandler == null) {
        server.setHandler(handler);
    } else {
        List<Handler> handlersInList = new ArrayList<>();
        handlersInList.add(handler);
        // WebSocket handler must be the last one
        if (webSocketServletContextHandler != null) {
            handlersInList.add(webSocketServletContextHandler);
        }
        HandlerList handlers = new HandlerList();
        handlers.setHandlers(handlersInList.toArray(new Handler[handlersInList.size()]));
        server.setHandler(handlers);
    }
    try {
        logger.info("== {} has ignited ...", NAME);
        logger.info(">> Listening on {}:{}", host, port);
        server.start();
    } catch (Exception e) {
        logger.error("ignite failed", e);
        System.exit(100);
    }
    return port;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HandlerList(org.eclipse.jetty.server.handler.HandlerList) ArrayList(java.util.ArrayList) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Handler(org.eclipse.jetty.server.Handler) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) IOException(java.io.IOException)

Example 23 with Handler

use of org.eclipse.jetty.server.Handler in project spring-boot by spring-projects.

the class JettyServletWebServerFactoryTests method assertTimeout.

private void assertTimeout(JettyServletWebServerFactory factory, int expected) {
    this.webServer = factory.getWebServer();
    JettyWebServer jettyWebServer = (JettyWebServer) this.webServer;
    Handler[] handlers = jettyWebServer.getServer().getChildHandlersByClass(WebAppContext.class);
    WebAppContext webAppContext = (WebAppContext) handlers[0];
    int actual = webAppContext.getSessionHandler().getMaxInactiveInterval();
    assertThat(actual).isEqualTo(expected);
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Handler(org.eclipse.jetty.server.Handler)

Example 24 with Handler

use of org.eclipse.jetty.server.Handler in project spring-boot by spring-projects.

the class JettyServletWebServerFactoryTests method wrappedHandlers.

@Test
public void wrappedHandlers() throws Exception {
    JettyServletWebServerFactory factory = getFactory();
    factory.setServerCustomizers(Arrays.asList(new JettyServerCustomizer() {

        @Override
        public void customize(Server server) {
            Handler handler = server.getHandler();
            HandlerWrapper wrapper = new HandlerWrapper();
            wrapper.setHandler(handler);
            HandlerCollection collection = new HandlerCollection();
            collection.addHandler(wrapper);
            server.setHandler(collection);
        }
    }));
    this.webServer = factory.getWebServer(exampleServletRegistration());
    this.webServer.start();
    assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World");
}
Also used : Server(org.eclipse.jetty.server.Server) Handler(org.eclipse.jetty.server.Handler) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper) Test(org.junit.Test)

Example 25 with Handler

use of org.eclipse.jetty.server.Handler in project otter by alibaba.

the class JettyEmbedServer method start.

public void start() throws Exception {
    Resource configXml = Resource.newSystemResource(config);
    XmlConfiguration configuration = new XmlConfiguration(configXml.getInputStream());
    server = (Server) configuration.configure();
    //        Integer port = getPort();
    //        if (port != null && port > 0) {
    //            Connector[] connectors = server.getConnectors();
    //            for (Connector connector : connectors) {
    //                connector.setPort(port);
    //            }
    //        }
    Handler handler = server.getHandler();
    if (handler != null && handler instanceof WebAppContext) {
        WebAppContext webAppContext = (WebAppContext) handler;
        webAppContext.setResourceBase(JettyEmbedServer.class.getResource("/webapp").toString());
    }
    server.start();
    if (logger.isInfoEnabled()) {
        logger.info("##Jetty Embed Server is startup!");
    }
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Resource(org.eclipse.jetty.util.resource.Resource) Handler(org.eclipse.jetty.server.Handler) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration)

Aggregations

Handler (org.eclipse.jetty.server.Handler)63 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)18 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)18 Server (org.eclipse.jetty.server.Server)14 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)13 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)12 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)10 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)10 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)10 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)7 ServerConnector (org.eclipse.jetty.server.ServerConnector)7 ErrorHandler (org.eclipse.jetty.server.handler.ErrorHandler)7 HandlerList (org.eclipse.jetty.server.handler.HandlerList)7 ArrayList (java.util.ArrayList)6 Connector (org.eclipse.jetty.server.Connector)6 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)6 Test (org.junit.Test)6 HandlerWrapper (org.eclipse.jetty.server.handler.HandlerWrapper)5 GzipHandler (org.eclipse.jetty.server.handler.gzip.GzipHandler)5 URI (java.net.URI)4