use of io.vertx.core.http.HttpClientOptions in project vert.x by eclipse.
the class HttpTest method testUseInMultithreadedWorker.
@Test
public void testUseInMultithreadedWorker() throws Exception {
class MyVerticle extends AbstractVerticle {
@Override
public void start() {
assertIllegalStateException(() -> server = vertx.createHttpServer(new HttpServerOptions()));
assertIllegalStateException(() -> client = vertx.createHttpClient(new HttpClientOptions()));
testComplete();
}
}
MyVerticle verticle = new MyVerticle();
vertx.deployVerticle(verticle, new DeploymentOptions().setWorker(true).setMultiThreaded(true));
await();
}
use of io.vertx.core.http.HttpClientOptions in project vert.x by eclipse.
the class HttpMetricsTest method testServerConnectionClosed.
private void testServerConnectionClosed(HttpVersion protocol) throws Exception {
server.close();
server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST).setIdleTimeout(2));
server.requestHandler(req -> {
FakeHttpServerMetrics metrics = FakeMetricsBase.getMetrics(server);
HttpServerMetric metric = metrics.getMetric(req);
assertNotNull(metric);
assertFalse(metric.failed.get());
req.response().closeHandler(v -> {
assertNull(metrics.getMetric(req));
assertTrue(metric.failed.get());
testComplete();
});
});
startServer();
client = vertx.createHttpClient(new HttpClientOptions().setProtocolVersion(protocol));
HttpClientRequest req = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
req.handler(resp -> {
}).end();
await();
}
use of io.vertx.core.http.HttpClientOptions 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.HttpClientOptions in project vert.x by eclipse.
the class SSLEngineTest method doTest.
private void doTest(SSLEngineOptions engine, boolean useAlpn, HttpVersion version, String error, String expectedSslContext, boolean expectCause) {
server.close();
HttpServerOptions options = new HttpServerOptions().setSslEngineOptions(engine).setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST).setKeyCertOptions(Cert.SERVER_PEM.get()).setSsl(true).setUseAlpn(useAlpn);
try {
server = vertx.createHttpServer(options);
} catch (VertxException e) {
e.printStackTrace();
if (error == null) {
fail(e);
} else {
assertEquals(error, e.getMessage());
if (expectCause) {
assertNotSame(e, e.getCause());
}
}
return;
}
server.requestHandler(req -> {
assertEquals(req.version(), version);
assertTrue(req.isSSL());
req.response().end();
});
server.listen(onSuccess(s -> {
HttpServerImpl impl = (HttpServerImpl) s;
SSLHelper sslHelper = impl.getSslHelper();
SslContext ctx = sslHelper.getContext((VertxInternal) vertx);
switch(expectedSslContext) {
case "jdk":
assertTrue(ctx instanceof JdkSslContext);
break;
case "openssl":
assertTrue(ctx instanceof OpenSslContext);
break;
}
client = vertx.createHttpClient(new HttpClientOptions().setSslEngineOptions(engine).setSsl(true).setUseAlpn(useAlpn).setTrustAll(true).setProtocolVersion(version));
client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> {
assertEquals(200, resp.statusCode());
testComplete();
});
}));
await();
}
use of io.vertx.core.http.HttpClientOptions in project vert.x by eclipse.
the class DummyMetricsTest method testDummyHttpClientMetrics.
@Test
public void testDummyHttpClientMetrics() {
HttpClient client = vertx.createHttpClient(new HttpClientOptions());
assertFalse(client.isMetricsEnabled());
}
Aggregations