Search in sources :

Example 1 with HealthServlet

use of com.kixeye.chassis.transport.shared.HealthServlet in project chassis by Kixeye.

the class HttpTransportConfiguration method httpServer.

@Bean(initMethod = "start", destroyMethod = "stop")
@Order(0)
public Server httpServer(@Value("${http.enabled:false}") boolean httpEnabled, @Value("${http.hostname:}") String httpHostname, @Value("${http.port:-1}") int httpPort, @Value("${https.enabled:false}") boolean httpsEnabled, @Value("${https.hostname:}") String httpsHostname, @Value("${https.port:-1}") int httpsPort, @Value("${https.selfSigned:false}") boolean selfSigned, @Value("${https.mutualSsl:false}") boolean mutualSsl, @Value("${https.keyStorePath:}") String keyStorePath, @Value("${https.keyStoreData:}") String keyStoreData, @Value("${https.keyStorePassword:}") String keyStorePassword, @Value("${https.keyManagerPassword:}") String keyManagerPassword, @Value("${https.trustStorePath:}") String trustStorePath, @Value("${https.trustStoreData:}") String trustStoreData, @Value("${https.trustStorePassword:}") String trustStorePassword, @Value("${https.excludedCipherSuites:}") String[] excludedCipherSuites, ConfigurableWebApplicationContext webApplicationContext) throws Exception {
    // set up servlets
    ServletContextHandler context = servletContextHandler();
    // create a new child application context
    AnnotationConfigWebApplicationContext childApplicationContext = (AnnotationConfigWebApplicationContext) transportWebMvcContext(webApplicationContext, context).getContext();
    // register swagger
    childApplicationContext.getBean(SwaggerRegistry.class).registerSwagger(context, getObjectMappers(webApplicationContext));
    // configure the spring mvc dispatcher
    DispatcherServlet dispatcher = new DispatcherServlet(childApplicationContext);
    // enable gzip
    context.addFilter(GzipFilter.class, "/*", null);
    // map application servlets
    context.addServlet(new ServletHolder(dispatcher), "/");
    if (healthCheckRegistry != null) {
        context.addServlet(new ServletHolder(new HealthServlet(healthCheckRegistry)), "/healthcheck");
    }
    // create the server
    Server server;
    if (metricRegistry == null || !monitorThreadpool) {
        server = new Server();
        server.setHandler(context);
    } else {
        server = new Server(new InstrumentedQueuedThreadPool(metricRegistry));
        InstrumentedHandler instrumented = new InstrumentedHandler(metricRegistry);
        instrumented.setHandler(context);
        server.setHandler(instrumented);
    }
    // set up connectors
    if (httpEnabled) {
        InetSocketAddress address = StringUtils.isBlank(httpHostname) ? new InetSocketAddress(httpPort) : new InetSocketAddress(httpHostname, httpPort);
        JettyConnectorRegistry.registerHttpConnector(server, address);
    }
    if (httpsEnabled) {
        InetSocketAddress address = StringUtils.isBlank(httpsHostname) ? new InetSocketAddress(httpsPort) : new InetSocketAddress(httpsHostname, httpsPort);
        JettyConnectorRegistry.registerHttpsConnector(server, address, selfSigned, mutualSsl, keyStorePath, keyStoreData, keyStorePassword, keyManagerPassword, trustStorePath, trustStoreData, trustStorePassword, excludedCipherSuites);
    }
    return server;
}
Also used : InstrumentedQueuedThreadPool(com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool) Server(org.eclipse.jetty.server.Server) HealthServlet(com.kixeye.chassis.transport.shared.HealthServlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) InetSocketAddress(java.net.InetSocketAddress) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) SwaggerRegistry(com.kixeye.chassis.transport.swagger.SwaggerRegistry) Order(org.springframework.core.annotation.Order) Bean(org.springframework.context.annotation.Bean)

Example 2 with HealthServlet

use of com.kixeye.chassis.transport.shared.HealthServlet in project chassis by Kixeye.

the class AdminTransportConfiguration method adminServer.

