Search in sources :

Example 11 with NCSARequestLog

use of org.eclipse.jetty.server.NCSARequestLog in project scheduling by ow2-proactive.

the class JettyStarter method deployWebApplications.

public List<String> deployWebApplications(String rmUrl, String schedulerUrl) {
    initializeRestProperties();
    setSystemPropertyIfNotDefined("rm.url", rmUrl);
    setSystemPropertyIfNotDefined("scheduler.url", schedulerUrl);
    System.setProperty(CentralPAPropertyRepository.JAVAX_XML_TRANSFORM_TRANSFORMERFACTORY.getName(), DEFAULT_XML_TRANSFORMER);
    if (WebProperties.WEB_DEPLOY.getValueAsBoolean()) {
        logger.info("Starting the web applications...");
        int httpPort = getJettyHttpPort();
        int httpsPort = 443;
        if (WebProperties.WEB_HTTPS_PORT.isSet()) {
            httpsPort = WebProperties.WEB_HTTPS_PORT.getValueAsInt();
        }
        boolean httpsEnabled = WebProperties.WEB_HTTPS.getValueAsBoolean();
        boolean redirectHttpToHttps = WebProperties.WEB_REDIRECT_HTTP_TO_HTTPS.getValueAsBoolean();
        int restPort = httpPort;
        String httpProtocol;
        String[] defaultVirtualHost;
        String[] httpVirtualHost = new String[] { "@" + HTTP_CONNECTOR_NAME };
        if (httpsEnabled) {
            httpProtocol = "https";
            defaultVirtualHost = new String[] { "@" + HTTPS_CONNECTOR_NAME };
            restPort = httpsPort;
        } else {
            defaultVirtualHost = httpVirtualHost;
            httpProtocol = "http";
        }
        Server server = createHttpServer(httpPort, httpsPort, httpsEnabled, redirectHttpToHttps);
        server.setStopAtShutdown(true);
        HandlerList topLevelHandlerList = new HandlerList();
        if (httpsEnabled && redirectHttpToHttps) {
            ContextHandler redirectHandler = new ContextHandler();
            redirectHandler.setContextPath("/");
            redirectHandler.setHandler(new SecuredRedirectHandler());
            redirectHandler.setVirtualHosts(httpVirtualHost);
            topLevelHandlerList.addHandler(redirectHandler);
        }
        topLevelHandlerList.addHandler(createSecurityHeadersHandler());
        if (WebProperties.JETTY_LOG_FILE.isSet()) {
            String pathToJettyLogFile = FileStorageSupportFactory.relativeToHomeIfNotAbsolute(WebProperties.JETTY_LOG_FILE.getValueAsString());
            File jettyLogFile = new File(pathToJettyLogFile);
            if (!jettyLogFile.getParentFile().exists() && !jettyLogFile.getParentFile().mkdirs()) {
                logger.error("Could not create jetty log file in: " + WebProperties.JETTY_LOG_FILE.getValueAsString());
            } else {
                NCSARequestLog requestLog = new NCSARequestLog(pathToJettyLogFile);
                requestLog.setAppend(true);
                requestLog.setExtended(false);
                requestLog.setLogTimeZone("GMT");
                requestLog.setLogLatency(true);
                requestLog.setRetainDays(WebProperties.JETTY_LOG_RETAIN_DAYS.getValueAsInt());
                RequestLogHandler requestLogHandler = new RequestLogHandler();
                requestLogHandler.setRequestLog(requestLog);
                topLevelHandlerList.addHandler(requestLogHandler);
            }
        }
        RewriteHandler rewriteHandler = null;
        HandlerList contextHandlerList = null;
        if (WebProperties.WEB_PCA_PROXY_REWRITE_ENABLED.getValueAsBoolean()) {
            rewriteHandler = new RewriteHandler();
            PCAProxyRule proxyRule = new PCAProxyRule();
            rewriteHandler.addRule(proxyRule);
            rewriteHandler.setRewriteRequestURI(true);
            rewriteHandler.setRewritePathInfo(false);
            rewriteHandler.setOriginalPathAttribute(PCAProxyRule.originalPathAttribute);
            rewriteHandler.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
            contextHandlerList = new HandlerList();
        } else {
            contextHandlerList = topLevelHandlerList;
        }
        addWarsToHandlerList(contextHandlerList, defaultVirtualHost);
        if (WebProperties.WEB_PCA_PROXY_REWRITE_ENABLED.getValueAsBoolean()) {
            rewriteHandler.setHandler(contextHandlerList);
            topLevelHandlerList.addHandler(rewriteHandler);
        }
        server.setHandler(topLevelHandlerList);
        if (logger.isDebugEnabled()) {
            server.setDumpAfterStart(true);
        }
        String schedulerHost = ProActiveInet.getInstance().getHostname();
        return startServer(server, schedulerHost, restPort, httpProtocol);
    }
    return new ArrayList<>();
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) Server(org.eclipse.jetty.server.Server) SecuredRedirectHandler(org.eclipse.jetty.server.handler.SecuredRedirectHandler) ArrayList(java.util.ArrayList) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) NCSARequestLog(org.eclipse.jetty.server.NCSARequestLog) File(java.io.File) RewriteHandler(org.eclipse.jetty.rewrite.handler.RewriteHandler)

Example 12 with NCSARequestLog

use of org.eclipse.jetty.server.NCSARequestLog in project killbill by killbill.

the class HttpServer method createLogHandler.

private RequestLogHandler createLogHandler(final HttpServerConfig config) {
    final RequestLogHandler logHandler = new RequestLogHandler();
    final RequestLog requestLog = new NCSARequestLog(config.getLogPath());
    logHandler.setRequestLog(requestLog);
    return logHandler;
}
Also used : NCSARequestLog(org.eclipse.jetty.server.NCSARequestLog) RequestLog(org.eclipse.jetty.server.RequestLog) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) NCSARequestLog(org.eclipse.jetty.server.NCSARequestLog)

Aggregations

NCSARequestLog (org.eclipse.jetty.server.NCSARequestLog)12 File (java.io.File)9 Server (org.eclipse.jetty.server.Server)8 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)7 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)5 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)5 ServerConnector (org.eclipse.jetty.server.ServerConnector)4 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)4 ArrayList (java.util.ArrayList)3 HashLoginService (org.eclipse.jetty.security.HashLoginService)3 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)3 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)3 MBeanContainer (org.eclipse.jetty.jmx.MBeanContainer)2 RewriteHandler (org.eclipse.jetty.rewrite.handler.RewriteHandler)2 AbstractConnector (org.eclipse.jetty.server.AbstractConnector)2 Connector (org.eclipse.jetty.server.Connector)2 Handler (org.eclipse.jetty.server.Handler)2 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)2 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)2 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)2