use of org.eclipse.jetty.server.handler.RequestLogHandler in project airlift by airlift.
the class HttpServer method createLogHandler.
private static RequestLogHandler createLogHandler(HttpServerConfig config, TraceTokenManager tokenManager, EventClient eventClient) throws IOException {
// TODO: use custom (more easily-parseable) format
// TODO: make retention & rotation configurable
RequestLogHandler logHandler = new RequestLogHandler();
File logFile = new File(config.getLogPath());
if (logFile.exists() && !logFile.isFile()) {
throw new IOException(format("Log path %s exists but is not a file", logFile.getAbsolutePath()));
}
File logPath = logFile.getParentFile();
if (!logPath.mkdirs() && !logPath.exists()) {
throw new IOException(format("Cannot create %s and path does not already exist", logPath.getAbsolutePath()));
}
RequestLog requestLog = new DelimitedRequestLog(config.getLogPath(), config.getLogHistory(), config.getLogQueueSize(), config.getLogMaxFileSize().toBytes(), tokenManager, eventClient, config.isLogCompressionEnabled());
logHandler.setRequestLog(requestLog);
return logHandler;
}
use of org.eclipse.jetty.server.handler.RequestLogHandler in project athenz by yahoo.
the class AthenzJettyContainerTest method testRequestLogHandler.
@Test
public void testRequestLogHandler() {
System.setProperty(AthenzConsts.ATHENZ_PROP_ACCESS_LOG_RETAIN_DAYS, "3");
System.setProperty(AthenzConsts.ATHENZ_PROP_MAX_THREADS, "100");
AthenzJettyContainer container = new AthenzJettyContainer();
container.createServer(100);
container.addRequestLogHandler();
// now retrieve the request log handler
Handler[] handlers = container.getHandlers().getHandlers();
RequestLogHandler logHandler = null;
for (Handler handler : handlers) {
if (handler instanceof RequestLogHandler) {
logHandler = (RequestLogHandler) handler;
break;
}
}
assertNotNull(logHandler);
RequestLog reqLog = logHandler.getRequestLog();
assertNotNull(reqLog);
assertEquals(reqLog.getClass(), AthenzRequestLog.class);
}
use of org.eclipse.jetty.server.handler.RequestLogHandler in project knox by apache.
the class GatewayServer method createHandlers.
private static HandlerCollection createHandlers(final GatewayConfig config, final GatewayServices services, final ContextHandlerCollection contexts, final Map<String, Integer> topologyPortMap) {
HandlerCollection handlers = new HandlerCollection();
RequestLogHandler logHandler = new RequestLogHandler();
logHandler.setRequestLog(new AccessHandler());
TraceHandler traceHandler = new TraceHandler();
traceHandler.setHandler(contexts);
traceHandler.setTracedBodyFilter(System.getProperty("org.apache.knox.gateway.trace.body.status.filter"));
CorrelationHandler correlationHandler = new CorrelationHandler();
correlationHandler.setHandler(traceHandler);
/* KNOX-732: Handler for GZip compression */
GzipHandler gzipHandler = new GzipHandler();
String[] mimeTypes = {};
if (config.getMimeTypesToCompress() != null && !config.getMimeTypesToCompress().isEmpty()) {
mimeTypes = (String[]) config.getMimeTypesToCompress().toArray();
}
gzipHandler.addIncludedMimeTypes(mimeTypes);
gzipHandler.setHandler(correlationHandler);
// Used to correct the {target} part of request with Topology Port Mapping feature
final PortMappingHelperHandler portMappingHandler = new PortMappingHelperHandler(config);
portMappingHandler.setHandler(gzipHandler);
if (config.isGatewayPortMappingEnabled()) {
for (final Map.Entry<String, Integer> entry : topologyPortMap.entrySet()) {
log.createJettyHandler(entry.getKey());
final ContextHandler topologyContextHandler = new ContextHandler();
final RequestUpdateHandler updateHandler = new RequestUpdateHandler(config, entry.getKey(), services);
topologyContextHandler.setHandler(updateHandler);
topologyContextHandler.setVirtualHosts(new String[] { "@" + entry.getKey().toLowerCase() });
handlers.addHandler(topologyContextHandler);
}
}
handlers.addHandler(logHandler);
if (config.isWebsocketEnabled()) {
final GatewayWebsocketHandler websocketHandler = new GatewayWebsocketHandler(config, services);
websocketHandler.setHandler(portMappingHandler);
handlers.addHandler(websocketHandler);
} else {
handlers.addHandler(portMappingHandler);
}
return handlers;
}
use of org.eclipse.jetty.server.handler.RequestLogHandler in project apache-kafka-on-k8s by banzaicloud.
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();
Slf4jRequestLog requestLog = new Slf4jRequestLog();
requestLog.setLoggerName(JsonRestServer.class.getCanonicalName());
requestLog.setLogLatency(true);
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());
}
use of org.eclipse.jetty.server.handler.RequestLogHandler in project apache-kafka-on-k8s by banzaicloud.
the class RestServer method start.
public void start(Herder herder) {
log.info("Starting REST server");
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.register(new JacksonJsonProvider());
resourceConfig.register(new RootResource(herder));
resourceConfig.register(new ConnectorsResource(herder, config));
resourceConfig.register(new ConnectorPluginsResource(herder));
resourceConfig.register(ConnectExceptionMapper.class);
ServletContainer servletContainer = new ServletContainer(resourceConfig);
ServletHolder servletHolder = new ServletHolder(servletContainer);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.addServlet(servletHolder, "/*");
String allowedOrigins = config.getString(WorkerConfig.ACCESS_CONTROL_ALLOW_ORIGIN_CONFIG);
if (allowedOrigins != null && !allowedOrigins.trim().isEmpty()) {
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
filterHolder.setName("cross-origin");
filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, allowedOrigins);
String allowedMethods = config.getString(WorkerConfig.ACCESS_CONTROL_ALLOW_METHODS_CONFIG);
if (allowedMethods != null && !allowedOrigins.trim().isEmpty()) {
filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, allowedMethods);
}
context.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
}
RequestLogHandler requestLogHandler = new RequestLogHandler();
Slf4jRequestLog requestLog = new Slf4jRequestLog();
requestLog.setLoggerName(RestServer.class.getCanonicalName());
requestLog.setLogLatency(true);
requestLogHandler.setRequestLog(requestLog);
HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers(new Handler[] { context, new DefaultHandler(), requestLogHandler });
/* Needed for graceful shutdown as per `setStopTimeout` documentation */
StatisticsHandler statsHandler = new StatisticsHandler();
statsHandler.setHandler(handlers);
jettyServer.setHandler(statsHandler);
jettyServer.setStopTimeout(GRACEFUL_SHUTDOWN_TIMEOUT_MS);
jettyServer.setStopAtShutdown(true);
try {
jettyServer.start();
} catch (Exception e) {
throw new ConnectException("Unable to start REST server", e);
}
log.info("REST server listening at " + jettyServer.getURI() + ", advertising URL " + advertisedUrl());
}
Aggregations