@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof Proxy) { Proxy p = (Proxy) obj; return (host != null ? host.equals(p.getHost()) : p.getHost() == null) && port == p.getPort() && (username != null ? username.equals(p.getUsername()) : p.getUsername() == null) && (password != null ? password.equals(p.getPassword()) : p.getPassword() == null) && authenticationRequired == p.authenticationRequired; } return false; } }
private static OkHttpClient createOkHttpClient(ClientConfiguration clientConfiguration) { OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder(); clientBuilder.connectTimeout(clientConfiguration.getConnectionTimeout(), TimeUnit.SECONDS); clientBuilder.readTimeout(clientConfiguration.getConnectionTimeout(), TimeUnit.SECONDS); clientBuilder.writeTimeout(clientConfiguration.getConnectionTimeout(), TimeUnit.SECONDS); clientBuilder.cookieJar(CookieJar.NO_COOKIES); clientBuilder.retryOnConnectionFailure(false); // handled by SDK final Proxy sdkProxy = clientConfiguration.getProxy(); if (sdkProxy != null) { java.net.Proxy proxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress(sdkProxy.getHost(), sdkProxy.getPort())); clientBuilder.proxy(proxy); if (sdkProxy.isAuthenticationRequired()) { clientBuilder.proxyAuthenticator((route, response) -> { String credential = Credentials.basic(sdkProxy.getUsername(), sdkProxy.getPassword()); return response.request().newBuilder() .header("Proxy-Authorization", credential) .build(); }); } } return clientBuilder.build(); }
@Override public AuthenticationClientBuilder setProxy(Proxy proxy) { if (proxy == null) { throw new IllegalArgumentException("proxy argument cannot be null."); } clientConfig.setProxyHost(proxy.getHost()); clientConfig.setProxyPort(proxy.getPort()); clientConfig.setProxyUsername(proxy.getUsername()); clientConfig.setProxyPassword(proxy.getPassword()); return this; }
@Override public ClientBuilder setProxy(Proxy proxy) { if (proxy == null) { throw new IllegalArgumentException("proxy argument cannot be null."); } clientConfig.setProxyHost(proxy.getHost()); clientConfig.setProxyPort(proxy.getPort()); clientConfig.setProxyUsername(proxy.getUsername()); clientConfig.setProxyPassword(proxy.getPassword()); return this; }
@Override public ClientBuilder setProxy(Proxy proxy) { if (proxy == null) { throw new IllegalArgumentException("proxy argument cannot be null."); } clientConfig.setProxyHost(proxy.getHost()); clientConfig.setProxyPort(proxy.getPort()); clientConfig.setProxyUsername(proxy.getUsername()); clientConfig.setProxyPassword(proxy.getPassword()); return this; }
HttpHost httpProxyHost = new HttpHost(proxy.getHost(), proxy.getPort()); httpClientBuilder.setProxy(httpProxyHost); AuthScope authScope = new AuthScope(proxy.getHost(), proxy.getPort()); Credentials credentials = new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword()); CredentialsProvider credentialsProviderProvider = new BasicCredentialsProvider();
HttpHost httpProxyHost = new HttpHost(proxy.getHost(), proxy.getPort()); httpClientBuilder.setProxy(httpProxyHost); AuthScope authScope = new AuthScope(proxy.getHost(), proxy.getPort()); Credentials credentials = new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword()); CredentialsProvider credentialsProviderProvider = new BasicCredentialsProvider();