Search in sources :

Example 21 with HTTP2ServerConnectionFactory

use of org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory in project dropwizard by dropwizard.

the class Http2ConnectorFactory method build.

@Override
public Connector build(Server server, MetricRegistry metrics, String name, @Nullable ThreadPool threadPool) {
    // HTTP/2 requires that a server MUST support TLSv1.2 or higher and TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 cipher
    // See https://datatracker.ietf.org/doc/html/rfc7540#section-9.2
    setSupportedProtocols(Arrays.asList("TLSv1.3", "TLSv1.2"));
    checkSupportedCipherSuites();
    // Setup connection factories
    final HttpConfiguration httpConfig = buildHttpConfiguration();
    final HttpConnectionFactory http1 = buildHttpConnectionFactory(httpConfig);
    final HTTP2ServerConnectionFactory http2 = new HTTP2ServerConnectionFactory(httpConfig);
    http2.setMaxConcurrentStreams(maxConcurrentStreams);
    http2.setInitialStreamRecvWindow(initialStreamRecvWindow);
    final NegotiatingServerConnectionFactory alpn = new ALPNServerConnectionFactory();
    // Speak HTTP 1.1 over TLS if negotiation fails
    alpn.setDefaultProtocol("http/1.1");
    final SslContextFactory sslContextFactory = configureSslContextFactory(new SslContextFactory.Server());
    sslContextFactory.addLifeCycleListener(logSslParameters(sslContextFactory));
    server.addBean(sslContextFactory);
    server.addBean(new SslReload(sslContextFactory, this::configureSslContextFactory));
    // We should use ALPN as a negotiation protocol. Old clients that don't support it will be served
    // via HTTPS. New clients, however, that want to use HTTP/2 will use TLS with ALPN extension.
    // If negotiation succeeds, the client and server switch to HTTP/2 protocol.
    final SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(sslContextFactory, "alpn");
    return buildConnector(server, new ScheduledExecutorScheduler(), buildBufferPool(), name, threadPool, new InstrumentedConnectionFactory(sslConnectionFactory, metrics.timer(httpConnections())), alpn, http2, http1);
}
Also used : SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SslReload(io.dropwizard.jetty.SslReload) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) NegotiatingServerConnectionFactory(org.eclipse.jetty.server.NegotiatingServerConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) InstrumentedConnectionFactory(com.codahale.metrics.jetty9.InstrumentedConnectionFactory)

Example 22 with HTTP2ServerConnectionFactory

use of org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory in project dropwizard by dropwizard.

the class Http2CConnectorFactory method build.

@Override
public Connector build(Server server, MetricRegistry metrics, String name, @Nullable ThreadPool threadPool) {
    // Prepare connection factories for HTTP/2c
    final HttpConfiguration httpConfig = buildHttpConfiguration();
    final HttpConnectionFactory http11 = buildHttpConnectionFactory(httpConfig);
    final HTTP2ServerConnectionFactory http2c = new HTTP2CServerConnectionFactory(httpConfig);
    http2c.setMaxConcurrentStreams(maxConcurrentStreams);
    http2c.setInitialStreamRecvWindow(initialStreamRecvWindow);
    // new protocol.
    return buildConnector(server, new ScheduledExecutorScheduler(), buildBufferPool(), name, threadPool, new InstrumentedConnectionFactory(http11, metrics.timer(httpConnections())), http2c);
}
Also used : HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) InstrumentedConnectionFactory(com.codahale.metrics.jetty9.InstrumentedConnectionFactory)

Example 23 with HTTP2ServerConnectionFactory

use of org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory in project rest.li by linkedin.

the class HttpsH2JettyServer method getConnectors.

@Override
protected Connector[] getConnectors(Server server) {
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(_keyStore);
    sslContextFactory.setKeyStorePassword(_keyStorePassword);
    sslContextFactory.setTrustStorePath(_keyStore);
    sslContextFactory.setTrustStorePassword(_keyStorePassword);
    sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
    sslContextFactory.setUseCipherSuitesOrder(true);
    HttpConfiguration https_config = new HttpConfiguration();
    https_config.setSecureScheme(HttpScheme.HTTPS.asString());
    https_config.setSecurePort(_sslPort);
    // HTTPS Configuration
    HttpConfiguration http2_config = new HttpConfiguration(https_config);
    http2_config.addCustomizer(new SecureRequestCustomizer());
    // HTTP/2 Connection Factory
    HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(http2_config) {

        /**
         * Required to override since we are using legacy versions in testing which would not be otherwise accepted
         */
        @Override
        public boolean isAcceptable(String protocol, String tlsProtocol, String tlsCipher) {
            return true;
        }
    };
    NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable();
    ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
    alpn.setDefaultProtocol("h2");
    // SSL Connection Factory
    SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
    // Connector supporting HTTP/2, http1.1 and negotiation protocols
    ServerConnector h2Connector = new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(https_config, HttpCompliance.RFC2616));
    h2Connector.setPort(_sslPort);
    server.addConnector(h2Connector);
    HttpConfiguration configuration = new HttpConfiguration();
    ServerConnector h2cConnector = new ServerConnector(server, new HttpConnectionFactory(configuration, HttpCompliance.RFC2616), new HTTP2CServerConnectionFactory(configuration));
    h2cConnector.setPort(_port);
    return new ServerConnector[] { h2Connector, h2cConnector };
}
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) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Aggregations

HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)21 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)21 ServerConnector (org.eclipse.jetty.server.ServerConnector)15 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)14 ALPNServerConnectionFactory (org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory)13 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)13 Server (org.eclipse.jetty.server.Server)11 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)11 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)10 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)8 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)8 HTTP2CServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory)5 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 HTTP2Cipher (org.eclipse.jetty.http2.HTTP2Cipher)3 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)3 InstrumentedConnectionFactory (com.codahale.metrics.jetty9.InstrumentedConnectionFactory)2 HttpServlet (javax.servlet.http.HttpServlet)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2