use of org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2 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());
}
use of org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2 in project jetty.project by eclipse.
the class AbstractTest method prepareClient.
protected void prepareClient() throws Exception {
client = new HttpClient(new HttpClientTransportOverHTTP2(new HTTP2Client()), null);
QueuedThreadPool clientExecutor = new QueuedThreadPool();
clientExecutor.setName("client");
client.setExecutor(clientExecutor);
}
use of org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2 in project dropwizard by dropwizard.
the class Http2CIntegrationTest method setUp.
@Before
public void setUp() throws Exception {
final HTTP2Client http2Client = new HTTP2Client();
// No need for ALPN
http2Client.setClientConnectionFactory(new HTTP2ClientConnectionFactory());
client = new HttpClient(new HttpClientTransportOverHTTP2(http2Client), null);
client.start();
}
use of org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2 in project cayenne by apache.
the class JettyHttp2ClientConnectionProvider method initJettyHttpClient.
@Override
protected HttpClient initJettyHttpClient() {
try {
HttpClientTransportOverHTTP2 http2 = new HttpClientTransportOverHTTP2(new HTTP2Client());
boolean useALPN = runtimeProperties.getBoolean(ClientConstants.ROP_SERVICE_USE_ALPN_PROPERTY, false);
http2.setUseALPN(useALPN);
HttpClient httpClient = new HttpClient(http2, new SslContextFactory());
httpClient.start();
return httpClient;
} catch (Exception e) {
throw new CayenneRuntimeException("Exception while starting Jetty HttpClient over HTTP/2.", e);
}
}
use of org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2 in project cayenne by apache.
the class JettyHttpROPConnectorIT method initJettyHttp2Client.
protected static HttpClient initJettyHttp2Client() {
try {
HttpClientTransportOverHTTP2 http2 = new HttpClientTransportOverHTTP2(new HTTP2Client());
http2.setUseALPN(false);
HttpClient httpClient = new HttpClient(http2, new SslContextFactory());
httpClient.start();
return httpClient;
} catch (Exception e) {
throw new CayenneRuntimeException("Exception while starting Jetty HttpClient over HTTP/2.", e);
}
}
Aggregations