use of io.vertx.core.http.HttpClient in project vert.x by eclipse.
the class HAProxyTest method testHttpWithoutHAProxySupport.
@Test
public void testHttpWithoutHAProxySupport() {
Vertx vertx = Vertx.vertx();
try {
vertx.createHttpServer(new HttpServerOptions().setUseProxyProtocol(true)).requestHandler(req -> {
req.response().end("hello");
}).listen(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, onSuccess(s -> {
HttpClient client = vertx.createHttpClient();
client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/", onSuccess(req -> {
req.send(onSuccess(resp -> {
resp.body(onSuccess(body -> {
assertEquals("hello", body.toString());
testComplete();
}));
}));
}));
}));
await();
} finally {
vertx.close();
}
}
use of io.vertx.core.http.HttpClient in project vert.x by eclipse.
the class VertxTest method testFinalizeHttpClient.
@Test
public void testFinalizeHttpClient() throws Exception {
VertxInternal vertx = (VertxInternal) Vertx.vertx();
try {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<NetSocket> socketRef = new AtomicReference<>();
vertx.createNetServer().connectHandler(socketRef::set).listen(8080, "localhost").onComplete(onSuccess(server -> latch.countDown()));
awaitLatch(latch);
AtomicBoolean closed = new AtomicBoolean();
// No keep alive so the connection is not held in the pool ????
CloseFuture closeFuture = new CloseFuture();
closeFuture.future().onComplete(ar -> closed.set(true));
HttpClient client = vertx.createHttpClient(new HttpClientOptions().setKeepAlive(false), closeFuture);
vertx.addCloseHook(closeFuture);
client.request(HttpMethod.GET, 8080, "localhost", "/").compose(HttpClientRequest::send).onComplete(onFailure(err -> {
}));
WeakReference<HttpClient> ref = new WeakReference<>(client);
closeFuture = null;
client = null;
assertWaitUntil(() -> socketRef.get() != null);
for (int i = 0; i < 10; i++) {
Thread.sleep(10);
RUNNER.runSystemGC();
assertFalse(closed.get());
assertNotNull(ref.get());
}
socketRef.get().close();
long now = System.currentTimeMillis();
while (true) {
assertTrue(System.currentTimeMillis() - now < 20_000);
RUNNER.runSystemGC();
if (ref.get() == null) {
assertTrue(closed.get());
break;
}
}
} finally {
vertx.close(ar -> {
testComplete();
});
}
await();
}
use of io.vertx.core.http.HttpClient in project vert.x by eclipse.
the class NettyCompatTest method testHttp2.
@Test
public void testHttp2() {
vertx.createHttpServer(new HttpServerOptions().setUseAlpn(true).setSsl(true).setSslEngineOptions(new OpenSSLEngineOptions()).setKeyCertOptions(Cert.SERVER_JKS.get())).requestHandler(req -> req.response().end("OK")).listen(8443, "localhost", onSuccess(s -> {
HttpClient client = vertx.createHttpClient(new HttpClientOptions().setSsl(true).setSslEngineOptions(new OpenSSLEngineOptions()).setTrustStoreOptions(Trust.SERVER_JKS.get()));
client.getNow(8443, "localhost", "/somepath", resp -> {
resp.bodyHandler(buff -> {
assertEquals("OK", buff.toString());
testComplete();
});
});
}));
await();
}
use of io.vertx.core.http.HttpClient in project vert.x by eclipse.
the class DummyMetricsTest method testDummyHttpClientMetrics.
@Test
public void testDummyHttpClientMetrics() {
HttpClient client = vertx.createHttpClient(new HttpClientOptions());
assertFalse(client.isMetricsEnabled());
}
use of io.vertx.core.http.HttpClient in project vert.x by eclipse.
the class ProxyErrorTest method proxyTest.
private void proxyTest(int error, String username, String url, Handler<HttpClientResponse> assertResponse, boolean completeOnException) throws Exception {
startProxy(error, username);
final HttpClientOptions options = new HttpClientOptions().setSsl(url.startsWith("https")).setProxyOptions(new ProxyOptions().setType(ProxyType.HTTP).setHost("localhost").setPort(proxy.getPort()));
HttpClient client = vertx.createHttpClient(options);
client.getAbs(url, assertResponse).exceptionHandler(e -> {
if (completeOnException) {
testComplete();
} else {
fail(e);
}
}).end();
await();
}
Aggregations