@Test public void testWebsocketPauseAndResume() { client.close(); client = vertx.createHttpClient(new HttpClientOptions().setConnectTimeout(1000)); this.server = vertx.createHttpServer(new HttpServerOptions().setAcceptBacklog(1).setPort(DEFAULT_HTTP_PORT)); AtomicBoolean paused = new AtomicBoolean();
options.setTrustOptions(trustOptions); options.addEnabledCipherSuite(enabledCipher); options.setConnectTimeout(connectTimeout); options.setTrustAll(trustAll); options.addCrlPath(crlPath);
@Override public HttpClientOptions createHttpClientOptions() { HttpVersion ver = ServiceRegistryConfig.INSTANCE.getHttpVersion(); HttpClientOptions httpClientOptions = new HttpClientOptions(); httpClientOptions.setProtocolVersion(ver); httpClientOptions.setConnectTimeout(ServiceRegistryConfig.INSTANCE.getConnectionTimeout()); httpClientOptions.setIdleTimeout(ServiceRegistryConfig.INSTANCE.getIdleWatchTimeout()); if (ver == HttpVersion.HTTP_2) { LOGGER.debug("service center ws client protocol version is HTTP/2"); httpClientOptions.setHttp2ClearTextUpgrade(false); } if (ServiceRegistryConfig.INSTANCE.isSsl()) { LOGGER.debug("service center ws client performs requests over TLS"); VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions); } return httpClientOptions; } }
@Override public RestClientOptions setConnectTimeout(int connectTimeout) { super.setConnectTimeout(connectTimeout); return this; }
private void connect(final Runnable runnable) { final HttpClientOptions httpClientOptions = new HttpClientOptions(); final JksOptions jksOptions = new JksOptions(); jksOptions.setPath(trustStorePath).setPassword(trustStorePassword); httpClientOptions.setDefaultHost(host).setDefaultPort(port) .setConnectTimeout(timeOutInMilliseconds) .setMaxPoolSize(poolSize) .setKeepAlive(keepAlive) .setPipelining(pipeline) .setSoLinger(soLinger) .setTcpNoDelay(tcpNoDelay) .setTryUseCompression(tryUseCompression) .setSsl(ssl) .setTrustAll(trustAll) .setVerifyHost(verifyHost) .setMaxWebsocketFrameSize(maxWebSocketFrameSize) .setUsePooledBuffers(true); httpClient = vertx.createHttpClient(httpClientOptions); if (debug) logger.debug("HTTP CLIENT: connect:: \nhost {} \nport {}\n", host, port); closed.set(false); Sys.sleep(100); if (runnable != null) runnable.run(); }
private HttpClientOptions createHttpClientOptions() { HttpClientOptions httpClientOptions = new HttpClientOptions(); if (ConfigCenterConfig.INSTANCE.isProxyEnable()) { ProxyOptions proxy = new ProxyOptions() .setHost(ConfigCenterConfig.INSTANCE.getProxyHost()) .setPort(ConfigCenterConfig.INSTANCE.getProxyPort()) .setUsername(ConfigCenterConfig.INSTANCE.getProxyUsername()) .setPassword(Encryptions.decode(ConfigCenterConfig.INSTANCE.getProxyPasswd(), PROXY_KEY)); httpClientOptions.setProxyOptions(proxy); } httpClientOptions.setConnectTimeout(CONFIG_CENTER_CONFIG.getConnectionTimeout()); if (this.memberDiscovery.getConfigServer().toLowerCase().startsWith("https")) { LOGGER.debug("config center client performs requests over TLS"); SSLOptionFactory factory = SSLOptionFactory.createSSLOptionFactory(SSL_KEY, ConfigCenterConfig.INSTANCE.getConcurrentCompositeConfiguration()); SSLOption sslOption; if (factory == null) { sslOption = SSLOption.buildFromYaml(SSL_KEY, ConfigCenterConfig.INSTANCE.getConcurrentCompositeConfiguration()); } else { sslOption = factory.createSSLOption(); } SSLCustom sslCustom = SSLCustom.createSSLCustom(sslOption.getSslCustomClass()); VertxTLSBuilder.buildHttpClientOptions(sslOption, sslCustom, httpClientOptions); } return httpClientOptions; }
@Test public void testWebsocketPauseAndResume() { client.close(); client = vertx.createHttpClient(new HttpClientOptions().setConnectTimeout(1000)); this.server = vertx.createHttpServer(new HttpServerOptions().setAcceptBacklog(1).setPort(DEFAULT_HTTP_PORT)); AtomicBoolean paused = new AtomicBoolean();
@Override public HttpClientOptions createHttpClientOptions() { HttpVersion ver = ServiceRegistryConfig.INSTANCE.getHttpVersion(); HttpClientOptions httpClientOptions = new HttpClientOptions(); httpClientOptions.setProtocolVersion(ver); httpClientOptions.setConnectTimeout(ServiceRegistryConfig.INSTANCE.getConnectionTimeout()); httpClientOptions.setIdleTimeout(ServiceRegistryConfig.INSTANCE.getIdleConnectionTimeout()); if (ServiceRegistryConfig.INSTANCE.isProxyEnable()) { ProxyOptions proxy = new ProxyOptions(); proxy.setHost(ServiceRegistryConfig.INSTANCE.getProxyHost()); proxy.setPort(ServiceRegistryConfig.INSTANCE.getProxyPort()); proxy.setUsername(ServiceRegistryConfig.INSTANCE.getProxyUsername()); proxy.setPassword(Encryptions.decode(ServiceRegistryConfig.INSTANCE.getProxyPasswd(), PROXY_KEY)); httpClientOptions.setProxyOptions(proxy); } if (ver == HttpVersion.HTTP_2) { LOGGER.debug("service center client protocol version is HTTP/2"); httpClientOptions.setHttp2ClearTextUpgrade(false); } if (ServiceRegistryConfig.INSTANCE.isSsl()) { LOGGER.debug("service center client performs requests over TLS"); VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions); } return httpClientOptions; } }
@Test public void test(TestContext testContext) { HttpClient client = vertx.createHttpClient(new HttpClientOptions() .setConnectTimeout(10000)); Async async = testContext.async(); client.getNow(PORT, "127.0.0.1", "/test", testContext.asyncAssertSuccess(httpClientResponse -> { testContext.assertEquals(HttpURLConnection.HTTP_NO_CONTENT, httpClientResponse.statusCode()); async.complete(); })); }
assertEquals(options, options.setConnectTimeout(rand)); assertEquals(rand, options.getConnectTimeout()); assertIllegalArgumentException(() -> options.setConnectTimeout(-2));
httpClientOptions .setIdleTimeout((int) (endpoint.getHttpClientOptions().getIdleTimeout() / 1000)) .setConnectTimeout((int) endpoint.getHttpClientOptions().getConnectTimeout()) .setTryUseCompression(endpoint.getHttpClientOptions().isUseCompression());
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());
options.setTrustOptions(trustOptions); options.addEnabledCipherSuite(enabledCipher); options.setConnectTimeout(connectTimeout); options.setTrustAll(trustAll); options.addCrlPath(crlPath);
/** * Sets request options using Feign {@link Request.Options}. * * @param options Feign {@code Request.Options} object * * @return this builder */ @Override public Builder options(final Request.Options options) { checkNotNull(options, "Argument options must be not null"); this.options = new HttpClientOptions() .setConnectTimeout(options.connectTimeoutMillis()) .setIdleTimeout(options.readTimeoutMillis()); return this; }
@Override public HttpClient load(ApimanHttpConnectorOptions opts) throws Exception { HttpClientOptions vxClientOptions = HttpClientOptionsFactory.parseTlsOptions(opts.getTlsOptions(), opts.getUri()) .setConnectTimeout(opts.getConnectionTimeout()) .setIdleTimeout(opts.getIdleTimeout()) .setKeepAlive(opts.isKeepAlive()) .setTryUseCompression(opts.isTryUseCompression()); return vertx.createHttpClient(vxClientOptions); } });
public HttpClientOptions buildHttpClientOptions() { final HttpClientOptions options = new HttpClientOptions() .setDefaultHost (getHost ()) .setDefaultPort (getPort ()) .setMaxPoolSize (getPoolSize()) .setConnectTimeout(getTimeout ()) .setKeepAlive (isKeepAlive()) .setPipelining (false ) ; if ("https".equals(getScheme())) { options.setSsl(true).setVerifyHost(false).setTrustAll(true); } return options; }
/** * Test what happens if the first host is unreachable */ @Test public void retrySecondHost(TestContext ctx) { client.setDefaultOptions(new HttpClientOptions().setConnectTimeout(500)); client.setHosts(Arrays.asList( URI.create("http://192.0.2.0:80"), URI.create("http://localhost:" + wireMockRule2.port()))); Async async = ctx.async(); client.performRequest("/") .doOnSuccess(o -> ctx.assertEquals(expected2, o)) .subscribe(o -> async.complete()); }
@Test public void testCreateServer() throws Exception { HttpClientOptions options = new HttpClientOptions().setConnectTimeout(300); vertx.createHttpClient(options) .request(HttpMethod.GET, port, host, "/integration/test", response -> { assertEquals(200, response.statusCode()); testComplete(); }) .exceptionHandler(t -> fail(t.getMessage())) .end(); await(); }
@Test public void test(TestContext testContext) { HttpClient client = vertx.createHttpClient(new HttpClientOptions() .setConnectTimeout(10000)); Async async = testContext.async(); HttpClientRequest httpClientRequest = client.get(PORT, "127.0.0.1", "/test", httpClientResponse -> { testContext.assertEquals(HttpURLConnection.HTTP_NO_CONTENT, httpClientResponse.statusCode()); async.complete(); }).exceptionHandler(testContext::fail); httpClientRequest.end(); }
assertEquals(options, options.setConnectTimeout(rand)); assertEquals(rand, options.getConnectTimeout()); assertIllegalArgumentException(() -> options.setConnectTimeout(-2));