@Bean(initMethod = "start", destroyMethod = "stop")
@Order(0)
public Server adminServer(@Value("${admin.hostname}") String hostname, @Value("${admin.port}") int port) {
    // set up servlets
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY);
    context.setErrorHandler(null);
    context.setWelcomeFiles(new String[] { "/" });
    // enable gzip
    context.addFilter(GzipFilter.class, "/*", null);
    // add common admin servlets
    context.addServlet(new ServletHolder(new HealthServlet(healthCheckRegistry)), "/healthcheck");
    context.addServlet(new ServletHolder(new ClasspathResourceServlet("com/kixeye/chassis/transport/admin", "/admin/", "index.html")), "/admin/*");
    context.addServlet(new ServletHolder(new PropertiesServlet()), "/admin/properties");
    context.addServlet(new ServletHolder(new ClasspathDumpServlet()), "/admin/classpath");
    // add websocket servlets if WebSockets have been initialized
    if (mappingRegistry != null && messageRegistry != null) {
        context.addServlet(new ServletHolder(new ProtobufMessagesDocumentationServlet(appName, mappingRegistry, messageRegistry)), "/schema/messages/protobuf");
        context.addServlet(new ServletHolder(new ProtobufEnvelopeDocumentationServlet()), "/schema/envelope/protobuf");
    }
    // add metric servlets if Metric has been initialized
    if (metricRegistry != null && healthCheckRegistry != null) {
        context.getServletContext().setAttribute(MetricsServlet.METRICS_REGISTRY, metricRegistry);
        context.getServletContext().setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, healthCheckRegistry);
        ServletHolder holder = new ServletHolder(new AdminServlet());
        holder.setInitParameter("service-name", System.getProperty("app.name"));
        context.addServlet(holder, "/metrics/*");
    }
    // create the server
    InetSocketAddress address = StringUtils.isBlank(hostname) ? new InetSocketAddress(port) : new InetSocketAddress(hostname, port);
    Server server = new Server();
    JettyConnectorRegistry.registerHttpConnector(server, address);
    server.setHandler(context);
    return server;
}
Also used : AdminServlet(com.codahale.metrics.servlets.AdminServlet) PropertiesServlet(com.kixeye.chassis.transport.shared.PropertiesServlet) Server(org.eclipse.jetty.server.Server) HealthServlet(com.kixeye.chassis.transport.shared.HealthServlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ProtobufMessagesDocumentationServlet(com.kixeye.chassis.transport.websocket.docs.ProtobufMessagesDocumentationServlet) InetSocketAddress(java.net.InetSocketAddress) ClasspathDumpServlet(com.kixeye.chassis.transport.shared.ClasspathDumpServlet) ProtobufEnvelopeDocumentationServlet(com.kixeye.chassis.transport.websocket.docs.ProtobufEnvelopeDocumentationServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ClasspathResourceServlet(com.kixeye.chassis.transport.shared.ClasspathResourceServlet) Order(org.springframework.core.annotation.Order) Bean(org.springframework.context.annotation.Bean)

Aggregations

HealthServlet (com.kixeye.chassis.transport.shared.HealthServlet)2 InetSocketAddress (java.net.InetSocketAddress)2 Server (org.eclipse.jetty.server.Server)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 Bean (org.springframework.context.annotation.Bean)2 Order (org.springframework.core.annotation.Order)2 InstrumentedQueuedThreadPool (com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool)1 AdminServlet (com.codahale.metrics.servlets.AdminServlet)1 ClasspathDumpServlet (com.kixeye.chassis.transport.shared.ClasspathDumpServlet)1 ClasspathResourceServlet (com.kixeye.chassis.transport.shared.ClasspathResourceServlet)1 PropertiesServlet (com.kixeye.chassis.transport.shared.PropertiesServlet)1 SwaggerRegistry (com.kixeye.chassis.transport.swagger.SwaggerRegistry)1 ProtobufEnvelopeDocumentationServlet (com.kixeye.chassis.transport.websocket.docs.ProtobufEnvelopeDocumentationServlet)1 ProtobufMessagesDocumentationServlet (com.kixeye.chassis.transport.websocket.docs.ProtobufMessagesDocumentationServlet)1 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)1 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)1