Search in sources :

Example 46 with ContextHandler

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;
}
Also used : CorrelationHandler(org.apache.knox.gateway.filter.CorrelationHandler) RequestUpdateHandler(org.apache.knox.gateway.filter.RequestUpdateHandler) TraceHandler(org.apache.knox.gateway.trace.TraceHandler) PortMappingHelperHandler(org.apache.knox.gateway.filter.PortMappingHelperHandler) AccessHandler(org.apache.knox.gateway.trace.AccessHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) GatewayWebsocketHandler(org.apache.knox.gateway.websockets.GatewayWebsocketHandler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) GzipHandler(org.eclipse.jetty.servlets.gzip.GzipHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 47 with ContextHandler

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));
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Server(org.eclipse.jetty.server.Server) URI(java.net.URI)

Example 48 with ContextHandler

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();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Server(org.eclipse.jetty.server.Server) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection)

Example 49 with ContextHandler

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));
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Server(org.eclipse.jetty.server.Server) URI(java.net.URI)

Example 50 with ContextHandler

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));
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Server(org.eclipse.jetty.server.Server) URI(java.net.URI) BeforeClass(org.junit.BeforeClass)

Aggregations

ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)127 Server (org.eclipse.jetty.server.Server)47 ServerConnector (org.eclipse.jetty.server.ServerConnector)27 URI (java.net.URI)21 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)20 Test (org.junit.Test)20 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)19 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)19 IOException (java.io.IOException)18 Handler (org.eclipse.jetty.server.Handler)14 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)14 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)14 File (java.io.File)13 ServletException (javax.servlet.ServletException)13 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)13 BeforeClass (org.junit.BeforeClass)11 BaseIntegrationTest (com.ctrip.framework.apollo.BaseIntegrationTest)10 Config (com.ctrip.framework.apollo.Config)10 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)10 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)10