Search in sources :

Example 61 with ByteBufferPool

use of org.eclipse.jetty.io.ByteBufferPool in project jetty.project by eclipse.

the class DebugHandlerTest method startServer.

@SuppressWarnings("deprecation")
@Before
public void startServer() throws Exception {
    server = new Server();
    ServerConnector httpConnector = new ServerConnector(server);
    httpConnector.setPort(0);
    server.addConnector(httpConnector);
    File keystorePath = MavenTestingUtils.getTestResourceFile("keystore");
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(keystorePath.getAbsolutePath());
    sslContextFactory.setKeyStorePassword("storepwd");
    sslContextFactory.setKeyManagerPassword("keypwd");
    sslContextFactory.setTrustStorePath(keystorePath.getAbsolutePath());
    sslContextFactory.setTrustStorePassword("storepwd");
    ByteBufferPool pool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged());
    ServerConnector sslConnector = new ServerConnector(server, (Executor) null, (Scheduler) null, pool, 1, 1, AbstractConnectionFactory.getFactories(sslContextFactory, new HttpConnectionFactory()));
    server.addConnector(sslConnector);
    debugHandler = new DebugHandler();
    capturedLog = new ByteArrayOutputStream();
    debugHandler.setOutputStream(capturedLog);
    debugHandler.setHandler(new AbstractHandler() {

        @Override
        public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            baseRequest.setHandled(true);
            response.setStatus(HttpStatus.OK_200);
        }
    });
    server.setHandler(debugHandler);
    server.start();
    String host = httpConnector.getHost();
    if (host == null)
        host = "localhost";
    serverURI = URI.create(String.format("http://%s:%d/", host, httpConnector.getLocalPort()));
    secureServerURI = URI.create(String.format("https://%s:%d/", host, sslConnector.getLocalPort()));
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    try (InputStream stream = sslContextFactory.getKeyStoreResource().getInputStream()) {
        keystore.load(stream, "storepwd".toCharArray());
    }
    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(keystore);
    sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
    try {
        HttpsURLConnection.setDefaultHostnameVerifier(__hostnameverifier);
        SSLContext sc = SSLContext.getInstance("TLS");
        sc.init(null, SslContextFactory.TRUST_ALL_CERTS, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) Server(org.eclipse.jetty.server.Server) ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) InputStream(java.io.InputStream) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SSLContext(javax.net.ssl.SSLContext) KeyStore(java.security.KeyStore) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) File(java.io.File) Before(org.junit.Before)

Example 62 with ByteBufferPool

use of org.eclipse.jetty.io.ByteBufferPool in project jetty.project by eclipse.

the class HttpClientLoadTest method newServerConnector.

@Override
protected ServerConnector newServerConnector(Server server) {
    int cores = Runtime.getRuntime().availableProcessors();
    ByteBufferPool byteBufferPool = new ArrayByteBufferPool();
    byteBufferPool = new LeakTrackingByteBufferPool(byteBufferPool);
    return new ServerConnector(server, null, null, byteBufferPool, 1, Math.min(1, cores / 2), provideServerConnectionFactory(transport));
}
Also used : LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) ServerConnector(org.eclipse.jetty.server.ServerConnector) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool)

Example 63 with ByteBufferPool

use of org.eclipse.jetty.io.ByteBufferPool in project dropwizard by dropwizard.

the class HttpConnectorFactoryTest method testBuildConnector.

