@Test public void testNewClientWithProxySettings() { String host = "localhost"; int port = 8080; ProxySettings proxySettings = ProxySettings.useProxy(host, port); HttpClientConfig config = HttpClientConfig.basicConfig() .withProxySettings(proxySettings); HttpClientImpl client = createClient(config); Proxy proxy = client.getClient().proxy(); assertThat(proxy).isNotNull(); assertThat(proxy.address()).isInstanceOf(InetSocketAddress.class); InetSocketAddress address = (InetSocketAddress) proxy.address(); assertThat(address.getHostName()).isEqualTo(host); assertThat(address.getPort()).isEqualTo(port); assertThat(proxy.type()).isEqualTo(Proxy.Type.HTTP); }
private static OkHttpClient createClient(HttpClientConfig config) { OkHttpClient.Builder builder = new OkHttpClient.Builder(); if (config.proxySettings().isProxyUse()) { Proxy proxy = createProxy(config.proxySettings()); builder.proxy(proxy); } if (unverifiedSSLCertificate()) { builder.hostnameVerifier((s, sslSession) -> true); } return builder.build(); }
HttpClientFactoryImpl implements HttpClientFactory { private static OkHttpClient createClient(HttpClientConfig config) { OkHttpClient.Builder builder = new OkHttpClient.Builder(); if (config.proxySettings().isProxyUse()) { Proxy proxy = createProxy(config.proxySettings()); builder.proxy(proxy); } if (unverifiedSSLCertificate()) { builder.hostnameVerifier((s, sslSession) -> true); } return builder.build(); } }
HttpClientFactoryImpl implements HttpClientFactory { private static OkHttpClient createClient(HttpClientConfig config) { OkHttpClient.Builder builder = new OkHttpClient.Builder(); if (config.proxySettings().isProxyUse()) { Proxy proxy = createProxy(config.proxySettings()); builder.proxy(proxy); } if (unverifiedSSLCertificate()) { builder.hostnameVerifier((s, sslSession) -> true); } return builder.build(); }  }
HttpClientFactoryImpl implements HttpClientFactory { private static OkHttpClient createClient(HttpClientConfig config) { OkHttpClient.Builder builder = new OkHttpClient.Builder(); if (config.proxySettings().isProxyUse()) { Proxy proxy = createProxy(config.proxySettings()); builder.proxy(proxy); } if (unverifiedSSLCertificate()) { builder.hostnameVerifier((s, sslSession) -> true); } return builder.build(); }  @Override HttpClient newHttpClient(HttpClientConfig config); }
HttpClientFactoryImpl implements HttpClientFactory { private static OkHttpClient createClient(HttpClientConfig config) { OkHttpClient.Builder builder = new OkHttpClient.Builder(); if (config.proxySettings().isProxyUse()) { Proxy proxy = createProxy(config.proxySettings()); builder.proxy(proxy); } if (unverifiedSSLCertificate()) { builder.hostnameVerifier((s, sslSession) -> true); } return builder.build(); }  @Override HttpClient newHttpClient(HttpClientConfig config);  }