io.vertx.reactivex.ext.web.client.WebClient Java Examples

The following examples show how to use io.vertx.reactivex.ext.web.client.WebClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DiscoveryTest.java    From redpipe with Apache License 2.0 6 votes vote down vote up
@Before
public void prepare(TestContext context) throws IOException {
	Async async = context.async();

	server = new Server();
	server.start(TestResource.class)
	.subscribe(() -> {
		webClient = WebClient.create(server.getVertx(),
				new WebClientOptions().setDefaultHost("localhost").setDefaultPort(9000));
		async.complete();
	}, x -> {
		x.printStackTrace();
		context.fail(x);
		async.complete();
	});
}
 
Example #2
Source File: DashboardWebAppVerticle.java    From vertx-in-action with MIT License 6 votes vote down vote up
private void hydrate() {
  WebClient webClient = WebClient.create(vertx);
  webClient
    .get(3001, "localhost", "/ranking-last-24-hours")
    .as(BodyCodec.jsonArray())
    .rxSend()
    .delay(5, TimeUnit.SECONDS, RxHelper.scheduler(vertx))
    .retry(5)
    .map(HttpResponse::body)
    .flattenAsFlowable(Functions.identity())
    .cast(JsonObject.class)
    .flatMapSingle(json -> whoOwnsDevice(webClient, json))
    .flatMapSingle(json -> fillWithUserProfile(webClient, json))
    .subscribe(
      this::hydrateEntryIfPublic,
      err -> logger.error("Hydratation error", err),
      () -> logger.info("Hydratation completed"));
}
 
Example #3
Source File: SwaggerApiTest.java    From redpipe with Apache License 2.0 6 votes vote down vote up
@Before
public void prepare(TestContext context) throws IOException {
    Async async = context.async();

    server = new Server();
    server.start(ReactiveController.class)
            .subscribe(() -> {
                webClient = WebClient.create(server.getVertx(),
                        new WebClientOptions().setDefaultHost("localhost").setDefaultPort(9000));
                async.complete();
            }, x -> {
                x.printStackTrace();
                context.fail(x);
                async.complete();
            });
}
 
Example #4
Source File: MyResource.java    From redpipe with Apache License 2.0 6 votes vote down vote up
@Path("coroutines/1")
@GET
public Single<Response> helloAsync(@Context io.vertx.reactivex.core.Vertx rxVertx){
	return Fibers.fiber(() -> {
		System.err.println("Creating client");
		WebClientOptions options = new WebClientOptions();
		options.setSsl(true);
		options.setTrustAll(true);
		options.setVerifyHost(false);
		WebClient client = WebClient.create(rxVertx, options);
		Single<HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> responseHandler = client.get(443,
				"www.google.com", 
				"/robots.txt").rxSend();

		System.err.println("Got response");

		HttpResponse<io.vertx.reactivex.core.buffer.Buffer> httpResponse = Fibers.await(responseHandler);
		System.err.println("Got body");
		client.close();
		
		return Response.ok(httpResponse.body().toString()).build();
	});
}
 
Example #5
Source File: MyResource.java    From redpipe with Apache License 2.0 6 votes vote down vote up
@Path("8error")
@GET
public Single<String> hello8Error(@Context io.vertx.reactivex.core.Vertx rxVertx){
	System.err.println("Creating client");
	WebClientOptions options = new WebClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	WebClient client = WebClient.create(rxVertx, options);
	Single<HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> responseHandler = client.get(443,
			"www.google.com", 
			"/robots.txt").rxSend();

	System.err.println("Created client");
	return responseHandler
			.doAfterTerminate(() -> client.close())
			.map(body -> {
		System.err.println("Got body");
		throw new MyException();
	});
}
 
Example #6
Source File: MyResource.java    From redpipe with Apache License 2.0 6 votes vote down vote up
@Path("8user")
@Produces("text/json")
@GET
public Single<DataClass> hello8User(@Context io.vertx.reactivex.core.Vertx rxVertx){
	System.err.println("Creating client");
	WebClientOptions options = new WebClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	WebClient client = WebClient.create(rxVertx, options);
	Single<HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> responseHandler = client.get(443,
			"www.google.com", 
			"/robots.txt").rxSend();

	System.err.println("Created client");
	return responseHandler.map(body -> {
		System.err.println("Got body");
		return new DataClass(body.body().toString());
	}).doAfterTerminate(() -> client.close());
}
 
