Search in sources :

Example 1 with InstrumentedConnectionFactory

use of io.dropwizard.metrics.jetty11.InstrumentedConnectionFactory in project dropwizard by dropwizard.

the class HttpsConnectorFactoryTest method testBuild.

@Test
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(Arrays.asList("TLSv1.1", "TLSv1.2"));
    https.setSupportedCipherSuites(Arrays.asList("TLS_DHE_RSA.*", "TLS_ECDHE.*"));
    final Server server = new Server();
    final MetricRegistry metrics = new MetricRegistry();
    final ThreadPool threadPool = new QueuedThreadPool();
    try (final ServerConnector serverConnector = (ServerConnector) https.build(server, metrics, "test-https-connector", threadPool)) {
        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 InstrumentedConnectionFactory sslConnectionFactory = (InstrumentedConnectionFactory) serverConnector.getConnectionFactory("ssl");
        assertThat(sslConnectionFactory).isInstanceOf(InstrumentedConnectionFactory.class);
        assertThat(sslConnectionFactory).extracting("connectionFactory").asInstanceOf(InstanceOfAssertFactories.type(SslConnectionFactory.class)).extracting(SslConnectionFactory::getSslContextFactory).satisfies(sslContextFactory -> {
            assertThat(sslContextFactory.getKeyStoreResource()).isEqualTo(newResource("/etc/app/server.ks"));
            assertThat(sslContextFactory.getKeyStoreType()).isEqualTo("JKS");
            assertThat(sslContextFactory).extracting("_keyStorePassword").isEqualTo("correct_horse");
            assertThat(sslContextFactory.getKeyStoreProvider()).isEqualTo("BC");
            assertThat(sslContextFactory.getTrustStoreResource()).isEqualTo(newResource("/etc/app/server.ts"));
            assertThat(sslContextFactory.getKeyStoreType()).isEqualTo("JKS");
            assertThat(sslContextFactory).extracting("_trustStorePassword").isEqualTo("battery_staple");
            assertThat(sslContextFactory.getKeyStoreProvider()).isEqualTo("BC");
            assertThat(sslContextFactory).extracting("_keyManagerPassword").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(sslContextFactory.getEndpointIdentificationAlgorithm()).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);
    } finally {
        server.stop();
    }
}
Also used : 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) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) InstrumentedConnectionFactory(com.codahale.metrics.jetty9.InstrumentedConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) File(java.io.File) InstrumentedConnectionFactory(com.codahale.metrics.jetty9.InstrumentedConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 2 with InstrumentedConnectionFactory

use of io.dropwizard.metrics.jetty11.InstrumentedConnectionFactory in project dropwizard by dropwizard.

the class HttpConnectorFactory method build.

@Override
public Connector build(Server server, MetricRegistry metrics, String name, @Nullable ThreadPool threadPool) {
    final HttpConfiguration httpConfig = buildHttpConfiguration();
    final HttpConnectionFactory httpConnectionFactory = buildHttpConnectionFactory(httpConfig);
    final Scheduler scheduler = new ScheduledExecutorScheduler();
    final ByteBufferPool bufferPool = buildBufferPool();
    return buildConnector(server, scheduler, bufferPool, name, threadPool, new InstrumentedConnectionFactory(httpConnectionFactory, metrics.timer(httpConnections())));
}
Also used : ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) Scheduler(org.eclipse.jetty.util.thread.Scheduler) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) InstrumentedConnectionFactory(com.codahale.metrics.jetty9.InstrumentedConnectionFactory)

Example 3 with InstrumentedConnectionFactory

use of io.dropwizard.metrics.jetty11.InstrumentedConnectionFactory 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(io.dropwizard.metrics.jetty11.InstrumentedHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) InstrumentedQueuedThreadPool(io.dropwizard.metrics.jetty11.InstrumentedQueuedThreadPool) AdminServlet(io.dropwizard.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) InstrumentedQueuedThreadPool(io.dropwizard.metrics.jetty11.InstrumentedQueuedThreadPool) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) InstrumentedConnectionFactory(io.dropwizard.metrics.jetty11.InstrumentedConnectionFactory)

Example 4 with InstrumentedConnectionFactory

use of io.dropwizard.metrics.jetty11.InstrumentedConnectionFactory 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 5 with InstrumentedConnectionFactory

use of io.dropwizard.metrics.jetty11.InstrumentedConnectionFactory in project dropwizard by dropwizard.

the class HttpConnectorFactoryTest method testBuildConnector.

