Search in sources :

Example 21 with StatisticsHandler

use of org.eclipse.jetty.server.handler.StatisticsHandler in project kafka by apache.

the class JsonRestServer method start.

/**
 * Start the JsonRestServer.
 *
 * @param resources         The path handling resources to register.
 */
public void start(Object... resources) {
    log.info("Starting REST server");
    ResourceConfig resourceConfig = new ResourceConfig();
    resourceConfig.register(new JacksonJsonProvider(JsonUtil.JSON_SERDE));
    for (Object resource : resources) {
        resourceConfig.register(resource);
        log.info("Registered resource {}", resource);
    }
    resourceConfig.register(RestExceptionMapper.class);
    ServletContainer servletContainer = new ServletContainer(resourceConfig);
    ServletHolder servletHolder = new ServletHolder(servletContainer);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    context.addServlet(servletHolder, "/*");
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    Slf4jRequestLogWriter slf4jRequestLogWriter = new Slf4jRequestLogWriter();
    slf4jRequestLogWriter.setLoggerName(JsonRestServer.class.getCanonicalName());
    CustomRequestLog requestLog = new CustomRequestLog(slf4jRequestLogWriter, CustomRequestLog.EXTENDED_NCSA_FORMAT + " %{ms}T");
    requestLogHandler.setRequestLog(requestLog);
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers(new Handler[] { context, new DefaultHandler(), requestLogHandler });
    StatisticsHandler statsHandler = new StatisticsHandler();
    statsHandler.setHandler(handlers);
    jettyServer.setHandler(statsHandler);
    /* Needed for graceful shutdown as per `setStopTimeout` documentation */
    jettyServer.setStopTimeout(GRACEFUL_SHUTDOWN_TIMEOUT_MS);
    jettyServer.setStopAtShutdown(true);
    try {
        jettyServer.start();
    } catch (Exception e) {
        throw new RuntimeException("Unable to start REST server", e);
    }
    log.info("REST server listening at " + jettyServer.getURI());
}
Also used : CustomRequestLog(org.eclipse.jetty.server.CustomRequestLog) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) Slf4jRequestLogWriter(org.eclipse.jetty.server.Slf4jRequestLogWriter) IOException(java.io.IOException) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) StatisticsHandler(org.eclipse.jetty.server.handler.StatisticsHandler)

Example 22 with StatisticsHandler

use of org.eclipse.jetty.server.handler.StatisticsHandler in project vespa by vespa-engine.

the class JettyHttpServer method getHandlerCollection.

private HandlerCollection getHandlerCollection(ServerConfig serverConfig, ServletPathsConfig servletPathsConfig, ServletHolder jdiscServlet, ComponentRegistry<ServletHolder> servletHolders, FilterHolder jDiscFilterInvokerFilter, RequestLog requestLog) {
    ServletContextHandler servletContextHandler = createServletContextHandler();
    servletHolders.allComponentsById().forEach((id, servlet) -> {
        String path = getServletPath(servletPathsConfig, id);
        servletContextHandler.addServlet(servlet, path);
        servletContextHandler.addFilter(jDiscFilterInvokerFilter, path, EnumSet.allOf(DispatcherType.class));
    });
    servletContextHandler.addServlet(jdiscServlet, "/*");
    GzipHandler gzipHandler = newGzipHandler(serverConfig);
    gzipHandler.setHandler(servletContextHandler);
    StatisticsHandler statisticsHandler = newStatisticsHandler();
    statisticsHandler.setHandler(gzipHandler);
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    requestLogHandler.setRequestLog(requestLog);
    HandlerCollection handlerCollection = new HandlerCollection();
    handlerCollection.setHandlers(new Handler[] { statisticsHandler, requestLogHandler });
    return handlerCollection;
}
Also used : GzipHandler(org.eclipse.jetty.server.handler.gzip.GzipHandler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) DispatcherType(javax.servlet.DispatcherType) StatisticsHandler(org.eclipse.jetty.server.handler.StatisticsHandler)

Example 23 with StatisticsHandler

use of org.eclipse.jetty.server.handler.StatisticsHandler in project vespa by vespa-engine.

the class JettyHttpServer method newStatisticsHandler.

private StatisticsHandler newStatisticsHandler() {
    StatisticsHandler statisticsHandler = new StatisticsHandler();
    statisticsHandler.statsReset();
    return statisticsHandler;
}
Also used : StatisticsHandler(org.eclipse.jetty.server.handler.StatisticsHandler)

Example 24 with StatisticsHandler

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

the class JettyServletWebServerFactory method getWebServer.

@Override
public WebServer getWebServer(ServletContextInitializer... initializers) {
    JettyEmbeddedWebAppContext context = new JettyEmbeddedWebAppContext();
    int port = Math.max(getPort(), 0);
    InetSocketAddress address = new InetSocketAddress(getAddress(), port);
    Server server = createServer(address);
    configureWebAppContext(context, initializers);
    server.setHandler(addHandlerWrappers(context));
    this.logger.info("Server initialized with port: " + port);
    if (getSsl() != null && getSsl().isEnabled()) {
        customizeSsl(server, address);
    }
    for (JettyServerCustomizer customizer : getServerCustomizers()) {
        customizer.customize(server);
    }
    if (this.useForwardHeaders) {
        new ForwardHeadersCustomizer().customize(server);
    }
    if (getShutdown() == Shutdown.GRACEFUL) {
        StatisticsHandler statisticsHandler = new StatisticsHandler();
        statisticsHandler.setHandler(server.getHandler());
        server.setHandler(statisticsHandler);
    }
    return getJettyWebServer(server);
}
Also used : Server(org.eclipse.jetty.server.Server) WebServer(org.springframework.boot.web.server.WebServer) InetSocketAddress(java.net.InetSocketAddress) StatisticsHandler(org.eclipse.jetty.server.handler.StatisticsHandler)

Aggregations

StatisticsHandler (org.eclipse.jetty.server.handler.StatisticsHandler)24 Server (org.eclipse.jetty.server.Server)10 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)10 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)9 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)8 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)8 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)7 IOException (java.io.IOException)5 ServerConnector (org.eclipse.jetty.server.ServerConnector)5 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)4 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)4 Test (org.junit.Test)4 Socket (java.net.Socket)3 ConnectException (org.apache.kafka.connect.errors.ConnectException)3 Handler (org.eclipse.jetty.server.Handler)3 Slf4jRequestLog (org.eclipse.jetty.server.Slf4jRequestLog)3 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)3 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)3 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)3 Unirest (com.mashape.unirest.http.Unirest)2