Example #7
Source File: MyResource.java    From redpipe with Apache License 2.0 6 votes vote down vote up
@Path("8")
@GET
public Single<String> hello8(@Context io.vertx.reactivex.core.Vertx rxVertx){
	System.err.println("Creating client");
	WebClientOptions options = new WebClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	WebClient client = WebClient.create(rxVertx, options);
	Single<HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> responseHandler = client.get(443,
			"www.google.com", 
			"/robots.txt").rxSend();

	System.err.println("Created client");
	return responseHandler.map(body -> {
		System.err.println("Got body");
		return body.body().toString();
	}).doAfterTerminate(() -> client.close());
}
 
Example #8
Source File: MyResource.java    From redpipe with Apache License 2.0 6 votes vote down vote up
@Path("7error")
@GET
public CompletionStage<String> hello7Error(@Context Vertx vertx){
	io.vertx.reactivex.core.Vertx rxVertx = io.vertx.reactivex.core.Vertx.newInstance(vertx);
	System.err.println("Creating client");
	WebClientOptions options = new WebClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	WebClient client = WebClient.create(rxVertx, options);
	Single<HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> responseHandler = client.get(443,
			"www.google.com", 
			"/robots.txt").rxSend();

	CompletableFuture<String> ret = new CompletableFuture<>();
	responseHandler
		.doAfterTerminate(() -> client.close())
		.subscribe(body -> {
		System.err.println("Got body");
		
		ret.completeExceptionally(new MyException());
	});
	System.err.println("Created client");
	return ret;
}
 
Example #9
Source File: MyResource.java    From redpipe with Apache License 2.0 6 votes vote down vote up
@Path("7")
@GET
public CompletionStage<String> hello7(@Context Vertx vertx){
	io.vertx.reactivex.core.Vertx rxVertx = io.vertx.reactivex.core.Vertx.newInstance(vertx);
	System.err.println("Creating client");
	WebClientOptions options = new WebClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	WebClient client = WebClient.create(rxVertx, options);
	Single<HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> responseHandler = client.get(443,
			"www.google.com", 
			"/robots.txt").rxSend();

	CompletableFuture<String> ret = new CompletableFuture<>();
	responseHandler
		.doAfterTerminate(() -> client.close())
		.subscribe(body -> {
		System.err.println("Got body");
		ret.complete(body.body().toString());
	});
	
	System.err.println("Created client");
	return ret;
}
 
Example #10
Source File: MyResource.java    From redpipe with Apache License 2.0 6 votes vote down vote up
@Path("6")
@GET
public void hello6(@Suspended final AsyncResponse asyncResponse,
	      // Inject the Vertx instance
	      @Context Vertx vertx){
	io.vertx.reactivex.core.Vertx rxVertx = io.vertx.reactivex.core.Vertx.newInstance(vertx);
	System.err.println("Creating client");
	WebClientOptions options = new WebClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	WebClient client = WebClient.create(rxVertx, options);
	Single<HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> responseHandler = client.get(443,
			"www.google.com", 
			"/robots.txt").rxSend();

	responseHandler
		.doAfterTerminate(() -> client.close())
		.subscribe(body -> {
		System.err.println("Got body");
		asyncResponse.resume(Response.ok(body.body().toString()).build());
	});
	
	System.err.println("Created client");
}
 
Example #11
Source File: PortfolioServiceImpl.java    From vertx-kubernetes-workshop with Apache License 2.0 6 votes vote down vote up
private Single<Double> getValueForCompany(WebClient client, String company, int numberOfShares) {
        //TODO
        //----

        return client.get("/?name=" + encode(company))
            .as(BodyCodec.jsonObject())
            .rxSend()
            .map(HttpResponse::body)
            .map(json -> json.getDouble("bid"))
            .map(val -> val * numberOfShares);

//        return Single.just(0.0);
        // ---


    }
 
