Search in sources :

Example 1 with ConnectHandler

use of org.eclipse.jetty.server.handler.ConnectHandler in project saga by timurstrekalov.

the class InstrumentingProxyServer method start.

public int start() {
    final SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(0);
    server.addConnector(connector);
    final HandlerCollection handlers = new HandlerCollection();
    // Setup proxy servlet
    final ServletContextHandler context = new ServletContextHandler(handlers, "/");
    context.setAttribute(InstrumentingProxyServlet.INSTRUMENTER, instrumenter);
    context.addServlet(new ServletHolder(InstrumentingProxyServlet.class), "/*");
    // Setup proxy handler to handle CONNECT methods
    final ConnectHandler connectProxy = new ConnectHandler();
    handlers.addHandler(connectProxy);
    server.setHandler(handlers);
    try {
        server.start();
        logger.info("Proxy server started on port {}", connector.getLocalPort());
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
    return connector.getLocalPort();
}
Also used : SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) ConnectHandler(org.eclipse.jetty.server.handler.ConnectHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

ConnectHandler (org.eclipse.jetty.server.handler.ConnectHandler)1 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)1 SelectChannelConnector (org.eclipse.jetty.server.nio.SelectChannelConnector)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1