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;
}
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();
});
}
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);
}
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();
}
});
}
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);
}
Aggregations