Example #12
Source File: ApiTest.java    From redpipe with Apache License 2.0 6 votes vote down vote up
@Before
public void prepare(TestContext context) throws IOException {
	Async async = context.async();

	JsonObject config = new JsonObject().put("db_url", "jdbc:hsqldb:mem:testdb;shutdown=true")
			.put("db_max_pool_size", 4)
			.put("security_definitions", "classpath:wiki-users.properties")
			.put("scan", new JsonArray().add(AppResource.class.getPackage().getName()))
			.put("keystore", new JsonObject()
					.put("path", "keystore.jceks")
					.put("type", "jceks")
					.put("password", "secret"));
			
	server = new WikiServer();
	server.start(config)
	.subscribe(() -> {
		webClient = WebClient.create(server.getVertx(),
				new WebClientOptions().setDefaultHost("localhost").setDefaultPort(9000));
		async.complete();
	}, x -> {
		x.printStackTrace();
		context.fail(x);
		async.complete();
	});
}
 
Example #13
Source File: HttpAuthenticationProviderConfiguration.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Bean
@Qualifier("idpHttpAuthWebClient")
public WebClient httpClient() {
    WebClientOptions httpClientOptions = new WebClientOptions();
    httpClientOptions
            .setUserAgent(DEFAULT_USER_AGENT)
            .setConnectTimeout(configuration.getConnectTimeout())
            .setMaxPoolSize(configuration.getMaxPoolSize());

    if (configuration.getAuthenticationResource().getBaseURL() != null
            && configuration.getAuthenticationResource().getBaseURL().startsWith("https://")) {
        httpClientOptions.setSsl(true);
        httpClientOptions.setTrustAll(true);
    }

    return WebClient.create(vertx, httpClientOptions);
}
 
Example #14
Source File: HttpUserProviderConfiguration.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Bean
@Qualifier("idpHttpUsersWebClient")
public WebClient httpClient() {
    WebClientOptions httpClientOptions = new WebClientOptions();
    httpClientOptions
            .setUserAgent(DEFAULT_USER_AGENT)
            .setConnectTimeout(configuration.getConnectTimeout())
            .setMaxPoolSize(configuration.getMaxPoolSize());

    if (configuration.getUsersResource().getBaseURL() != null
            && configuration.getUsersResource().getBaseURL().startsWith("https://")) {
        httpClientOptions.setSsl(true);
        httpClientOptions.setTrustAll(true);
    }

    return WebClient.create(vertx, httpClientOptions);
}
 
Example #15
Source File: PortfolioServiceImpl.java    From vertx-kubernetes-workshop with Apache License 2.0 6 votes vote down vote up
private void computeEvaluation(WebClient webClient, Handler<AsyncResult<Double>> resultHandler) {
    // We need to call the service for each company in which we own shares
    Flowable.fromIterable(portfolio.getShares().entrySet())
        // For each, we retrieve the value
        .flatMapSingle(entry -> getValueForCompany(webClient, entry.getKey(), entry.getValue()))
        // We accumulate the results
        .toList()
        // And compute the sum
        .map(list -> list.stream().mapToDouble(x -> x).sum())
        // We report the result or failure
        .subscribe((sum, err) -> {
            if (err != null) {
                System.out.println("Evaluation of the portfolio failed " + err.getMessage());
                resultHandler.handle(Future.failedFuture(err));
            } else {
                System.out.println("Evaluation of the portfolio succeeeded");
                resultHandler.handle(Future.succeededFuture(sum));
            }
        });
}
 
Example #16
Source File: GetBooksHandlerTest.java    From vertx-postgresql-starter with MIT License 6 votes vote down vote up
@Before
public void setUp(TestContext testContext) {
  BookDatabaseService mockBookDatabaseService = Mockito.mock(BookDatabaseService.class);

  JsonArray mockDbResponse = new JsonArray()
    .add(new JsonObject()
      .put("id", 1)
      .put("title", "Effective Java")
      .put("category", "java")
      .put("publicationDate", "2009-01-01"))
    .add(new JsonObject()
      .put("id", 2)
      .put("title", "Thinking in Java")
      .put("category", "java")
      .put("publicationDate", "2006-02-20"));


  Mockito.when(mockBookDatabaseService.rxGetBooks(new Book())).thenReturn(Single.just(mockDbResponse));

  mockServer(1234, GET, EndPoints.GET_BOOKS, BookApis.getBooksHandler(mockBookDatabaseService), testContext);

  webClient = WebClient.create(vertx);
}
 
