Search in sources :

Example 11 with HTTP2Client

use of org.eclipse.jetty.http2.client.HTTP2Client in project jetty.project by eclipse.

the class FlowControlStalledTest method start.

protected void start(FlowControlStrategy.Factory flowControlFactory, ServerSessionListener listener) throws Exception {
    QueuedThreadPool serverExecutor = new QueuedThreadPool();
    serverExecutor.setName("server");
    server = new Server(serverExecutor);
    RawHTTP2ServerConnectionFactory connectionFactory = new RawHTTP2ServerConnectionFactory(new HttpConfiguration(), listener);
    connectionFactory.setFlowControlStrategyFactory(flowControlFactory);
    connector = new ServerConnector(server, connectionFactory);
    server.addConnector(connector);
    server.start();
    client = new HTTP2Client();
    QueuedThreadPool clientExecutor = new QueuedThreadPool();
    clientExecutor.setName("client");
    client.setExecutor(clientExecutor);
    client.setFlowControlStrategyFactory(flowControlFactory);
    client.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) RawHTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.RawHTTP2ServerConnectionFactory) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 12 with HTTP2Client

use of org.eclipse.jetty.http2.client.HTTP2Client in project jetty.project by eclipse.

the class FlowControlStrategyTest method start.

protected void start(ServerSessionListener listener) throws Exception {
    QueuedThreadPool serverExecutor = new QueuedThreadPool();
    serverExecutor.setName("server");
    server = new Server(serverExecutor);
    RawHTTP2ServerConnectionFactory connectionFactory = new RawHTTP2ServerConnectionFactory(new HttpConfiguration(), listener);
    connectionFactory.setFlowControlStrategyFactory(FlowControlStrategyTest.this::newFlowControlStrategy);
    connector = new ServerConnector(server, connectionFactory);
    server.addConnector(connector);
    server.start();
    client = new HTTP2Client();
    QueuedThreadPool clientExecutor = new QueuedThreadPool();
    clientExecutor.setName("client");
    client.setExecutor(clientExecutor);
    client.setFlowControlStrategyFactory(FlowControlStrategyTest.this::newFlowControlStrategy);
    client.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) RawHTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.RawHTTP2ServerConnectionFactory) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 13 with HTTP2Client

use of org.eclipse.jetty.http2.client.HTTP2Client in project jetty.project by eclipse.

the class HTTP2Test method testMultipleRequests.

@Test
public void testMultipleRequests() throws Exception {
    final String downloadBytes = "X-Download";
    start(new HttpServlet() {

        @Override
        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            int download = request.getIntHeader(downloadBytes);
            byte[] content = new byte[download];
            new Random().nextBytes(content);
            response.getOutputStream().write(content);
        }
    });
    int requests = 20;
    Session session = newClient(new Session.Listener.Adapter());
    Random random = new Random();
    HttpFields fields = new HttpFields();
    fields.putLongField(downloadBytes, random.nextInt(128 * 1024));
    fields.put("User-Agent", "HTTP2Client/" + Jetty.VERSION);
    MetaData.Request metaData = newRequest("GET", fields);
    HeadersFrame frame = new HeadersFrame(metaData, null, true);
    final CountDownLatch latch = new CountDownLatch(requests);
    for (int i = 0; i < requests; ++i) {
        session.newStream(frame, new Promise.Adapter<>(), new Stream.Listener.Adapter() {

            @Override
            public void onData(Stream stream, DataFrame frame, Callback callback) {
                callback.succeeded();
                if (frame.isEndStream())
                    latch.countDown();
            }
        });
    }
    Assert.assertTrue(latch.await(requests, TimeUnit.SECONDS));
}
Also used : ServerSessionListener(org.eclipse.jetty.http2.api.server.ServerSessionListener) HttpServlet(javax.servlet.http.HttpServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) DataFrame(org.eclipse.jetty.http2.frames.DataFrame) CountDownLatch(java.util.concurrent.CountDownLatch) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) Promise(org.eclipse.jetty.util.Promise) FuturePromise(org.eclipse.jetty.util.FuturePromise) Callback(org.eclipse.jetty.util.Callback) Random(java.util.Random) MetaData(org.eclipse.jetty.http.MetaData) HttpFields(org.eclipse.jetty.http.HttpFields) Stream(org.eclipse.jetty.http2.api.Stream) Session(org.eclipse.jetty.http2.api.Session) Test(org.junit.Test)

Example 14 with HTTP2Client

use of org.eclipse.jetty.http2.client.HTTP2Client in project jetty.project by eclipse.

the class DirectHTTP2OverTLSTest method startClient.

private void startClient() throws Exception {
    QueuedThreadPool clientThreads = new QueuedThreadPool();
    clientThreads.setName("client");
    HttpClientTransportOverHTTP2 transport = new HttpClientTransportOverHTTP2(new HTTP2Client());
    transport.setUseALPN(false);
    client = new HttpClient(transport, newSslContextFactory());
    client.setExecutor(clientThreads);
    client.start();
}
Also used : QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HttpClient(org.eclipse.jetty.client.HttpClient) HTTP2Client(org.eclipse.jetty.http2.client.HTTP2Client)

Example 15 with HTTP2Client

use of org.eclipse.jetty.http2.client.HTTP2Client in project jetty.project by eclipse.

the class HttpClientTransportOverHTTP2Test method testPropertiesAreForwarded.

@Test
public void testPropertiesAreForwarded() throws Exception {
    HTTP2Client http2Client = new HTTP2Client();
    HttpClient httpClient = new HttpClient(new HttpClientTransportOverHTTP2(http2Client), null);
    Executor executor = new QueuedThreadPool();
    httpClient.setExecutor(executor);
    httpClient.setConnectTimeout(13);
    httpClient.setIdleTimeout(17);
    httpClient.start();
    Assert.assertTrue(http2Client.isStarted());
    Assert.assertSame(httpClient.getExecutor(), http2Client.getExecutor());
    Assert.assertSame(httpClient.getScheduler(), http2Client.getScheduler());
    Assert.assertSame(httpClient.getByteBufferPool(), http2Client.getByteBufferPool());
    Assert.assertEquals(httpClient.getConnectTimeout(), http2Client.getConnectTimeout());
    Assert.assertEquals(httpClient.getIdleTimeout(), http2Client.getIdleTimeout());
    httpClient.stop();
    Assert.assertTrue(http2Client.isStopped());
}
Also used : Executor(java.util.concurrent.Executor) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HttpClient(org.eclipse.jetty.client.HttpClient) HTTP2Client(org.eclipse.jetty.http2.client.HTTP2Client) Test(org.junit.Test)

Aggregations

HTTP2Client (org.eclipse.jetty.http2.client.HTTP2Client)10 HttpClient (org.eclipse.jetty.client.HttpClient)8 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)8 Session (org.eclipse.jetty.http2.api.Session)7 HttpFields (org.eclipse.jetty.http.HttpFields)6 MetaData (org.eclipse.jetty.http.MetaData)6 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)6 Test (org.junit.Test)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 Stream (org.eclipse.jetty.http2.api.Stream)5 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)4 DataFrame (org.eclipse.jetty.http2.frames.DataFrame)4 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)4 Server (org.eclipse.jetty.server.Server)4 ServerConnector (org.eclipse.jetty.server.ServerConnector)4 Callback (org.eclipse.jetty.util.Callback)4 FuturePromise (org.eclipse.jetty.util.FuturePromise)4 InetSocketAddress (java.net.InetSocketAddress)3 Executor (java.util.concurrent.Executor)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3