use of io.vertx.core.http.HttpClientOptions in project vertx-web by vert-x3.
the class OpenAPI3SchemasTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
// Have to stop default server of WebTestBase
stopServer();
startSchemaServer();
CountDownLatch latch = new CountDownLatch(1);
OpenAPI3RouterFactory.create(this.vertx, OAS_PATH, openAPI3RouterFactoryAsyncResult -> {
assertTrue(openAPI3RouterFactoryAsyncResult.succeeded());
assertNull(openAPI3RouterFactoryAsyncResult.cause());
routerFactory = openAPI3RouterFactoryAsyncResult.result();
routerFactory.setOptions(new RouterFactoryOptions().setRequireSecurityHandlers(false).setMountValidationFailureHandler(true).setValidationFailureHandler(FAILURE_HANDLER).setMountNotImplementedHandler(false));
latch.countDown();
});
awaitLatch(latch);
client = vertx.createHttpClient(new HttpClientOptions().setDefaultPort(8080));
}
use of io.vertx.core.http.HttpClientOptions in project vertx-web by vert-x3.
the class RoutingContextNullCurrentRouteTest method test.
@Test
public void test(TestContext testContext) {
HttpClient client = vertx.createHttpClient(new HttpClientOptions().setConnectTimeout(10000));
Async async = testContext.async();
HttpClientRequest httpClientRequest = client.get(PORT, "127.0.0.1", "/test", httpClientResponse -> {
testContext.assertEquals(HttpURLConnection.HTTP_NO_CONTENT, httpClientResponse.statusCode());
async.complete();
}).exceptionHandler(testContext::fail);
httpClientRequest.end();
}
use of io.vertx.core.http.HttpClientOptions in project gravitee-management-rest-api by gravitee-io.
the class WebhookNotifierServiceImpl method trigger.
@Override
public void trigger(final Hook hook, GenericNotificationConfig genericNotificationConfig, final Map<String, Object> params) {
if (genericNotificationConfig.getConfig() == null || genericNotificationConfig.getConfig().isEmpty()) {
LOGGER.error("Webhook Notifier configuration is empty");
return;
}
URI requestUri = URI.create(genericNotificationConfig.getConfig());
boolean ssl = HTTPS_SCHEME.equalsIgnoreCase(requestUri.getScheme());
final HttpClientOptions options = new HttpClientOptions().setSsl(ssl).setTrustAll(true).setMaxPoolSize(1).setKeepAlive(false).setTcpKeepAlive(false).setConnectTimeout(GLOBAL_TIMEOUT);
final HttpClient httpClient = vertx.createHttpClient(options);
final int port = requestUri.getPort() != -1 ? requestUri.getPort() : (HTTPS_SCHEME.equals(requestUri.getScheme()) ? 443 : 80);
HttpClientRequest request = httpClient.post(port, requestUri.getHost(), requestUri.toString(), response -> LOGGER.debug("Webhook response status code : {}", response.statusCode()));
request.setTimeout(GLOBAL_TIMEOUT);
// body
String body = toJson(hook, params);
// headers
request.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
request.putHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(body.length()));
request.putHeader("X-Gravitee-Event", hook.name());
request.putHeader("X-Gravitee-Event-Scope", hook.getScope().name());
request.putHeader("X-Gravitee-Request-Id", UUID.toString(UUID.random()));
request.write(body);
request.end();
}
use of io.vertx.core.http.HttpClientOptions in project vertx-openshift-it by cescoffier.
the class GatewayVerticle method start.
@Override
public void start() throws Exception {
dnsClient = vertx.createHttpClient(new HttpClientOptions().setDefaultHost(ENDPOINT_NAME).setDefaultPort(8080).setKeepAlive(false));
dnsWeb = WebClient.create(vertx, new WebClientOptions().setDefaultHost(ENDPOINT_NAME).setDefaultPort(8080).setKeepAlive(false));
dnsDatabase = JDBCClient.createShared(vertx, new JsonObject().put("url", "jdbc:postgresql://my-database:5432/my_data").put("driver_class", "org.postgresql.Driver").put("user", "luke").put("password", "secret"));
Router router = Router.router(vertx);
router.get("/health").handler(rc -> rc.response().end("OK"));
router.get("/services/http").handler(this::invokeHttpService);
router.get("/services/web").handler(this::invokeWebService);
router.get("/services/db").handler(this::checkDb);
router.get("/dns/http").handler(this::invokeHttpServiceWithDns);
router.get("/dns/web").handler(this::invokeWebServiceWithDns);
router.get("/dns/db").handler(this::checkDbWithDns);
router.get("/ref/http").handler(this::invokeHttpServiceWithRef);
router.get("/ref/web").handler(this::invokeWebServiceWithRef);
router.put("/webclient").handler(this::webclient);
ServiceDiscovery.create(vertx, discovery -> {
this.discovery = discovery;
Single<WebClient> svc1 = HttpEndpoint.rxGetWebClient(discovery, svc -> svc.getName().equals(ENDPOINT_NAME), new JsonObject().put("keepAlive", false));
Single<HttpClient> svc2 = HttpEndpoint.rxGetClient(discovery, svc -> svc.getName().equals(ENDPOINT_NAME), new JsonObject().put("keepAlive", false));
Single<JDBCClient> svc3 = JDBCDataSource.rxGetJDBCClient(discovery, svc -> svc.getName().equals("my-database"), new JsonObject().put("url", "jdbc:postgresql://my-database:5432/my_data").put("driver_class", "org.postgresql.Driver").put("user", "luke").put("password", "secret"));
Single.zip(svc1, svc2, svc3, (wc, hc, db) -> {
this.web = wc;
this.client = hc;
this.database = db;
return vertx.createHttpServer().requestHandler(router::accept).listen(8080);
}).subscribe();
});
}
use of io.vertx.core.http.HttpClientOptions in project vertx-openshift-it by cescoffier.
the class Http2IT method testHttp2_H2.
/**
* Checks that we can call a HTTP/2 endpoint exposed by a pod through a "TLS passthrough" route.
*/
@Test
public void testHttp2_H2() throws Exception {
Assertions.assertThat(client).deployments().pods().isPodReadyForPeriod();
AtomicReference<String> response = new AtomicReference<>();
HttpClientOptions options = new HttpClientOptions().setSsl(true).setUseAlpn(true).setProtocolVersion(HttpVersion.HTTP_2).setTrustAll(true);
final String host = securedUrlForRoute(client.routes().withName(NAME).get()).getHost();
System.out.println("Host: " + host);
System.out.println("Port: " + 443);
vertx.createHttpClient(options).getNow(443, host, "/", resp -> {
System.out.println("Got response " + resp.statusCode() + " with protocol " + resp.version());
resp.bodyHandler(body -> {
System.out.println("Got 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!");
}
Aggregations