Search in sources :

Example 1 with ProxyConnectionFactory

use of org.eclipse.jetty.server.ProxyConnectionFactory in project jetty.project by eclipse.

the class UnixSocketServer method main.

public static void main(String... args) throws Exception {
    Server server = new Server();
    HttpConnectionFactory http = new HttpConnectionFactory();
    ProxyConnectionFactory proxy = new ProxyConnectionFactory(http.getProtocol());
    UnixSocketConnector connector = new UnixSocketConnector(server, proxy, http);
    server.addConnector(connector);
    server.setHandler(new AbstractHandler.ErrorDispatchHandler() {

        @Override
        protected void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            baseRequest.setHandled(true);
            response.setStatus(200);
            response.getWriter().write("Hello World\r\n");
            response.getWriter().write("remote=" + request.getRemoteAddr() + ":" + request.getRemotePort() + "\r\n");
            response.getWriter().write("local =" + request.getLocalAddr() + ":" + request.getLocalPort() + "\r\n");
        }
    });
    server.start();
    server.join();
}
Also used : Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) ProxyConnectionFactory(org.eclipse.jetty.server.ProxyConnectionFactory)

Example 2 with ProxyConnectionFactory

use of org.eclipse.jetty.server.ProxyConnectionFactory in project athenz by yahoo.

the class AthenzJettyContainer method addHTTPSConnector.

void addHTTPSConnector(HttpConfiguration httpConfig, int httpsPort, boolean proxyProtocol, String listenHost, int idleTimeout, boolean needClientAuth) {
    // SSL Context Factory
    SslContextFactory sslContextFactory = createSSLContextObject(needClientAuth);
    // SSL HTTP Configuration
    HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
    httpsConfig.setSecureScheme("https");
    httpsConfig.setSecurePort(httpsPort);
    httpsConfig.addCustomizer(new SecureRequestCustomizer());
    // SSL Connector
    ServerConnector sslConnector = null;
    if (proxyProtocol) {
        sslConnector = new ServerConnector(server, new ProxyConnectionFactory(), new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
    } else {
        sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
    }
    sslConnector.setPort(httpsPort);
    sslConnector.setIdleTimeout(idleTimeout);
    server.addConnector(sslConnector);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ProxyConnectionFactory(org.eclipse.jetty.server.ProxyConnectionFactory)

Example 3 with ProxyConnectionFactory

use of org.eclipse.jetty.server.ProxyConnectionFactory in project dropwizard by dropwizard.

the class HttpConnectorFactory method buildConnector.

protected ServerConnector buildConnector(Server server, Scheduler scheduler, ByteBufferPool bufferPool, String name, @Nullable ThreadPool threadPool, ConnectionFactory... factories) {
    if (useProxyProtocol) {
        factories = ArrayUtil.prependToArray(new ProxyConnectionFactory(), factories, ConnectorFactory.class);
    }
    final ServerConnector connector = new ServerConnector(server, threadPool, scheduler, bufferPool, acceptorThreads.orElse(-1), selectorThreads.orElse(-1), factories);
    connector.setPort(port);
    connector.setHost(bindHost);
    connector.setInheritChannel(inheritChannel);
    if (acceptQueueSize != null) {
        connector.setAcceptQueueSize(acceptQueueSize);
    } else {
        // if we do not set the acceptQueueSize, when jetty
        // creates the ServerSocket, it uses the default backlog of 50, and
        // not the value from the OS.  Therefore we set to the value
        // obtained from NetUtil, which will attempt to read the value from the OS.
        // somaxconn setting
        connector.setAcceptQueueSize(NetUtil.getTcpBacklog());
    }
    connector.setReuseAddress(reuseAddress);
    connector.setIdleTimeout(idleTimeout.toMilliseconds());
    connector.setName(name);
    return connector;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ProxyConnectionFactory(org.eclipse.jetty.server.ProxyConnectionFactory)

Example 4 with ProxyConnectionFactory

use of org.eclipse.jetty.server.ProxyConnectionFactory in project jetty.project by eclipse.

the class ProxyProtocolTest method startServer.

public void startServer(Handler handler) throws Exception {
    server = new Server();
    HttpConfiguration configuration = new HttpConfiguration();
    connector = new ServerConnector(server, new ProxyConnectionFactory(), new HTTP2CServerConnectionFactory(configuration));
    server.addConnector(connector);
    server.setHandler(handler);
    client = new HTTP2Client();
    server.addBean(client, true);
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ProxyConnectionFactory(org.eclipse.jetty.server.ProxyConnectionFactory)

Example 5 with ProxyConnectionFactory

use of org.eclipse.jetty.server.ProxyConnectionFactory in project athenz by yahoo.

the class AthenzJettyContainer method addHTTPConnector.

void addHTTPConnector(HttpConfiguration httpConfig, int httpPort, boolean proxyProtocol, String listenHost, int idleTimeout) {
    ServerConnector connector;
    if (proxyProtocol) {
        connector = new ServerConnector(server, new ProxyConnectionFactory(), new HttpConnectionFactory(httpConfig));
    } else {
        connector = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
    }
    if (!StringUtil.isEmpty(listenHost)) {
        connector.setHost(listenHost);
    }
    connector.setPort(httpPort);
    connector.setIdleTimeout(idleTimeout);
    server.addConnector(connector);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ProxyConnectionFactory(org.eclipse.jetty.server.ProxyConnectionFactory)

Aggregations

ProxyConnectionFactory (org.eclipse.jetty.server.ProxyConnectionFactory)6 ServerConnector (org.eclipse.jetty.server.ServerConnector)5 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)4 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)3 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)2 Server (org.eclipse.jetty.server.Server)2 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)2 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HTTP2CServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory)1 Request (org.eclipse.jetty.server.Request)1 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)1 KeyStoreScanner (org.eclipse.jetty.util.ssl.KeyStoreScanner)1