use of org.apache.knox.gateway.trace.TraceHandler 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) {
final Map<String, Handler> contextToHandlerMap = new HashMap<>();
if (contexts.getHandlers() != null) {
Arrays.asList(contexts.getHandlers()).stream().filter(h -> h instanceof WebAppContext).forEach(h -> contextToHandlerMap.put(((WebAppContext) h).getContextPath(), h));
}
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);
// Used to correct the {target} part of request with Topology Port Mapping feature
final PortMappingHelperHandler portMappingHandler = new PortMappingHelperHandler(config);
portMappingHandler.setHandler(correlationHandler);
if (config.isGatewayPortMappingEnabled()) {
/* Do the virtual host bindings for all the defined topology port mapped
* contexts except for the one that has gateway port to prevent issues
* with context deployment */
topologyPortMap.entrySet().stream().filter(e -> !e.getValue().equals(config.getGatewayPort())).forEach(entry -> {
log.createJettyHandler(entry.getKey());
final Handler context = contextToHandlerMap.get("/" + config.getGatewayPath() + "/" + entry.getKey());
if (context != null) {
((WebAppContext) context).setVirtualHosts(new String[] { "@" + entry.getKey().toLowerCase(Locale.ROOT) });
} else {
// no topology found for mapping entry.getKey()
log.noMappedTopologyFound(entry.getKey());
}
});
}
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;
}
Aggregations