@Test
void testBuildConnector() throws Exception {
    HttpConnectorFactory http = spy(new HttpConnectorFactory());
    http.setBindHost("127.0.0.1");
    http.setAcceptorThreads(Optional.of(1));
    http.setSelectorThreads(Optional.of(2));
    http.setAcceptQueueSize(1024);
    http.setMinResponseDataPerSecond(DataSize.bytes(200));
    http.setMinRequestDataPerSecond(DataSize.bytes(42));
    http.setRequestCookieCompliance(CookieCompliance.RFC6265);
    http.setResponseCookieCompliance(CookieCompliance.RFC6265);
    MetricRegistry metrics = new MetricRegistry();
    ThreadPool threadPool = new QueuedThreadPool();
    Server server = null;
    try {
        server = new Server();
        try (final ServerConnector connector = (ServerConnector) http.build(server, metrics, "test-http-connector", threadPool)) {
            assertThat(connector.getPort()).isEqualTo(8080);
            assertThat(connector.getHost()).isEqualTo("127.0.0.1");
            assertThat(connector.getAcceptQueueSize()).isEqualTo(1024);
            assertThat(connector.getReuseAddress()).isTrue();
            assertThat(connector.getIdleTimeout()).isEqualTo(30000);
            assertThat(connector.getName()).isEqualTo("test-http-connector");
            assertThat(connector.getServer()).isSameAs(server);
            assertThat(connector.getScheduler()).isInstanceOf(ScheduledExecutorScheduler.class);
            assertThat(connector.getExecutor()).isSameAs(threadPool);
            verify(http).buildBufferPool(64, 1024, 64 * 1024);
            assertThat(connector.getAcceptors()).isEqualTo(1);
            assertThat(connector.getSelectorManager().getSelectorCount()).isEqualTo(2);
            InstrumentedConnectionFactory connectionFactory = (InstrumentedConnectionFactory) connector.getConnectionFactory("http/1.1");
            assertThat(connectionFactory).isInstanceOf(InstrumentedConnectionFactory.class);
            assertThat(connectionFactory).extracting("connectionFactory").asInstanceOf(InstanceOfAssertFactories.type(HttpConnectionFactory.class)).satisfies(factory -> {
                assertThat(factory.getInputBufferSize()).isEqualTo(8192);
                assertThat(factory.getHttpCompliance()).isEqualByComparingTo(HttpCompliance.RFC7230);
            }).extracting(HttpConnectionFactory::getHttpConfiguration).satisfies(config -> {
                assertThat(config.getHeaderCacheSize()).isEqualTo(512);
                assertThat(config.getOutputBufferSize()).isEqualTo(32768);
                assertThat(config.getRequestHeaderSize()).isEqualTo(8192);
                assertThat(config.getResponseHeaderSize()).isEqualTo(8192);
                assertThat(config.getSendDateHeader()).isTrue();
                assertThat(config.getSendServerVersion()).isFalse();
                assertThat(config.getCustomizers()).noneMatch(customizer -> customizer.getClass().equals(ForwardedRequestCustomizer.class));
                assertThat(config.getMinRequestDataRate()).isEqualTo(42);
                assertThat(config.getMinResponseDataRate()).isEqualTo(200);
                assertThat(config.getRequestCookieCompliance()).isEqualTo(CookieCompliance.RFC6265);
                assertThat(config.getResponseCookieCompliance()).isEqualTo(CookieCompliance.RFC6265);
            });
        }
    } finally {
        if (server != null) {
            server.stop();
        }
    }
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) MetricRegistry(com.codahale.metrics.MetricRegistry) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) InstrumentedConnectionFactory(com.codahale.metrics.jetty9.InstrumentedConnectionFactory) ForwardedRequestCustomizer(org.eclipse.jetty.server.ForwardedRequestCustomizer) Test(org.junit.jupiter.api.Test)

Aggregations

InstrumentedConnectionFactory (com.codahale.metrics.jetty9.InstrumentedConnectionFactory)7 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)7 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)5 Server (org.eclipse.jetty.server.Server)4 ServerConnector (org.eclipse.jetty.server.ServerConnector)4 ScheduledExecutorScheduler (org.eclipse.jetty.util.thread.ScheduledExecutorScheduler)4 ThreadPool (org.eclipse.jetty.util.thread.ThreadPool)4 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 HealthCheckRegistry (com.codahale.metrics.health.HealthCheckRegistry)2 HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)2 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)2 Connector (org.eclipse.jetty.server.Connector)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)2 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)2 Scheduler (org.eclipse.jetty.util.thread.Scheduler)2 Test (org.junit.jupiter.api.Test)2 InstrumentedHandler (com.codahale.metrics.jetty9.InstrumentedHandler)1