Example #17
Source File: ApiTest.java    From redpipe with Apache License 2.0 6 votes vote down vote up
@Before
public void prepare(TestContext context) throws IOException {
	Async async = context.async();

	server = new Server();
	server.start(//new JsonObject().put("mode", "prod"), 
			TestResource.class)
	.subscribe(() -> {
		webClient = WebClient.create(server.getVertx(),
				new WebClientOptions().setDefaultHost("localhost").setDefaultPort(9000));
		async.complete();
	}, x -> {
		x.printStackTrace();
		context.fail(x);
		async.complete();
	});
}
 
Example #18
Source File: GetBookByIdHandlerTest.java    From vertx-postgresql-starter with MIT License 6 votes vote down vote up
@Before
public void setUp(TestContext testContext) {
  BookDatabaseService mockBookDatabaseService = Mockito.mock(BookDatabaseService.class);

  JsonObject mockDbResponse = new JsonObject()
    .put("id", 1)
    .put("title", "Effective Java")
    .put("category", "java")
    .put("publicationDate", "2009-01-01");


  Mockito.when(mockBookDatabaseService.rxGetBookById(1)).thenReturn(Single.just(mockDbResponse));

  mockServer(1234, GET, EndPoints.GET_BOOK_BY_ID, BookApis.getBookByIdHandler(mockBookDatabaseService), testContext);

  webClient = WebClient.create(vertx);
}
 
Example #19
Source File: PortfolioServiceImpl.java    From vertx-kubernetes-workshop with Apache License 2.0 6 votes vote down vote up
private void computeEvaluation(WebClient webClient, Handler<AsyncResult<Double>> resultHandler) {
    // We need to call the service for each company in which we own shares
    Flowable.fromIterable(portfolio.getShares().entrySet())
        // For each, we retrieve the value
        .flatMapSingle(entry -> getValueForCompany(webClient, entry.getKey(), entry.getValue()))
        // We accumulate the results
        .toList()
        // And compute the sum
        .map(list -> list.stream().mapToDouble(x -> x).sum())
        // We report the result or failure
        .subscribe((sum, err) -> {
            if (err != null) {
                resultHandler.handle(Future.failedFuture(err));
            } else {
                resultHandler.handle(Future.succeededFuture(sum));
            }
        });
}
 
Example #20
Source File: WebClientTest.java    From vertx-rx with Apache License 2.0 6 votes vote down vote up
@Test
public void testGet() {
  int times = 5;
  waitFor(times);
  HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
  server.requestStream().handler(req -> req.response().setChunked(true).end("some_content"));
  try {
    server.listen(ar -> {
      client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
      Single<HttpResponse<Buffer>> single = client
              .get(8080, "localhost", "/the_uri")
              .as(BodyCodec.buffer())
              .rxSend();
      for (int i = 0; i < times; i++) {
        single.subscribe(resp -> {
          Buffer body = resp.body();
          assertEquals("some_content", body.toString("UTF-8"));
          complete();
        }, this::fail);
      }
    });
    await();
  } finally {
    server.close();
  }
}
 
Example #21
Source File: WebClientTest.java    From vertx-rx with Apache License 2.0 6 votes vote down vote up
@Test
public void testPost() {
  int times = 5;
  waitFor(times);
  HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
  server.requestStream().handler(req -> req.bodyHandler(buff -> {
    assertEquals("onetwothree", buff.toString());
    req.response().end();
  }));
  try {
    server.listen(ar -> {
      client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
      Observable<Buffer> stream = Observable.just(Buffer.buffer("one"), Buffer.buffer("two"), Buffer.buffer("three"));
      Single<HttpResponse<Buffer>> single = client
              .post(8080, "localhost", "/the_uri")
              .rxSendStream(stream);
      for (int i = 0; i < times; i++) {
        single.subscribe(resp -> complete(), this::fail);
      }
    });
    await();
  } finally {
    server.close();
  }
}
 
