Search in sources :

Example 11 with HTTP2ServerConnectionFactory

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

the class Http2Server method main.

public static void main(String... args) throws Exception {
    Server server = new Server();
    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    server.addBean(mbContainer);
    ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
    context.setResourceBase("src/main/resources/docroot");
    context.addFilter(PushCacheFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    // context.addFilter(PushSessionCacheFilter.class,"/*",EnumSet.of(DispatcherType.REQUEST));
    context.addFilter(PushedTilesFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    context.addServlet(new ServletHolder(servlet), "/test/*");
    context.addServlet(DefaultServlet.class, "/").setInitParameter("maxCacheSize", "81920");
    server.setHandler(context);
    // HTTP Configuration
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(8443);
    http_config.setSendXPoweredBy(true);
    http_config.setSendServerVersion(true);
    // HTTP Connector
    ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config), new HTTP2CServerConnectionFactory(http_config));
    http.setPort(8080);
    server.addConnector(http);
    // SSL Context Factory for HTTPS and HTTP/2
    String jetty_distro = System.getProperty("jetty.distro", "../../jetty-distribution/target/distribution");
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(jetty_distro + "/demo-base/etc/keystore");
    sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
    sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
    // HTTPS Configuration
    HttpConfiguration https_config = new HttpConfiguration(http_config);
    https_config.addCustomizer(new SecureRequestCustomizer());
    // HTTP/2 Connection Factory
    HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(https_config);
    ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
    alpn.setDefaultProtocol(http.getDefaultProtocol());
    // SSL Connection Factory
    SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
    // HTTP/2 Connector
    ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(https_config));
    http2Connector.setPort(8443);
    server.addConnector(http2Connector);
    ALPN.debug = false;
    server.start();
    //server.dumpStdErr();
    server.join();
}
Also used : SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) 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) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 12 with HTTP2ServerConnectionFactory

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

the class TestTransparentProxyServer method main.

public static void main(String[] args) throws Exception {
    ((StdErrLog) Log.getLog()).setSource(false);
    String jetty_root = "../../..";
    // Setup Threadpool
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setMaxThreads(100);
    // Setup server
    Server server = new Server(threadPool);
    server.manage(threadPool);
    // Setup JMX
    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    server.addBean(mbContainer);
    server.addBean(Log.getLog());
    // Common HTTP configuration
    HttpConfiguration config = new HttpConfiguration();
    config.setSecurePort(8443);
    config.addCustomizer(new ForwardedRequestCustomizer());
    config.setSendDateHeader(true);
    config.setSendServerVersion(true);
    // Http Connector
    HttpConnectionFactory http = new HttpConnectionFactory(config);
    ServerConnector httpConnector = new ServerConnector(server, http);
    httpConnector.setPort(8080);
    httpConnector.setIdleTimeout(30000);
    server.addConnector(httpConnector);
    // SSL configurations
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(jetty_root + "/jetty-server/src/main/config/etc/keystore");
    sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
    sslContextFactory.setTrustStorePath(jetty_root + "/jetty-server/src/main/config/etc/keystore");
    sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    sslContextFactory.setExcludeCipherSuites("SSL_RSA_WITH_DES_CBC_SHA", "SSL_DHE_RSA_WITH_DES_CBC_SHA", "SSL_DHE_DSS_WITH_DES_CBC_SHA", "SSL_RSA_EXPORT_WITH_RC4_40_MD5", "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA", "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA", "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA");
    sslContextFactory.setCipherComparator(new HTTP2Cipher.CipherComparator());
    // HTTPS Configuration
    HttpConfiguration https_config = new HttpConfiguration(config);
    https_config.addCustomizer(new SecureRequestCustomizer());
    // HTTP2 factory
    HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(https_config);
    ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
    alpn.setDefaultProtocol(h2.getProtocol());
    // SSL Factory
    SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
    // HTTP2 Connector
    ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(https_config));
    http2Connector.setPort(8443);
    http2Connector.setIdleTimeout(15000);
    server.addConnector(http2Connector);
    // Handlers
    HandlerCollection handlers = new HandlerCollection();
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    handlers.setHandlers(new Handler[] { contexts, new DefaultHandler() });
    server.setHandler(handlers);
    // Setup proxy webapp
    WebAppContext webapp = new WebAppContext();
    webapp.setResourceBase("src/main/webapp");
    contexts.addHandler(webapp);
    // start server
    server.setStopAtShutdown(true);
    server.start();
    server.join();
}
Also used : StdErrLog(org.eclipse.jetty.util.log.StdErrLog) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ForwardedRequestCustomizer(org.eclipse.jetty.server.ForwardedRequestCustomizer) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HTTP2Cipher(org.eclipse.jetty.http2.HTTP2Cipher) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection)

