org.eclipse.jetty.server.NCSARequestLog Java Examples
The following examples show how to use
org.eclipse.jetty.server.NCSARequestLog.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KafkaCruiseControlApp.java From cruise-control with BSD 2-Clause "Simplified" License | 6 votes |
private NCSARequestLog createRequestLog() { boolean accessLogEnabled = _config.getBoolean(WebServerConfig.WEBSERVER_ACCESSLOG_ENABLED_CONFIG); if (accessLogEnabled) { String accessLogPath = _config.getString(WebServerConfig.WEBSERVER_ACCESSLOG_PATH_CONFIG); int accessLogRetention = _config.getInt(WebServerConfig.WEBSERVER_ACCESSLOG_RETENTION_DAYS_CONFIG); NCSARequestLog requestLog = new NCSARequestLog(accessLogPath); requestLog.setRetainDays(accessLogRetention); requestLog.setLogLatency(true); requestLog.setAppend(true); requestLog.setExtended(false); requestLog.setPreferProxiedForAddress(true); return requestLog; } else { return null; } }
Example #2
Source File: LogSearchWebServerCustomizer.java From ambari-logsearch with Apache License 2.0 | 5 votes |
@Override public void customize(JettyServletWebServerFactory webServerFactory) { serverProperties.getServlet().getSession().setTimeout(Duration.ofMinutes(logSearchHttpConfig.getSessionTimeout())); serverProperties.getServlet().getSession().getCookie().setName(LOGSEARCH_SESSION_ID); if ("https".equals(logSearchHttpConfig.getProtocol())) { sslConfigurer.ensureStorePasswords(); sslConfigurer.loadKeystore(); webServerFactory.addServerCustomizers((JettyServerCustomizer) server -> { SslContextFactory sslContextFactory = sslConfigurer.getSslContextFactory(); ServerConnector sslConnector = new ServerConnector(server, sslContextFactory); sslConnector.setPort(logSearchHttpConfig.getHttpsPort()); server.setConnectors(new Connector[]{sslConnector}); }); } else { webServerFactory.setPort(logSearchHttpConfig.getHttpPort()); } if (logSearchHttpConfig.isUseAccessLogs()) { webServerFactory.addServerCustomizers((JettyServerCustomizer) server -> { LoggerContext context = (LoggerContext) LogManager.getContext(false); Configuration configuration = context.getConfiguration(); String logDir = configuration.getStrSubstitutor().getVariableResolver().lookup("log-path"); String logFileNameSuffix = "logsearch-jetty-yyyy_mm_dd.request.log"; String logFileName = logDir == null ? logFileNameSuffix : Paths.get(logDir, logFileNameSuffix).toString(); NCSARequestLog requestLog = new NCSARequestLog(logFileName); requestLog.setAppend(true); requestLog.setExtended(false); requestLog.setLogTimeZone("GMT"); server.setRequestLog(requestLog); }); } }
Example #3
Source File: KafkaCruiseControlApp.java From cruise-control with BSD 2-Clause "Simplified" License | 5 votes |
KafkaCruiseControlApp(KafkaCruiseControlConfig config, Integer port, String hostname) throws ServletException { this._config = config; MetricRegistry metricRegistry = new MetricRegistry(); _jmxReporter = JmxReporter.forRegistry(metricRegistry).inDomain(METRIC_DOMAIN).build(); _jmxReporter.start(); _kafkaCruiseControl = new AsyncKafkaCruiseControl(config, metricRegistry); _server = new Server(); NCSARequestLog requestLog = createRequestLog(); if (requestLog != null) { _server.setRequestLog(requestLog); } _server.setConnectors(new Connector[]{ setupHttpConnector(hostname, port) }); ServletContextHandler contextHandler = createContextHandler(); maybeSetSecurityHandler(contextHandler); _server.setHandler(contextHandler); setupWebUi(contextHandler); KafkaCruiseControlServlet servlet = new KafkaCruiseControlServlet(_kafkaCruiseControl, metricRegistry); String apiUrlPrefix = config.getString(WebServerConfig.WEBSERVER_API_URLPREFIX_CONFIG); ServletHolder servletHolder = new ServletHolder(servlet); contextHandler.addServlet(servletHolder, apiUrlPrefix); }
Example #4
Source File: MinimalServletsWithLogging.java From cs601 with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void main(String[] args) throws Exception { // Create a basic jetty server object that will listen on port 8080. Note that if you set this to port 0 // then a randomly available port will be assigned that you can either look in the logs for the port, // or programmatically obtain it for use in test cases. Server server = new Server(8080); HandlerCollection handlers = new HandlerCollection(); server.setHandler(handlers); ServletHandler servlet = new ServletHandler(); servlet.addServletWithMapping(HelloServlet.class, "/*"); handlers.addHandler(servlet); handlers.addHandler(new DefaultHandler()); // must be after servlet it seems // log using NCSA (common log format) // http://en.wikipedia.org/wiki/Common_Log_Format NCSARequestLog requestLog = new NCSARequestLog(); requestLog.setFilename("/tmp/yyyy_mm_dd.request.log"); requestLog.setFilenameDateFormat("yyyy_MM_dd"); requestLog.setRetainDays(90); requestLog.setAppend(true); requestLog.setExtended(true); requestLog.setLogCookies(false); requestLog.setLogTimeZone("GMT"); RequestLogHandler requestLogHandler = new RequestLogHandler(); requestLogHandler.setRequestLog(requestLog); handlers.addHandler(requestLogHandler); // Start things up! By using the server.join() the server thread will join with the current thread. // See "http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()" for more details. server.start(); server.join(); }
Example #5
Source File: ServerDaemon.java From cloudstack with Apache License 2.0 | 5 votes |
private RequestLog createRequestLog() { final NCSARequestLog log = new NCSARequestLog(); final File logPath = new File(accessLogFile); final File parentFile = logPath.getParentFile(); if (parentFile != null) { parentFile.mkdirs(); } log.setFilename(logPath.getPath()); log.setAppend(true); log.setLogTimeZone("GMT"); log.setLogLatency(true); return log; }
Example #6
Source File: JettyStarter.java From scheduling with GNU Affero General Public License v3.0 | 4 votes |
public List<String> deployWebApplications(String rmUrl, String schedulerUrl) { initializeRestProperties(); setSystemPropertyIfNotDefined("rm.url", rmUrl); setSystemPropertyIfNotDefined("scheduler.url", schedulerUrl); 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 handlerList = new HandlerList(); 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); handlerList.addHandler(requestLogHandler); } } if (httpsEnabled && redirectHttpToHttps) { ContextHandler redirectHandler = new ContextHandler(); redirectHandler.setContextPath("/"); redirectHandler.setHandler(new SecuredRedirectHandler()); redirectHandler.setVirtualHosts(httpVirtualHost); handlerList.addHandler(redirectHandler); } addWarsToHandlerList(handlerList, defaultVirtualHost); server.setHandler(handlerList); String schedulerHost = ProActiveInet.getInstance().getHostname(); return startServer(server, schedulerHost, restPort, httpProtocol); } return new ArrayList<>(); }