Example #22
Source File: CongratsTest.java    From vertx-in-action with MIT License 6 votes vote down vote up
@BeforeEach
void prepare(Vertx vertx, VertxTestContext testContext) {
  Map<String, String> conf = new HashMap<>();
  conf.put("bootstrap.servers", "localhost:9092");
  conf.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
  conf.put("value.serializer", "io.vertx.kafka.client.serialization.JsonObjectSerializer");
  conf.put("acks", "1");
  producer = KafkaProducer.create(vertx, conf);
  webClient = WebClient.create(vertx);
  KafkaAdminClient adminClient = KafkaAdminClient.create(vertx, conf);
  adminClient
    .rxDeleteTopics(Arrays.asList("incoming.steps", "daily.step.updates"))
    .onErrorComplete()
    .andThen(vertx.rxDeployVerticle(new CongratsVerticle()))
    .ignoreElement()
    .andThen(vertx.rxDeployVerticle(new FakeUserService()))
    .ignoreElement()
    .andThen(webClient.delete(8025, "localhost", "/api/v1/messages").rxSend())
    .ignoreElement()
    .delay(1, TimeUnit.SECONDS, RxHelper.scheduler(vertx))
    .subscribe(testContext::completeNow, testContext::failNow);
}
 
Example #23
Source File: CongratsVerticle.java    From vertx-in-action with MIT License 6 votes vote down vote up
@Override
public Completable rxStart() {
  mailClient = MailClient.createShared(vertx, MailerConfig.config());
  webClient = WebClient.create(vertx);

  KafkaConsumer.<String, JsonObject>create(vertx, KafkaConfig.consumerConfig("congrats-service"))
    .subscribe("daily.step.updates")
    .toFlowable()
    .filter(this::above10k)
    .distinct(KafkaConsumerRecord::key)
    .flatMapSingle(this::sendmail)
    .doOnError(err -> logger.error("Woops", err))
    .retryWhen(this::retryLater)
    .subscribe(mailResult -> logger.info("Congratulated {}", mailResult.getRecipients()));

  return Completable.complete();
}
 
Example #24
Source File: WebClientTest.java    From vertx-rx with Apache License 2.0 6 votes vote down vote up
@Test
public void testResponseMissingBody() throws Exception {
  int times = 5;
  waitFor(times);
  HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
  server.requestStream().handler(req -> req.response().setStatusCode(403).end());
  try {
    server.listen(ar -> {
      client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
      Single<HttpResponse<Buffer>> single = client
              .get(8080, "localhost", "/the_uri")
              .rxSend();
      for (int i = 0; i < times; i++) {
        single.subscribe(resp -> {
          assertEquals(403, resp.statusCode());
          assertNull(resp.body());
          complete();
        }, this::fail);
      }
    });
    await();
  } finally {
    server.close();
  }
}
 
Example #25
Source File: WebClientTest.java    From vertx-rx with Apache License 2.0 6 votes vote down vote up
@Test
public void testResponseBodyAsAsJsonMapped() throws Exception {
  JsonObject expected = new JsonObject().put("cheese", "Goat Cheese").put("wine", "Condrieu");
  HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
  server.requestStream().handler(req -> req.response().end(expected.encode()));
  try {
    server.listen(ar -> {
      client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
      Single<HttpResponse<WineAndCheese>> single = client
              .get(8080, "localhost", "/the_uri")
              .as(BodyCodec.json(WineAndCheese.class))
              .rxSend();
      single.subscribe(resp -> {
        assertEquals(200, resp.statusCode());
        assertEquals(new WineAndCheese().setCheese("Goat Cheese").setWine("Condrieu"), resp.body());
        testComplete();
      }, this::fail);
    });
    await();
  } finally {
    server.close();
  }
}
 
Example #26
Source File: WebClientTest.java    From vertx-rx with Apache License 2.0 6 votes vote down vote up
@Test
public void testErrorHandling() throws Exception {
  try {
    client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
    Single<HttpResponse<WineAndCheese>> single = client
            .get(-1, "localhost", "/the_uri")
            .as(BodyCodec.json(WineAndCheese.class))
            .rxSend();
    single.subscribe(resp -> fail(), error -> {
      assertEquals(IllegalArgumentException.class, error.getClass());
      testComplete();
    });
    await();
  } catch (Throwable t) {
    fail();
  }
}
 
