Search in sources :

Example 31 with HttpClientOptions

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));
}
Also used : RouterFactoryOptions(io.vertx.ext.web.api.contract.RouterFactoryOptions) CountDownLatch(java.util.concurrent.CountDownLatch) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Example 32 with HttpClientOptions

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();
}
Also used : TestContext(io.vertx.ext.unit.TestContext) HttpURLConnection(java.net.HttpURLConnection) Async(io.vertx.ext.unit.Async) Vertx(io.vertx.core.Vertx) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Future(io.vertx.core.Future) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpServerResponse(io.vertx.core.http.HttpServerResponse) AbstractVerticle(io.vertx.core.AbstractVerticle) After(org.junit.After) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpClient(io.vertx.core.http.HttpClient) Before(org.junit.Before) HttpClientRequest(io.vertx.core.http.HttpClientRequest) Async(io.vertx.ext.unit.Async) HttpClient(io.vertx.core.http.HttpClient) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Test(org.junit.Test)

Example 33 with HttpClientOptions

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();
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClient(io.vertx.core.http.HttpClient) URI(java.net.URI) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Example 34 with HttpClientOptions

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();
    });
}
Also used : WebClientOptions(io.vertx.ext.web.client.WebClientOptions) HttpResponse(io.vertx.rxjava.ext.web.client.HttpResponse) Router(io.vertx.rxjava.ext.web.Router) RoutingContext(io.vertx.rxjava.ext.web.RoutingContext) HttpEndpoint(io.vertx.rxjava.servicediscovery.types.HttpEndpoint) AbstractVerticle(io.vertx.rxjava.core.AbstractVerticle) JDBCClient(io.vertx.rxjava.ext.jdbc.JDBCClient) WebClient(io.vertx.rxjava.ext.web.client.WebClient) HttpClient(io.vertx.rxjava.core.http.HttpClient) Single(rx.Single) JDBCDataSource(io.vertx.rxjava.servicediscovery.types.JDBCDataSource) ServiceDiscovery(io.vertx.rxjava.servicediscovery.ServiceDiscovery) JsonObject(io.vertx.core.json.JsonObject) HttpClientOptions(io.vertx.core.http.HttpClientOptions) BodyCodec(io.vertx.rxjava.ext.web.codec.BodyCodec) WebClientOptions(io.vertx.ext.web.client.WebClientOptions) HttpClient(io.vertx.rxjava.core.http.HttpClient) JsonObject(io.vertx.core.json.JsonObject) Router(io.vertx.rxjava.ext.web.Router) JDBCClient(io.vertx.rxjava.ext.jdbc.JDBCClient) WebClient(io.vertx.rxjava.ext.web.client.WebClient) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Example 35 with HttpClientOptions

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!");
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Aggregations

HttpClientOptions (io.vertx.core.http.HttpClientOptions)101 Test (org.junit.Test)51 HttpClient (io.vertx.core.http.HttpClient)27 HttpClientRequest (io.vertx.core.http.HttpClientRequest)23 HttpServerOptions (io.vertx.core.http.HttpServerOptions)19 CountDownLatch (java.util.concurrent.CountDownLatch)15 HttpMethod (io.vertx.core.http.HttpMethod)14 SSLCustom (org.apache.servicecomb.foundation.ssl.SSLCustom)14 SSLOption (org.apache.servicecomb.foundation.ssl.SSLOption)14 HttpVersion (io.vertx.core.http.HttpVersion)13 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 Vertx (io.vertx.core.Vertx)11 MockUp (mockit.MockUp)11 DeploymentOptions (io.vertx.core.DeploymentOptions)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 Buffer (io.vertx.core.buffer.Buffer)9 HttpServer (io.vertx.core.http.HttpServer)8 HttpServerResponse (io.vertx.core.http.HttpServerResponse)8 VertxOptions (io.vertx.core.VertxOptions)7 VertxInternal (io.vertx.core.impl.VertxInternal)7