Search in sources :

Example 76 with HttpConfiguration

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

the class DirectHTTP2OverTLSTest method startServer.

private void startServer(Handler handler) throws Exception {
    QueuedThreadPool serverThreads = new QueuedThreadPool();
    serverThreads.setName("server");
    server = new Server(serverThreads);
    HttpConfiguration httpsConfig = new HttpConfiguration();
    httpsConfig.addCustomizer(new SecureRequestCustomizer());
    ConnectionFactory h2 = new HTTP2ServerConnectionFactory(httpsConfig);
    ConnectionFactory ssl = new SslConnectionFactory(newSslContextFactory(), h2.getProtocol());
    connector = new ServerConnector(server, 1, 1, ssl, h2);
    server.addConnector(connector);
    server.setHandler(handler);
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Example 77 with HttpConfiguration

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

the class HttpClientTransportOverHTTP2Test method testLastStreamId.

@Test
public void testLastStreamId() throws Exception {
    prepareServer(new RawHTTP2ServerConnectionFactory(new HttpConfiguration(), new ServerSessionListener.Adapter() {

        @Override
        public Map<Integer, Integer> onPreface(Session session) {
            Map<Integer, Integer> settings = new HashMap<>();
            settings.put(SettingsFrame.MAX_CONCURRENT_STREAMS, 1);
            return settings;
        }

        @Override
        public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
            MetaData.Request request = (MetaData.Request) frame.getMetaData();
            if (HttpMethod.HEAD.is(request.getMethod())) {
                stream.getSession().close(ErrorCode.REFUSED_STREAM_ERROR.code, null, Callback.NOOP);
            } else {
                MetaData.Response response = new MetaData.Response(HttpVersion.HTTP_2, HttpStatus.OK_200, new HttpFields());
                stream.headers(new HeadersFrame(stream.getId(), response, null, true), Callback.NOOP);
            }
            return null;
        }
    }));
    server.start();
    CountDownLatch latch = new CountDownLatch(2);
    AtomicInteger lastStream = new AtomicInteger();
    AtomicReference<Stream> streamRef = new AtomicReference<>();
    CountDownLatch streamLatch = new CountDownLatch(1);
    client = new HttpClient(new HttpClientTransportOverHTTP2(new HTTP2Client()) {

        @Override
        protected HttpConnectionOverHTTP2 newHttpConnection(HttpDestination destination, Session session) {
            return new HttpConnectionOverHTTP2(destination, session) {

                @Override
                protected HttpChannelOverHTTP2 newHttpChannel(boolean push) {
                    return new HttpChannelOverHTTP2(getHttpDestination(), this, getSession(), push) {

                        @Override
                        public void setStream(Stream stream) {
                            super.setStream(stream);
                            streamRef.set(stream);
                            streamLatch.countDown();
                        }
                    };
                }
            };
        }

        @Override
        protected void onClose(HttpConnectionOverHTTP2 connection, GoAwayFrame frame) {
            super.onClose(connection, frame);
            lastStream.set(frame.getLastStreamId());
            latch.countDown();
        }
    }, null);
    QueuedThreadPool clientExecutor = new QueuedThreadPool();
    clientExecutor.setName("client");
    client.setExecutor(clientExecutor);
    client.start();
    // Prime the connection to allow client and server prefaces to be exchanged.
    ContentResponse response = client.newRequest("localhost", connector.getLocalPort()).path("/zero").timeout(5, TimeUnit.SECONDS).send();
    Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
    org.eclipse.jetty.client.api.Request request = client.newRequest("localhost", connector.getLocalPort()).method(HttpMethod.HEAD).path("/one");
    request.send(result -> {
        if (result.isFailed())
            latch.countDown();
    });
    Assert.assertTrue(streamLatch.await(5, TimeUnit.SECONDS));
    Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
    Stream stream = streamRef.get();
    Assert.assertNotNull(stream);
    Assert.assertEquals(lastStream.get(), stream.getId());
}
Also used : HashMap(java.util.HashMap) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) MetaData(org.eclipse.jetty.http.MetaData) HttpFields(org.eclipse.jetty.http.HttpFields) Stream(org.eclipse.jetty.http2.api.Stream) OutputStream(java.io.OutputStream) InputStream(java.io.InputStream) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) GoAwayFrame(org.eclipse.jetty.http2.frames.GoAwayFrame) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) RawHTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.RawHTTP2ServerConnectionFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpClient(org.eclipse.jetty.client.HttpClient) HTTP2Client(org.eclipse.jetty.http2.client.HTTP2Client) HttpDestination(org.eclipse.jetty.client.HttpDestination) HTTP2Session(org.eclipse.jetty.http2.HTTP2Session) Session(org.eclipse.jetty.http2.api.Session) Test(org.junit.Test)

Example 78 with HttpConfiguration

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

the class MaxConcurrentStreamsTest method start.

private void start(int maxConcurrentStreams, Handler handler) throws Exception {
    HTTP2ServerConnectionFactory http2 = new HTTP2ServerConnectionFactory(new HttpConfiguration());
    http2.setMaxConcurrentStreams(maxConcurrentStreams);
    prepareServer(http2);
    server.setHandler(handler);
    server.start();
    prepareClient();
    client.start();
}
Also used : HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 79 with HttpConfiguration

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

the class AbstractServerTest method startServer.

protected void startServer(HttpServlet servlet) throws Exception {
    prepareServer(new HTTP2ServerConnectionFactory(new HttpConfiguration()));
    ServletContextHandler context = new ServletContextHandler(server, "/");
    context.addServlet(new ServletHolder(servlet), path);
    server.start();
}
Also used : ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 80 with HttpConfiguration

use of org.eclipse.jetty.server.HttpConfiguration in project gocd by gocd.

the class FakeGoServer method sslConnector.

public Connector sslConnector(File keystore, File truststore, int sslPort) {
    HttpConfiguration httpsConfig = new HttpConfiguration();
    httpsConfig.setOutputBufferSize(RESPONSE_BUFFER_SIZE);
    httpsConfig.addCustomizer(new SecureRequestCustomizer());
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(keystore.getAbsolutePath());
    sslContextFactory.setKeyStorePassword(PASSWORD);
    sslContextFactory.setKeyManagerPassword(PASSWORD);
    sslContextFactory.setTrustStorePath(truststore.getAbsolutePath());
    sslContextFactory.setTrustStorePassword(PASSWORD);
    sslContextFactory.setWantClientAuth(true);
    ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(httpsConfig));
    https.setPort(sslPort);
    https.setIdleTimeout(MAX_IDLE_TIME);
    return https;
}
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) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Aggregations

HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)99 ServerConnector (org.eclipse.jetty.server.ServerConnector)71 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)70 Server (org.eclipse.jetty.server.Server)55 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)40 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)40 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)36 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)25 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)23 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)19 HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 Connector (org.eclipse.jetty.server.Connector)11 IOException (java.io.IOException)10 File (java.io.File)9 ServletException (javax.servlet.ServletException)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 ALPNServerConnectionFactory (org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory)8 HTTP2CServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory)7 Request (org.eclipse.jetty.server.Request)7