use of org.eclipse.jetty.server.handler.ContextHandler 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.ContextHandler in project knox by apache.
the class BadBackendTest method startProxy.
private static void startProxy() throws Exception {
proxy = new Server();
proxyConnector = new ServerConnector(proxy);
proxy.addConnector(proxyConnector);
/* start Knox with WebsocketAdapter to test */
final BigEchoSocketHandler wsHandler = new BigEchoSocketHandler(new ProxyWebSocketAdapter(new URI(BAD_BACKEND), Executors.newFixedThreadPool(10)));
ContextHandler context = new ContextHandler();
context.setContextPath("/");
context.setHandler(wsHandler);
proxy.setHandler(context);
// Start Server
proxy.start();
String host = proxyConnector.getHost();
if (host == null) {
host = "localhost";
}
int port = proxyConnector.getLocalPort();
proxyUri = new URI(String.format("ws://%s:%d/", host, port));
}
use of org.eclipse.jetty.server.handler.ContextHandler in project knox by apache.
the class GatewayPortMappingConfigTest method startGatewayServer.
private static void startGatewayServer() throws Exception {
// use default Max threads
gatewayServer = new Server(defaultPort);
final ServerConnector connector = new ServerConnector(gatewayServer);
gatewayServer.addConnector(connector);
// workaround so we can add our handler later at runtime
HandlerCollection handlers = new HandlerCollection(true);
// add some initial handlers
ContextHandler context = new ContextHandler();
context.setContextPath("/");
handlers.addHandler(context);
gatewayServer.setHandler(handlers);
// Start Server
gatewayServer.start();
}
use of org.eclipse.jetty.server.handler.ContextHandler in project knox by apache.
the class BigEchoSocketHandler method startProxy.
private static void startProxy() throws Exception {
proxy = new Server();
proxyConnector = new ServerConnector(proxy);
proxy.addConnector(proxyConnector);
/* start Knox with WebsocketAdapter to test */
final BigEchoSocketHandler wsHandler = new BigEchoSocketHandler(new ProxyWebSocketAdapter(serverUri, Executors.newFixedThreadPool(10)));
ContextHandler context = new ContextHandler();
context.setContextPath("/");
context.setHandler(wsHandler);
proxy.setHandler(context);
// Start Server
proxy.start();
String host = proxyConnector.getHost();
if (host == null) {
host = "localhost";
}
int port = proxyConnector.getLocalPort();
proxyUri = new URI(String.format("ws://%s:%d/", host, port));
}
use of org.eclipse.jetty.server.handler.ContextHandler in project knox by apache.
the class ProxyInboundClientTest method startWSServer.
@BeforeClass
public static void startWSServer() throws Exception {
server = new Server();
ServerConnector connector = new ServerConnector(server);
server.addConnector(connector);
handler = new WebsocketEchoHandler();
ContextHandler context = new ContextHandler();
context.setContextPath("/");
context.setHandler(handler);
server.setHandler(context);
server.start();
String host = connector.getHost();
if (host == null) {
host = "localhost";
}
int port = connector.getLocalPort();
serverUri = new URI(String.format("ws://%s:%d/", host, port));
}
Aggregations