public void load(Handler<AsyncResult<Void>> resultHandler) { WebClientOptions options = new WebClientOptions(); if (!"none".equalsIgnoreCase(PROXY_HOST)) { options.setProxyOptions(new ProxyOptions() .setType(ProxyType.HTTP) .setHost(PROXY_HOST) .setPort(PROXY_PORT)); } String wellKnownUrl = this.config.getWellKnownUrl(); WebClient.create(this.vertx, options) .getAbs(wellKnownUrl) .ssl(wellKnownUrl.startsWith("https://") ? true : false) .send(ar -> { if (ar.succeeded()) { JsonObject response = Optional.ofNullable(ar.result().bodyAsJsonObject()).orElseGet(JsonObject::new); this.parseAndStoreWellKnownFields(response, resultHandler); } else { LOG.error("Unable to retrieve well known fields from {}", wellKnownUrl, ar.cause()); resultHandler.handle(Future.failedFuture(ar.cause())); } }); }
@Test public void testDeployUsingProxyWithOptionsSystemProperties(TestContext context) throws Exception { testDeployUsingProxy(context, () -> { System.setProperty(HttpServiceFactory.HTTP_CLIENT_OPTIONS_PROPERTY, new JsonObject() .put("proxyOptions", new JsonObject() .put("host", "localhost") .put("port", 8081) .put("type", ProxyType.HTTP.name())).encode()); System.setProperty(HttpServiceFactory.PROXY_PORT_PROPERTY, "8081"); }); }
@Override protected void doStart() throws Exception { // TODO: Prepare HttpClientOptions according to the endpoint to improve performance when creating a new // instance of the Vertx client httpClientOptions = new HttpClientOptions(); httpClientOptions.setPipelining(endpoint.getHttpClientOptions().isPipelining()); httpClientOptions.setKeepAlive(endpoint.getHttpClientOptions().isKeepAlive()); httpClientOptions.setIdleTimeout((int) (endpoint.getHttpClientOptions().getIdleTimeout() / 1000)); httpClientOptions.setConnectTimeout((int) endpoint.getHttpClientOptions().getConnectTimeout()); httpClientOptions.setUsePooledBuffers(true); httpClientOptions.setMaxPoolSize(endpoint.getHttpClientOptions().getMaxConcurrentConnections()); httpClientOptions.setTryUseCompression(endpoint.getHttpClientOptions().isUseCompression()); // Configure proxy HttpProxy proxy = endpoint.getHttpProxy(); if (proxy != null && proxy.isEnabled()) { ProxyOptions proxyOptions = new ProxyOptions(); proxyOptions.setHost(proxy.getHost()); proxyOptions.setPort(proxy.getPort()); proxyOptions.setUsername(proxy.getUsername()); proxyOptions.setPassword(proxy.getPassword()); proxyOptions.setType(ProxyType.valueOf(proxy.getType().name())); httpClientOptions.setProxyOptions(proxyOptions); } URI target = URI.create(endpoint.getTarget()); // Configure SSL HttpClientSslOptions sslOptions = endpoint.getHttpClientSslOptions(); if (sslOptions != null && sslOptions.isEnabled()) { httpClientOptions .setSsl(sslOptions.isEnabled()) .setVerifyHost(sslOptions.isHostnameVerifier()) .setTrustAll(sslOptions.isTrustAll()); if (sslOptions.getPem() != null && ! sslOptions.getPem().isEmpty()) { httpClientOptions.setPemTrustOptions( new PemTrustOptions().addCertValue( io.vertx.core.buffer.Buffer.buffer(sslOptions.getPem()))); } } else if(HTTPS_SCHEME.equalsIgnoreCase(target.getScheme())) { // SSL is not configured but the endpoint scheme is HTTPS so let's enable the SSL on Vert.x HTTP client // automatically httpClientOptions.setSsl(true).setTrustAll(true); } printHttpClientConfiguration(httpClientOptions); }