Search in sources :

Example 6 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)

Example 7 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, JettyConnectionLogger connectionLogger) {
    // SSL Context Factory
    SslContextFactory.Server 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;
    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);
    if (listenHost != null) {
        sslConnector.setHost(listenHost);
    }
    if (connectionLogger != null) {
        sslConnector.addBean(connectionLogger);
    }
    server.addConnector(sslConnector);
    // Reload the key-store if the file is changed
    final int reloadSslContextSeconds = Integer.parseInt(System.getProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_RELOAD_SEC, "0"));
    if ((reloadSslContextSeconds > 0) && (sslContextFactory.getKeyStorePath() != null)) {
        try {
            KeyStoreScanner keystoreScanner = new KeyStoreScanner(sslContextFactory);
            keystoreScanner.setScanInterval(reloadSslContextSeconds);
            server.addBean(keystoreScanner);
        } catch (IllegalArgumentException exception) {
            LOG.error("Keystore cant be automatically reloaded when \"{}\" is changed: {}", sslContextFactory.getKeyStorePath(), exception.getMessage());
            throw exception;
        }
    }
}
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) KeyStoreScanner(org.eclipse.jetty.util.ssl.KeyStoreScanner) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ProxyConnectionFactory(org.eclipse.jetty.server.ProxyConnectionFactory)

Example 8 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)

Aggregations

ProxyConnectionFactory (org.eclipse.jetty.server.ProxyConnectionFactory)8 ServerConnector (org.eclipse.jetty.server.ServerConnector)7 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)6 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)4 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)3 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)3 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)3 Server (org.eclipse.jetty.server.Server)2 KeyStoreScanner (org.eclipse.jetty.util.ssl.KeyStoreScanner)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