Search in sources :

Example 6 with HttpConnectionFactory

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

the class HttpsConnectorFactoryTest method testBuild.

@Test
public void testBuild() throws Exception {
    final HttpsConnectorFactory https = new HttpsConnectorFactory();
    https.setBindHost("127.0.0.1");
    https.setPort(8443);
    https.setKeyStorePath("/etc/app/server.ks");
    https.setKeyStoreType("JKS");
    https.setKeyStorePassword("correct_horse");
    https.setKeyStoreProvider("BC");
    https.setTrustStorePath("/etc/app/server.ts");
    https.setTrustStoreType("JKS");
    https.setTrustStorePassword("battery_staple");
    https.setTrustStoreProvider("BC");
    https.setKeyManagerPassword("new_overlords");
    https.setNeedClientAuth(true);
    https.setWantClientAuth(true);
    https.setCertAlias("alt_server");
    https.setCrlPath(new File("/etc/ctr_list.txt"));
    https.setEnableCRLDP(true);
    https.setEnableOCSP(true);
    https.setMaxCertPathLength(4);
    https.setOcspResponderUrl(new URI("http://windc1/ocsp"));
    https.setJceProvider("BC");
    https.setAllowRenegotiation(false);
    https.setEndpointIdentificationAlgorithm("HTTPS");
    https.setValidateCerts(true);
    https.setValidatePeers(true);
    https.setSupportedProtocols(ImmutableList.of("TLSv1.1", "TLSv1.2"));
    https.setSupportedCipherSuites(ImmutableList.of("TLS_DHE_RSA.*", "TLS_ECDHE.*"));
    final Server server = new Server();
    final MetricRegistry metrics = new MetricRegistry();
    final ThreadPool threadPool = new QueuedThreadPool();
    final Connector connector = https.build(server, metrics, "test-https-connector", threadPool);
    assertThat(connector).isInstanceOf(ServerConnector.class);
    final ServerConnector serverConnector = (ServerConnector) connector;
    assertThat(serverConnector.getPort()).isEqualTo(8443);
    assertThat(serverConnector.getHost()).isEqualTo("127.0.0.1");
    assertThat(serverConnector.getName()).isEqualTo("test-https-connector");
    assertThat(serverConnector.getServer()).isSameAs(server);
    assertThat(serverConnector.getScheduler()).isInstanceOf(ScheduledExecutorScheduler.class);
    assertThat(serverConnector.getExecutor()).isSameAs(threadPool);
    final Jetty93InstrumentedConnectionFactory jetty93SslConnectionFacttory = (Jetty93InstrumentedConnectionFactory) serverConnector.getConnectionFactory("ssl");
    assertThat(jetty93SslConnectionFacttory).isInstanceOf(Jetty93InstrumentedConnectionFactory.class);
    assertThat(jetty93SslConnectionFacttory.getTimer()).isSameAs(metrics.timer("org.eclipse.jetty.server.HttpConnectionFactory.127.0.0.1.8443.connections"));
    final SslContextFactory sslContextFactory = ((SslConnectionFactory) jetty93SslConnectionFacttory.getConnectionFactory()).getSslContextFactory();
    assertThat(getField(SslContextFactory.class, "_keyStoreResource", true).get(sslContextFactory)).isEqualTo(Resource.newResource("/etc/app/server.ks"));
    assertThat(sslContextFactory.getKeyStoreType()).isEqualTo("JKS");
    assertThat(getField(SslContextFactory.class, "_keyStorePassword", true).get(sslContextFactory).toString()).isEqualTo("correct_horse");
    assertThat(sslContextFactory.getKeyStoreProvider()).isEqualTo("BC");
    assertThat(getField(SslContextFactory.class, "_trustStoreResource", true).get(sslContextFactory)).isEqualTo(Resource.newResource("/etc/app/server.ts"));
    assertThat(sslContextFactory.getKeyStoreType()).isEqualTo("JKS");
    assertThat(getField(SslContextFactory.class, "_trustStorePassword", true).get(sslContextFactory).toString()).isEqualTo("battery_staple");
    assertThat(sslContextFactory.getKeyStoreProvider()).isEqualTo("BC");
    assertThat(getField(SslContextFactory.class, "_keyManagerPassword", true).get(sslContextFactory).toString()).isEqualTo("new_overlords");
    assertThat(sslContextFactory.getNeedClientAuth()).isTrue();
    assertThat(sslContextFactory.getWantClientAuth()).isTrue();
    assertThat(sslContextFactory.getCertAlias()).isEqualTo("alt_server");
    assertThat(sslContextFactory.getCrlPath()).isEqualTo(new File("/etc/ctr_list.txt").getAbsolutePath());
    assertThat(sslContextFactory.isEnableCRLDP()).isTrue();
    assertThat(sslContextFactory.isEnableOCSP()).isTrue();
    assertThat(sslContextFactory.getMaxCertPathLength()).isEqualTo(4);
    assertThat(sslContextFactory.getOcspResponderURL()).isEqualTo("http://windc1/ocsp");
    assertThat(sslContextFactory.getProvider()).isEqualTo("BC");
    assertThat(sslContextFactory.isRenegotiationAllowed()).isFalse();
    assertThat(getField(SslContextFactory.class, "_endpointIdentificationAlgorithm", true).get(sslContextFactory)).isEqualTo("HTTPS");
    assertThat(sslContextFactory.isValidateCerts()).isTrue();
    assertThat(sslContextFactory.isValidatePeerCerts()).isTrue();
    assertThat(sslContextFactory.getIncludeProtocols()).containsOnly("TLSv1.1", "TLSv1.2");
    assertThat(sslContextFactory.getIncludeCipherSuites()).containsOnly("TLS_DHE_RSA.*", "TLS_ECDHE.*");
    final ConnectionFactory httpConnectionFactory = serverConnector.getConnectionFactory("http/1.1");
    assertThat(httpConnectionFactory).isInstanceOf(HttpConnectionFactory.class);
    final HttpConfiguration httpConfiguration = ((HttpConnectionFactory) httpConnectionFactory).getHttpConfiguration();
    assertThat(httpConfiguration.getSecureScheme()).isEqualTo("https");
    assertThat(httpConfiguration.getSecurePort()).isEqualTo(8443);
    assertThat(httpConfiguration.getCustomizers()).hasAtLeastOneElementOfType(SecureRequestCustomizer.class);
    connector.stop();
    server.stop();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) MetricRegistry(com.codahale.metrics.MetricRegistry) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) URI(java.net.URI) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) File(java.io.File) Test(org.junit.Test)

