Search in sources :

Example 6 with LowResourceMonitor

use of org.eclipse.jetty.server.LowResourceMonitor in project hive by apache.

the class HttpServer method initializeWebServer.

private void initializeWebServer(final Builder b, int queueSize) throws IOException {
    // Set handling for low resource conditions.
    final LowResourceMonitor low = new LowResourceMonitor(webServer);
    low.setLowResourcesIdleTimeout(10000);
    webServer.addBean(low);
    Connector connector = createChannelConnector(queueSize, b);
    webServer.addConnector(connector);
    RewriteHandler rwHandler = new RewriteHandler();
    rwHandler.setRewriteRequestURI(true);
    rwHandler.setRewritePathInfo(false);
    RewriteRegexRule rootRule = new RewriteRegexRule();
    rootRule.setRegex("^/$");
    rootRule.setReplacement(b.contextRootRewriteTarget);
    rootRule.setTerminating(true);
    rwHandler.addRule(rootRule);
    rwHandler.setHandler(webAppContext);
    // Configure web application contexts for the web server
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    contexts.addHandler(rwHandler);
    webServer.setHandler(contexts);
    if (b.usePAM) {
        setupPam(b, contexts);
    }
    addServlet("jmx", "/jmx", JMXJsonServlet.class);
    addServlet("conf", "/conf", ConfServlet.class);
    addServlet("stacks", "/stacks", StackServlet.class);
    addServlet("conflog", "/conflog", Log4j2ConfiguratorServlet.class);
    final String asyncProfilerHome = ProfileServlet.getAsyncProfilerHome();
    if (asyncProfilerHome != null && !asyncProfilerHome.trim().isEmpty()) {
        addServlet("prof", "/prof", ProfileServlet.class);
        Path tmpDir = Paths.get(ProfileServlet.OUTPUT_DIR);
        if (Files.notExists(tmpDir)) {
            Files.createDirectories(tmpDir);
        }
        ServletContextHandler genCtx = new ServletContextHandler(contexts, "/prof-output");
        setContextAttributes(genCtx.getServletContext(), b.contextAttrs);
        genCtx.addServlet(ProfileOutputServlet.class, "/*");
        genCtx.setResourceBase(tmpDir.toAbsolutePath().toString());
        genCtx.setDisplayName("prof-output");
    } else {
        LOG.info("ASYNC_PROFILER_HOME env or -Dasync.profiler.home not specified. Disabling /prof endpoint..");
    }
    for (Pair<String, Class<? extends HttpServlet>> p : b.servlets) {
        addServlet(p.getFirst(), "/" + p.getFirst(), p.getSecond());
    }
    ServletContextHandler staticCtx = new ServletContextHandler(contexts, "/static");
    staticCtx.setResourceBase(appDir + "/static");
    staticCtx.addServlet(DefaultServlet.class, "/*");
    staticCtx.setDisplayName("static");
    disableDirectoryListingOnServlet(staticCtx);
    String logDir = getLogDir(b.conf);
    if (logDir != null) {
        ServletContextHandler logCtx = new ServletContextHandler(contexts, "/logs");
        setContextAttributes(logCtx.getServletContext(), b.contextAttrs);
        if (b.useSPNEGO) {
            setupSpnegoFilter(b, logCtx);
        }
        logCtx.addServlet(AdminAuthorizedServlet.class, "/*");
        logCtx.setResourceBase(logDir);
        logCtx.setDisplayName("logs");
    }
}
Also used : Path(java.nio.file.Path) ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) RewriteRegexRule(org.eclipse.jetty.rewrite.handler.RewriteRegexRule) HttpServlet(javax.servlet.http.HttpServlet) LowResourceMonitor(org.eclipse.jetty.server.LowResourceMonitor) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) RewriteHandler(org.eclipse.jetty.rewrite.handler.RewriteHandler)

Aggregations

LowResourceMonitor (org.eclipse.jetty.server.LowResourceMonitor)6 ServerConnector (org.eclipse.jetty.server.ServerConnector)3 RewriteHandler (org.eclipse.jetty.rewrite.handler.RewriteHandler)2 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)2 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)2 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)2 Server (org.eclipse.jetty.server.Server)2 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)2 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)2 ServletContainer (com.sun.jersey.spi.container.servlet.ServletContainer)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 Path (java.nio.file.Path)1 DispatcherType (javax.servlet.DispatcherType)1 HttpServlet (javax.servlet.http.HttpServlet)1 DeploymentManager (org.eclipse.jetty.deploy.DeploymentManager)1 PropertiesConfigurationManager (org.eclipse.jetty.deploy.PropertiesConfigurationManager)1