Example #27
Source File: PortfolioServiceImpl.java    From vertx-kubernetes-workshop with Apache License 2.0 5 votes vote down vote up
@Override
public void evaluate(Handler<AsyncResult<Double>> resultHandler) {
    // TODO
    // ----
    Single<WebClient> quotes = HttpEndpoint.rxGetWebClient(discovery, rec -> rec.getName().equals("quote-generator"));
    quotes.subscribe((client, err) -> {
        if (err != null) {
            resultHandler.handle(Future.failedFuture(err));
        } else {
            computeEvaluation(client, resultHandler);
        }
    });
    // ---
}
 
Example #28
Source File: ServerExtendableTest.java    From redpipe with Apache License 2.0 5 votes vote down vote up
@Before
public void startVertxWithConfiguredVertxOptions(TestContext context) throws IOException {
    Async async = context.async();

    server = new Server() {
        @Override
        protected @NonNull
        VertxOptions configureVertxOptions(VertxOptions options) {
            return options.setWorkerPoolSize(3);
        }

        @Override
        protected AuthProvider setupAuthenticationRoutes() {
            Router router = AppGlobals.get().getRouter();
            router.get("/test").handler(context -> {
                context.response().end("OK");
            });
            return super.setupAuthenticationRoutes();
        }
    };
    server.start(new JsonObject().put("sessionDisabled", true), TestResource.class, TestResourceRxJava1.class)
            .subscribe(() -> {
                webClient = WebClient.create(server.getVertx(),
                        new WebClientOptions().setDefaultHost("localhost").setDefaultPort(9000));
                async.complete();
            }, x -> {
                x.printStackTrace();
                context.fail(x);
                async.complete();
            });
}
 
Example #29
Source File: WebClientsConfiguration.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
private WebClient createWebClient(Vertx vertx, URL url) {

        final int port = url.getPort() != -1 ? url.getPort() : (HTTPS_SCHEME.equals(url.getProtocol()) ? 443 : 80);

        WebClientOptions options = new WebClientOptions()
                .setDefaultPort(port)
                .setDefaultHost(url.getHost())
                .setKeepAlive(true)
                .setMaxPoolSize(10)
                .setTcpKeepAlive(true)
                .setConnectTimeout(httpClientTimeout)
                .setSsl(url.getProtocol().equals(HTTPS_SCHEME));

        if (this.isProxyConfigured) {
            ProxyOptions proxyOptions = new ProxyOptions();
            proxyOptions.setType(ProxyType.valueOf(httpClientProxyType));
            if (HTTPS_SCHEME.equals(url.getProtocol())) {
                proxyOptions.setHost(httpClientProxyHttpsHost);
                proxyOptions.setPort(httpClientProxyHttpsPort);
                proxyOptions.setUsername(httpClientProxyHttpsUsername);
                proxyOptions.setPassword(httpClientProxyHttpsPassword);
            } else {
                proxyOptions.setHost(httpClientProxyHttpHost);
                proxyOptions.setPort(httpClientProxyHttpPort);
                proxyOptions.setUsername(httpClientProxyHttpUsername);
                proxyOptions.setPassword(httpClientProxyHttpPassword);
            }
            options.setProxyOptions(proxyOptions);
        }

        return WebClient.create(vertx, options);
    }
 
Example #30
Source File: CommonConfiguration.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Bean
@Qualifier("oidcWebClient")
public WebClient webClient() {
    WebClientOptions options = new WebClientOptions()
            .setConnectTimeout(Integer.valueOf(environment.getProperty("oidc.http.connectionTimeout", "10")) * 1000)
            .setMaxPoolSize(Integer.valueOf(environment.getProperty("oidc.http.pool.maxTotalConnection", "200")))
            .setTrustAll(Boolean.valueOf(environment.getProperty("oidc.http.client.trustAll", "true")));

    return WebClient.create(vertx,options);
}