use of io.vertx.core.http.HttpClientOptions in project vertx-web by vert-x3.
the class SockJSTestBase method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
client = vertx.createHttpClient(new HttpClientOptions().setDefaultPort(8080));
router = Router.router(vertx);
router.route().handler(CookieHandler.create());
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)).setNagHttps(false).setSessionTimeout(60 * 60 * 1000));
addHandlersBeforeSockJSHandler(router);
SockJSHandlerOptions options = new SockJSHandlerOptions().setHeartbeatInterval(2000);
sockJSHandler = SockJSHandler.create(vertx, options);
router.route("/test/*").handler(sockJSHandler);
server = vertx.createHttpServer(new HttpServerOptions().setPort(8080).setHost("localhost"));
CountDownLatch latch = new CountDownLatch(1);
server.requestHandler(router).listen(ar -> latch.countDown());
awaitLatch(latch);
}
use of io.vertx.core.http.HttpClientOptions in project vertx-web by vert-x3.
the class ClusteredSessionHandlerTest method testClusteredSession.
@Test
public void testClusteredSession() throws Exception {
CountDownLatch serversReady = new CountDownLatch(3);
Router router1 = Router.router(vertices[0]);
router1.route().handler(CookieHandler.create());
SessionStore store1 = ClusteredSessionStore.create(vertices[0]);
router1.route().handler(SessionHandler.create(store1));
HttpServer server1 = vertices[0].createHttpServer(new HttpServerOptions().setPort(8081).setHost("localhost"));
server1.requestHandler(router1);
server1.listen(onSuccess(s -> serversReady.countDown()));
HttpClient client1 = vertices[0].createHttpClient(new HttpClientOptions());
Router router2 = Router.router(vertices[1]);
router2.route().handler(CookieHandler.create());
SessionStore store2 = ClusteredSessionStore.create(vertices[1]);
router2.route().handler(SessionHandler.create(store2));
HttpServer server2 = vertices[1].createHttpServer(new HttpServerOptions().setPort(8082).setHost("localhost"));
server2.requestHandler(router2);
server2.listen(onSuccess(s -> serversReady.countDown()));
HttpClient client2 = vertices[0].createHttpClient(new HttpClientOptions());
Router router3 = Router.router(vertices[2]);
router3.route().handler(CookieHandler.create());
SessionStore store3 = ClusteredSessionStore.create(vertices[2]);
router3.route().handler(SessionHandler.create(store3));
HttpServer server3 = vertices[2].createHttpServer(new HttpServerOptions().setPort(8083).setHost("localhost"));
server3.requestHandler(router3);
server3.listen(onSuccess(s -> serversReady.countDown()));
HttpClient client3 = vertices[0].createHttpClient(new HttpClientOptions());
awaitLatch(serversReady);
router1.route().handler(rc -> {
Session sess = rc.session();
sess.put("foo", "bar");
stuffSession(sess);
rc.response().end();
});
router2.route().handler(rc -> {
Session sess = rc.session();
checkSession(sess);
assertEquals("bar", sess.get("foo"));
sess.put("eek", "wibble");
rc.response().end();
});
router3.route().handler(rc -> {
Session sess = rc.session();
checkSession(sess);
assertEquals("bar", sess.get("foo"));
assertEquals("wibble", sess.get("eek"));
rc.response().end();
});
AtomicReference<String> rSetCookie = new AtomicReference<>();
testRequestBuffer(client1, HttpMethod.GET, 8081, "/", null, resp -> {
String setCookie = resp.headers().get("set-cookie");
rSetCookie.set(setCookie);
}, 200, "OK", null);
// FIXME - for now we do an artificial sleep because it's possible the session hasn't been stored properly before
// the next request hits the server
// https://github.com/vert-x3/vertx-web/issues/93
Thread.sleep(1000);
testRequestBuffer(client2, HttpMethod.GET, 8082, "/", req -> req.putHeader("cookie", rSetCookie.get()), null, 200, "OK", null);
Thread.sleep(1000);
testRequestBuffer(client3, HttpMethod.GET, 8083, "/", req -> req.putHeader("cookie", rSetCookie.get()), null, 200, "OK", null);
}
use of io.vertx.core.http.HttpClientOptions in project vertx-openshift-it by cescoffier.
the class Http2IT method testHttp2_H2C.
/**
* Checks that we can call a HTTP/2 - H2C endpoint exposed by a pod.
*/
@Test
@Ignore("Openshift does not support HTTP/2 H2C route")
public void testHttp2_H2C() throws Exception {
Assertions.assertThat(client).deployments().pods().isPodReadyForPeriod();
AtomicReference<String> response = new AtomicReference<>();
HttpClientOptions options = new HttpClientOptions().setProtocolVersion(HttpVersion.HTTP_2).setHttp2ClearTextUpgrade(false);
final String host = securedUrlForRoute(client.routes().withName("aloha").get()).getHost();
System.out.println("Host: " + host);
vertx.createHttpClient(options).getNow(80, host, "/", resp -> {
System.out.println("Got H2C response " + resp.statusCode() + " with protocol " + resp.version());
resp.bodyHandler(body -> {
System.out.println("Got H2C data " + body.toString("ISO-8859-1"));
response.set(body.toString("ISO-8859-1"));
});
});
await().atMost(1, TimeUnit.MINUTES).untilAtomic(response, is(notNullValue()));
assertThat(response.get()).contains("Aloha HTTP_2");
}
use of io.vertx.core.http.HttpClientOptions in project vertx-openshift-it by cescoffier.
the class Http2IT method testHttp2_Internal_H2C.
/**
* Checks that we can call a HTTP/2 - H2C endpoint exposed by a pod from another pod (no route).
*/
@Test
public void testHttp2_Internal_H2C() throws Exception {
Assertions.assertThat(client).deployments().pods().isPodReadyForPeriod();
AtomicReference<String> response = new AtomicReference<>();
HttpClientOptions options = new HttpClientOptions();
final String host = urlForRoute(client.routes().withName("http2-it").get()).getHost();
System.out.println("Host: " + host);
vertx.createHttpClient(options).getNow(80, host, "/aloha", resp -> {
System.out.println("Got H2C response " + resp.statusCode() + " with protocol " + resp.version());
resp.bodyHandler(body -> {
System.out.println("Got H2C data " + body.toString("ISO-8859-1"));
response.set(body.toString("ISO-8859-1"));
});
});
await().atMost(1, TimeUnit.MINUTES).untilAtomic(response, is(notNullValue()));
assertThat(response.get()).contains("version = HTTP_2").contains("Aloha from vert.x!").contains("HTTP_1_1");
}
use of io.vertx.core.http.HttpClientOptions in project vertx-openshift-it by cescoffier.
the class GatewayVerticle method webclient.
private void webclient(RoutingContext routingContext) {
String host = routingContext.request().getParam("host");
final HttpClient httpClient = vertx.createHttpClient(new HttpClientOptions().setDefaultHost(host).setKeepAlive(false));
forward(routingContext, httpClient, true);
}
Aggregations