Example 13 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, 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 Jetty93InstrumentedConnectionFactory(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) Jetty93InstrumentedConnectionFactory(io.dropwizard.jetty.Jetty93InstrumentedConnectionFactory)

Example 14 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, ThreadPool threadPool) {
    // HTTP/2 requires that a server MUST support TLSv1.2 and TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 cipher
    // See http://http2.github.io/http2-spec/index.html#rfc.section.9.2.2
    setSupportedProtocols(ImmutableList.of("TLSv1.2"));
    setSupportedCipherSuites(ImmutableList.of("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"));
    // 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(H2, H2_17);
    // Speak HTTP 1.1 over TLS if negotiation fails
    alpn.setDefaultProtocol(HTTP_1_1);
    final SslContextFactory sslContextFactory = configureSslContextFactory(new SslContextFactory());
    sslContextFactory.addLifeCycleListener(logSslInfoOnStart(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 Jetty93InstrumentedConnectionFactory(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) Jetty93InstrumentedConnectionFactory(io.dropwizard.jetty.Jetty93InstrumentedConnectionFactory)

Example 15 with HTTP2ServerConnectionFactory

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

the class WordPressHTTP2FastCGIProxyServer method main.

public static void main(String[] args) throws Exception {
    int tlsPort = 8443;
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setEndpointIdentificationAlgorithm("");
    sslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
    sslContextFactory.setKeyStorePassword("storepwd");
    sslContextFactory.setTrustStorePath("src/test/resources/truststore.jks");
    sslContextFactory.setTrustStorePassword("storepwd");
    sslContextFactory.setCipherComparator(new HTTP2Cipher.CipherComparator());
    Server server = new Server();
    // HTTP(S) Configuration
    HttpConfiguration config = new HttpConfiguration();
    HttpConfiguration https_config = new HttpConfiguration(config);
    https_config.addCustomizer(new SecureRequestCustomizer());
    // HTTP2 factory
    HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(https_config);
    ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
    alpn.setDefaultProtocol(h2.getProtocol());
    // SSL Factory
    SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
    // HTTP2 Connector
    ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(https_config));
    http2Connector.setPort(tlsPort);
    http2Connector.setIdleTimeout(15000);
    server.addConnector(http2Connector);
    String root = "/home/simon/programs/wordpress-3.7.1";
    ServletContextHandler context = new ServletContextHandler(server, "/wp");
    context.setResourceBase(root);
    context.setWelcomeFiles(new String[] { "index.php" });
    // Serve static resources
    ServletHolder defaultServlet = new ServletHolder("default", DefaultServlet.class);
    context.addServlet(defaultServlet, "/");
    FilterHolder tryFilesFilter = context.addFilter(TryFilesFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    //        tryFilesFilter.setInitParameter(TryFilesFilter.FILES_INIT_PARAM, "$path $path/index.php"); // Permalink /?p=123
    // Permalink /%year%/%monthnum%/%postname%
    tryFilesFilter.setInitParameter(TryFilesFilter.FILES_INIT_PARAM, "$path /index.php?p=$path");
    // FastCGI
    ServletHolder fcgiServlet = context.addServlet(FastCGIProxyServlet.class, "*.php");
    fcgiServlet.setInitParameter(FastCGIProxyServlet.SCRIPT_ROOT_INIT_PARAM, root);
    fcgiServlet.setInitParameter("proxyTo", "http://localhost:9000");
    fcgiServlet.setInitParameter("prefix", "/");
    fcgiServlet.setInitParameter(FastCGIProxyServlet.SCRIPT_PATTERN_INIT_PARAM, "(.+?\\.php)");
    server.start();
}
Also used : SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HTTP2Cipher(org.eclipse.jetty.http2.HTTP2Cipher) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)18 HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)17 ServerConnector (org.eclipse.jetty.server.ServerConnector)12 Server (org.eclipse.jetty.server.Server)11 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)10 ALPNServerConnectionFactory (org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory)9 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)9 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)9 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)8 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)8 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)8 HTTP2Cipher (org.eclipse.jetty.http2.HTTP2Cipher)3 HTTP2CServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory)3 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)3 Jetty93InstrumentedConnectionFactory (io.dropwizard.jetty.Jetty93InstrumentedConnectionFactory)2 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 HttpServlet (javax.servlet.http.HttpServlet)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2