use of org.apache.knox.gateway.filter.PortMappingHelperHandler 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;
}
Aggregations