@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(); } }); } }
@Override protected void connect() { this.client = WebClient.create(vertx, new WebClientOptions() .setSsl(false) .setTrustAll(true) .setVerifyHost(false)); }
new WebClientOptions() .setTrustAll(true) .setSsl(configuration.getBoolean("ssl", true)) .setDefaultHost(host) .setDefaultPort(port) .setFollowRedirects(true) );
return fiber(() -> { WebClient webClient = WebClient.create(vertx, new WebClientOptions() .setSsl(true) .setUserAgent("vert-x3")); String clientId = session.get("github_client_id"); String clientSecret = session.get("github_client_secret");
@Bean public WebClient httpClient() { WebClientOptions httpClientOptions = new WebClientOptions(); httpClientOptions .setUserAgent(DEFAULT_USER_AGENT) .setConnectTimeout(Integer.valueOf(properties.getProperty("identities.oauth2.http.connectionTimeout", DEFAULT_CONNECTION_TIMEOUT)) * 1000) .setMaxPoolSize(Integer.valueOf(properties.getProperty("identities.oauth2.http.pool.maxTotalConnection", DEFAULT_MAX_TOTAL_CONNECTION))); return WebClient.create(vertx, httpClientOptions); } }
private void init() { address = DEFAULT_ADDRESS; clientOptions = new WebClientOptions(); services = new ArrayList<>(); customHttpHeader = null; }
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; }
@Bean public WebClient webClient() { WebClientOptions options = new WebClientOptions() .setConnectTimeout(Integer.valueOf(properties.getProperty("oidc.http.connectionTimeout", DEFAULT_CONNECTION_TIMEOUT)) * 1000) .setMaxPoolSize(Integer.valueOf(properties.getProperty("oidc.http.pool.maxTotalConnection", DEFAULT_MAX_TOTAL_CONNECTION))) .setTrustAll(Boolean.valueOf(properties.getProperty("oidc.http.client.trustAll", "true"))); return WebClient.create(vertx,options); } }
@Test public void testToJson() { WebClientOptions options = new WebClientOptions() .setDefaultPort(4848) .setMaxPoolSize(50) .setUserAgentEnabled(false); JsonObject json = options.toJson(); assertEquals(4848, (int) json.getInteger("defaultPort")); assertEquals(50, (int) json.getInteger("maxPoolSize")); assertEquals(false, json.getBoolean("userAgentEnabled")); } }
/** * Creates an instance of {@link SlimVaultClient}. * * @param vertx the vert.x instance * @param configuration the configuration. This configuration can contain the underlying Web Client configuration. */ public SlimVaultClient(Vertx vertx, JsonObject configuration) { String host = configuration.getString("host"); Integer port = configuration.getInteger("port", 8200); Objects.requireNonNull(host, "The Vault host must be set"); client = WebClient.create(vertx, new WebClientOptions(configuration) .setDefaultPort(port).setDefaultHost(host) ); setToken(configuration.getString("token")); }
@Test public void testCustomUserAgent() throws Exception { client = WebClient.wrap(super.client, new WebClientOptions().setUserAgent("smith")); testRequest(client -> client.get("somehost", "somepath"), req -> assertEquals(Collections.singletonList("smith"), req.headers().getAll(HttpHeaders.USER_AGENT))); }
@Test public void testFromJson() { JsonObject json = new JsonObject() .put("defaultPort", 4848) .put("userAgentEnabled", false) .put("maxPoolSize", 50); WebClientOptions options = new WebClientOptions(json); assertEquals(4848, options.getDefaultPort()); assertFalse(options.isUserAgentEnabled()); assertEquals("Vert.x-WebClient/" + VersionCommand.getVersion(), options.getUserAgent()); assertEquals(50, options.getMaxPoolSize()); }
@Test public void testHttpProxyFtpRequest() throws Exception { startProxy(null, ProxyType.HTTP); proxy.setForceUri("http://" + DEFAULT_HTTP_HOST + ":" + DEFAULT_HTTP_PORT); server.requestHandler(req -> req.response().setStatusCode(200).end()); startServer(); WebClientOptions options = new WebClientOptions(); options.setProxyOptions(new ProxyOptions().setPort(proxy.getPort())); WebClient client = WebClient.create(vertx, options); client .getAbs("ftp://ftp.gnu.org/gnu/") .send(ar -> { if (ar.succeeded()) { // Obtain response HttpResponse<Buffer> response = ar.result(); assertEquals(200, response.statusCode()); assertEquals("ftp://ftp.gnu.org/gnu/", proxy.getLastUri()); testComplete(); } else { fail(ar.cause()); } }); await(); }
@Test public void testUserAgentDisabled() throws Exception { client = WebClient.wrap(super.client, new WebClientOptions().setUserAgentEnabled(false)); testRequest(client -> client.get("somehost", "somepath"), req -> assertEquals(Collections.emptyList(), req.headers().getAll(HttpHeaders.USER_AGENT))); }
/** * Set whether SSL/TLS is enabled * * @param ssl true if enabled * @return reference to this, for fluency */ public ConsulClientOptions setSsl(boolean ssl) { super.setSsl(ssl); return this; }
/** * Set whether all server certificates should be trusted * * @param trustAll true if all should be trusted * @return reference to this, for fluency */ public ConsulClientOptions setTrustAll(boolean trustAll) { super.setTrustAll(trustAll); return this; }
/** * Sets the Web Client user agent header. Defaults to Vert.x-WebClient/<version>. * * @param userAgent user agent header value * @return a reference to this, so the API can be used fluently */ @Override public ConsulClientOptions setUserAgent(String userAgent) { return (ConsulClientOptions) super.setUserAgent(userAgent); }
/** * Set the default host name to be used by this client in requests if none is provided when making the request. * * @return a reference to this, so the API can be used fluently */ @Override public ConsulClientOptions setDefaultHost(String defaultHost) { return (ConsulClientOptions) super.setDefaultHost(defaultHost); }
/** * Set the default port to be used by this client in requests if none is provided when making the request. * * @return a reference to this, so the API can be used fluently */ @Override public ConsulClientOptions setDefaultPort(int defaultPort) { return (ConsulClientOptions) super.setDefaultPort(defaultPort); }
/** * Set the maximum pool size for connections * * @param maxPoolSize the maximum pool size * @return a reference to this, so the API can be used fluently */ @Override public ConsulClientOptions setMaxPoolSize(int maxPoolSize) { return (ConsulClientOptions) super.setMaxPoolSize(maxPoolSize); }