Search in sources :

Example 1 with WebClientOptions

use of io.vertx.ext.web.client.WebClientOptions in project NetDiscovery by fengzhizi715.

the class VertxDownloader method initWebClientOptions.

private WebClientOptions initWebClientOptions(Request request) {
    WebClientOptions options = new WebClientOptions();
    options.setKeepAlive(true).setReuseAddress(true).setFollowRedirects(true);
    if (Preconditions.isNotBlank(request.getUserAgent())) {
        options.setUserAgent(request.getUserAgent());
    }
    if (Preconditions.isNotBlank(request.getProxy())) {
        ProxyOptions proxyOptions = new ProxyOptions();
        proxyOptions.setHost(request.getProxy().getIp());
        proxyOptions.setPort(request.getProxy().getPort());
        options.setProxyOptions(proxyOptions);
    }
    if (Preconditions.isNotBlank(request.getHeader())) {
        header = request.getHeader();
    }
    return options;
}
Also used : WebClientOptions(io.vertx.ext.web.client.WebClientOptions) ProxyOptions(io.vertx.core.net.ProxyOptions)

Example 2 with WebClientOptions

use of io.vertx.ext.web.client.WebClientOptions 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 3 with WebClientOptions

use of io.vertx.ext.web.client.WebClientOptions in project vertx-openshift-it by cescoffier.

the class EdgeVerticle method start.

@Override
public void start() throws Exception {
    client = WebClient.create(vertx, new WebClientOptions().setProtocolVersion(HttpVersion.HTTP_2).setSsl(true).setUseAlpn(true).setTrustAll(true));
    Router router = Router.router(vertx);
    router.get("/").handler(this::hello);
    router.get("/health").handler(rc -> rc.response().end("OK"));
    router.get("/aloha").handler(this::front);
    router.get("/hello").handler(this::grpc);
    HttpServer server = vertx.createHttpServer(new HttpServerOptions());
    server.requestHandler(router::accept).listen(8080);
}
Also used : WebClientOptions(io.vertx.ext.web.client.WebClientOptions) HttpServer(io.vertx.core.http.HttpServer) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Router(io.vertx.ext.web.Router)

Example 4 with WebClientOptions

use of io.vertx.ext.web.client.WebClientOptions in project vertx-examples by vert-x3.

the class Client method start.

@Override
public void start() throws Exception {
    // Create the web client and enable SSL/TLS with a trust store
    WebClient client = WebClient.create(vertx, new WebClientOptions().setSsl(true).setTrustStoreOptions(new JksOptions().setPath("client-truststore.jks").setPassword("wibble")));
    client.get(8443, "localhost", "/").send(ar -> {
        if (ar.succeeded()) {
            HttpResponse<Buffer> response = ar.result();
            System.out.println("Got HTTP response with status " + response.statusCode());
        } else {
            ar.cause().printStackTrace();
        }
    });
}
Also used : Buffer(io.vertx.core.buffer.Buffer) WebClientOptions(io.vertx.ext.web.client.WebClientOptions) JksOptions(io.vertx.core.net.JksOptions) WebClient(io.vertx.ext.web.client.WebClient)

Example 5 with WebClientOptions

use of io.vertx.ext.web.client.WebClientOptions in project vertx-web by vert-x3.

the class WebClientExamples method createFromOptions.

public void createFromOptions(Vertx vertx) {
    WebClientOptions options = new WebClientOptions().setUserAgent("My-App/1.2.3");
    options.setKeepAlive(false);
    WebClient client = WebClient.create(vertx, options);
}
Also used : WebClientOptions(io.vertx.ext.web.client.WebClientOptions) WebClient(io.vertx.ext.web.client.WebClient)

Aggregations

WebClientOptions (io.vertx.ext.web.client.WebClientOptions)10 WebClient (io.vertx.ext.web.client.WebClient)5 JsonObject (io.vertx.core.json.JsonObject)4 Future (io.vertx.core.Future)2 Buffer (io.vertx.core.buffer.Buffer)2 Router (io.vertx.rxjava.ext.web.Router)2 MessagingType (org.eclipse.hono.util.MessagingType)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Cookie (com.cv4j.netdiscovery.core.cookies.Cookie)1 CookieGroup (com.cv4j.netdiscovery.core.cookies.CookieGroup)1 Response (com.cv4j.netdiscovery.core.domain.Response)1 Cache (com.github.benmanes.caffeine.cache.Cache)1 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 Timer (io.micrometer.core.instrument.Timer)1 Tracer (io.opentracing.Tracer)1 ConfigMapping (io.smallrye.config.ConfigMapping)1 CircuitBreakerOptions (io.vertx.circuitbreaker.CircuitBreakerOptions)1 AsyncResult (io.vertx.core.AsyncResult)1 CompositeFuture (io.vertx.core.CompositeFuture)1