Example 7 with HttpConnectionFactory

use of org.eclipse.jetty.server.HttpConnectionFactory in project metrics by dropwizard.

the class ExampleServer method main.

public static void main(String[] args) throws Exception {
    COUNTER_1.inc();
    COUNTER_2.inc();
    final ThreadPool threadPool = new InstrumentedQueuedThreadPool(REGISTRY);
    final Server server = new Server(threadPool);
    final Connector connector = new ServerConnector(server, new InstrumentedConnectionFactory(new HttpConnectionFactory(), REGISTRY.timer("http.connection")));
    server.addConnector(connector);
    final ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/initial");
    context.setAttribute(MetricsServlet.METRICS_REGISTRY, REGISTRY);
    context.setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, new HealthCheckRegistry());
    final ServletHolder holder = new ServletHolder(new AdminServlet());
    context.addServlet(holder, "/dingo/*");
    final InstrumentedHandler handler = new InstrumentedHandler(REGISTRY);
    handler.setHandler(context);
    server.setHandler(handler);
    server.start();
    server.join();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) InstrumentedHandler(com.codahale.metrics.jetty9.InstrumentedHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) InstrumentedQueuedThreadPool(com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool) AdminServlet(com.codahale.metrics.servlets.AdminServlet) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) InstrumentedQueuedThreadPool(com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) InstrumentedConnectionFactory(com.codahale.metrics.jetty9.InstrumentedConnectionFactory)

Example 8 with HttpConnectionFactory

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

the class JDK9ALPNTest method startServer.

public void startServer(Handler handler) throws Exception {
    server = new Server();
    HttpConfiguration httpConfiguration = new HttpConfiguration();
    HttpConnectionFactory h1 = new HttpConnectionFactory(httpConfiguration);
    HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(httpConfiguration);
    ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
    alpn.setDefaultProtocol(h1.getProtocol());
    connector = new ServerConnector(server, newSslContextFactory(), alpn, h1, h2);
    server.addConnector(connector);
    server.setHandler(handler);
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)

Example 9 with HttpConnectionFactory

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

the class JDK9HTTP2Server method main.

public static void main(String... args) throws Exception {
    Server server = new Server();
    HttpConfiguration httpsConfig = new HttpConfiguration();
    httpsConfig.setSecureScheme("https");
    httpsConfig.setSecurePort(8443);
    httpsConfig.setSendXPoweredBy(true);
    httpsConfig.setSendServerVersion(true);
    httpsConfig.addCustomizer(new SecureRequestCustomizer());
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
    sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
    sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
    HttpConnectionFactory http = new HttpConnectionFactory(httpsConfig);
    HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(httpsConfig);
    ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
    alpn.setDefaultProtocol(http.getProtocol());
    SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
    ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, h2, http);
    http2Connector.setPort(8443);
    server.addConnector(http2Connector);
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) 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) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Example 10 with HttpConnectionFactory

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

the class AsyncServletIOTest method setUp.

@Before
public void setUp() throws Exception {
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setOutputBufferSize(4096);
    _connector = new ServerConnector(_server, new HttpConnectionFactory(http_config));
    _server.setConnectors(new Connector[] { _connector });
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/ctx");
    context.addEventListener(new DebugListener());
    _server.setHandler(context);
    _servletHandler = context.getServletHandler();
    ServletHolder holder = new ServletHolder(_servlet0);
    holder.setAsyncSupported(true);
    _servletHandler.addServletWithMapping(holder, "/path/*");
    ServletHolder holder2 = new ServletHolder(_servlet2);
    holder2.setAsyncSupported(true);
    _servletHandler.addServletWithMapping(holder2, "/path2/*");
    ServletHolder holder3 = new ServletHolder(_servlet3);
    holder3.setAsyncSupported(true);
    _servletHandler.addServletWithMapping(holder3, "/path3/*");
    ServletHolder holder4 = new ServletHolder(_servlet4);
    holder4.setAsyncSupported(true);
    _servletHandler.addServletWithMapping(holder4, "/path4/*");
    _server.start();
    _port = _connector.getLocalPort();
    _owp.set(0);
    _oda.set(0);
    _read.set(0);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) DebugListener(org.eclipse.jetty.server.DebugListener) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) Before(org.junit.Before)

Aggregations

HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)90 ServerConnector (org.eclipse.jetty.server.ServerConnector)79 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)69 Server (org.eclipse.jetty.server.Server)56 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)44 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)43 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)39 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)18 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)16 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)15 File (java.io.File)12 Connector (org.eclipse.jetty.server.Connector)12 IOException (java.io.IOException)11 ServletException (javax.servlet.ServletException)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)9 Before (org.junit.Before)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 ALPNServerConnectionFactory (org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory)8 Request (org.eclipse.jetty.server.Request)8