@Test
public void testBuildConnector() throws Exception {
    HttpConnectorFactory http = new HttpConnectorFactory();
    http.setBindHost("127.0.0.1");
    http.setAcceptorThreads(Optional.of(1));
    http.setSelectorThreads(Optional.of(2));
    http.setAcceptQueueSize(1024);
    http.setSoLingerTime(Duration.seconds(30));
    http.setBlockingTimeout(Duration.minutes(1));
    Server server = new Server();
    MetricRegistry metrics = new MetricRegistry();
    ThreadPool threadPool = new QueuedThreadPool();
    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.getSoLingerTime()).isEqualTo(30);
    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);
    // That's gross, but unfortunately ArrayByteBufferPool doesn't have public API for configuration
    ByteBufferPool byteBufferPool = connector.getByteBufferPool();
    assertThat(byteBufferPool).isInstanceOf(ArrayByteBufferPool.class);
    assertThat(getField(ArrayByteBufferPool.class, "_min", true).get(byteBufferPool)).isEqualTo(64);
    assertThat(getField(ArrayByteBufferPool.class, "_inc", true).get(byteBufferPool)).isEqualTo(1024);
    assertThat(((Object[]) getField(ArrayByteBufferPool.class, "_direct", true).get(byteBufferPool)).length).isEqualTo(64);
    assertThat(connector.getAcceptors()).isEqualTo(1);
    assertThat(connector.getSelectorManager().getSelectorCount()).isEqualTo(2);
    Jetty93InstrumentedConnectionFactory connectionFactory = (Jetty93InstrumentedConnectionFactory) connector.getConnectionFactory("http/1.1");
    assertThat(connectionFactory).isInstanceOf(Jetty93InstrumentedConnectionFactory.class);
    assertThat(connectionFactory.getTimer()).isSameAs(metrics.timer("org.eclipse.jetty.server.HttpConnectionFactory.127.0.0.1.8080.connections"));
    HttpConnectionFactory httpConnectionFactory = (HttpConnectionFactory) connectionFactory.getConnectionFactory();
    assertThat(httpConnectionFactory.getInputBufferSize()).isEqualTo(8192);
    assertThat(httpConnectionFactory.getHttpCompliance()).isEqualByComparingTo(HttpCompliance.RFC7230);
    HttpConfiguration httpConfiguration = httpConnectionFactory.getHttpConfiguration();
    assertThat(httpConfiguration.getHeaderCacheSize()).isEqualTo(512);
    assertThat(httpConfiguration.getOutputBufferSize()).isEqualTo(32768);
    assertThat(httpConfiguration.getRequestHeaderSize()).isEqualTo(8192);
    assertThat(httpConfiguration.getResponseHeaderSize()).isEqualTo(8192);
    assertThat(httpConfiguration.getSendDateHeader()).isTrue();
    assertThat(httpConfiguration.getSendServerVersion()).isFalse();
    assertThat(httpConfiguration.getCustomizers()).hasAtLeastOneElementOfType(ForwardedRequestCustomizer.class);
    assertThat(httpConfiguration.getBlockingTimeout()).isEqualTo(60000L);
    connector.stop();
    server.stop();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) 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) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) Test(org.junit.Test)

Example 64 with ByteBufferPool

use of org.eclipse.jetty.io.ByteBufferPool in project dropwizard by dropwizard.

the class HttpsConnectorFactory method build.

@Override
public Connector build(Server server, MetricRegistry metrics, String name, ThreadPool threadPool) {
    final HttpConfiguration httpConfig = buildHttpConfiguration();
    final HttpConnectionFactory httpConnectionFactory = buildHttpConnectionFactory(httpConfig);
    final SslContextFactory sslContextFactory = configureSslContextFactory(new SslContextFactory());
    sslContextFactory.addLifeCycleListener(logSslInfoOnStart(sslContextFactory));
    server.addBean(sslContextFactory);
    server.addBean(new SslReload(sslContextFactory, this::configureSslContextFactory));
    final SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.toString());
    final Scheduler scheduler = new ScheduledExecutorScheduler();
    final ByteBufferPool bufferPool = buildBufferPool();
    return buildConnector(server, scheduler, bufferPool, name, threadPool, new Jetty93InstrumentedConnectionFactory(sslConnectionFactory, metrics.timer(httpConnections())), httpConnectionFactory);
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) 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) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Example 65 with ByteBufferPool

use of org.eclipse.jetty.io.ByteBufferPool in project jetty.project by eclipse.

the class ServerFCGIConnection method onFillable.

@Override
public void onFillable() {
    EndPoint endPoint = getEndPoint();
    ByteBufferPool bufferPool = connector.getByteBufferPool();
    ByteBuffer buffer = bufferPool.acquire(configuration.getResponseHeaderSize(), true);
    try {
        while (true) {
            int read = endPoint.fill(buffer);
            if (// Avoid boxing of variable 'read'
            LOG.isDebugEnabled())
                LOG.debug("Read {} bytes from {}", read, endPoint);
            if (read > 0) {
                parse(buffer);
            } else if (read == 0) {
                bufferPool.release(buffer);
                fillInterested();
                break;
            } else {
                bufferPool.release(buffer);
                shutdown();
                break;
            }
        }
    } catch (Exception x) {
        if (LOG.isDebugEnabled())
            LOG.debug(x);
        bufferPool.release(buffer);
    // TODO: fail and close ?
    }
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) EndPoint(org.eclipse.jetty.io.EndPoint) ByteBuffer(java.nio.ByteBuffer) EndPoint(org.eclipse.jetty.io.EndPoint)

Aggregations

ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)72 ByteBuffer (java.nio.ByteBuffer)53 Test (org.junit.Test)51 MappedByteBufferPool (org.eclipse.jetty.io.MappedByteBufferPool)40 Parser (org.eclipse.jetty.http2.parser.Parser)37 HttpFields (org.eclipse.jetty.http.HttpFields)29 MetaData (org.eclipse.jetty.http.MetaData)24 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)21 HeaderGenerator (org.eclipse.jetty.http2.generator.HeaderGenerator)21 PrefaceFrame (org.eclipse.jetty.http2.frames.PrefaceFrame)20 SettingsFrame (org.eclipse.jetty.http2.frames.SettingsFrame)20 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)19 OutputStream (java.io.OutputStream)16 Socket (java.net.Socket)16 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)14 IOException (java.io.IOException)13 CountDownLatch (java.util.concurrent.CountDownLatch)13 EndPoint (org.eclipse.jetty.io.EndPoint)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8