.splitToList(httpProxyUri.getUserInfo()); if (list.size() == 2) { clientBuilder.proxyAuthenticator(new ProxyAuthenticator(list.get(0), list.get(1)));
builder.proxyAuthenticator((route, response) -> { if (response.request().header(PROXY_AUTHORIZATION) != null) {
private void setProxy(OkHttpClient.Builder builder) { ProxyConfiguration config = proxyConfigurationService.getConfiguration(); if (!config.getProxyType().equals(Proxy.Type.DIRECT)) { final Proxy proxy = config.createProxy(); builder.proxy(proxy); if (config.hasCredential()){ builder.proxyAuthenticator((route, response) -> { final String credential= Credentials.basic(config.getProxyUserName(), config.getProxyUserPassword()); return response.request().newBuilder() .header("Proxy-Authorization", credential) .build(); }); } } }
public Client(final String key, final String appIdentifier, final String proxy) { OkHttpClient.Builder builder = new OkHttpClient.Builder(); if (proxy != null) { try { URL url = new URL(proxy); Proxy proxyAddress = createProxyAddress(url); Authenticator proxyAuthenticator = createProxyAuthenticator(url); if (proxyAddress != null) { builder.proxy(proxyAddress); if (proxyAuthenticator != null) { builder.proxyAuthenticator(proxyAuthenticator); } } } catch (java.lang.Exception e) { throw new ConnectionException("Invalid proxy: " + e.getMessage(), e); } } builder.sslSocketFactory(TLSContext.socketFactory, TLSContext.trustManager); builder.connectTimeout(0, TimeUnit.SECONDS); builder.readTimeout(0, TimeUnit.SECONDS); builder.writeTimeout(0, TimeUnit.SECONDS); client = builder.build(); credentials = Credentials.basic("api", key); if (appIdentifier == null) { userAgent = USER_AGENT; } else { userAgent = USER_AGENT + " " + appIdentifier; } }
httpClient.proxyAuthenticator(pubnub.getConfiguration().getProxyAuthenticator());
protected OkHttpClient createHTTPClient() { Proxy proxy = Proxy.NO_PROXY; Authenticator auth = Authenticator.NONE; try { String proxyHost = System.getProperty(PROXY_HOST); if (!StringUtils.isBlank(proxyHost)) { logger.info("Using http.proxyHost = " + proxyHost); int proxyPort = getProxyPort(); proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)); auth = createAuthenticator(); } HttpLoggingInterceptor httpLog = new HttpLoggingInterceptor(new HttpLogger(logger)); httpLog.setLevel(HttpLoggingInterceptor.Level.BODY); return new OkHttpClient.Builder() .addInterceptor(new RetryInterceptor(logger)) .addInterceptor(httpLog) .connectTimeout(10, TimeUnit.SECONDS) .readTimeout(60, TimeUnit.SECONDS) .proxy(proxy) .proxyAuthenticator(auth).build(); } catch (Exception ex) { logger.warn("ERROR Instantiating HTTPClient. Exception received: " + ex.getMessage(), ex); throw new RuntimeException("ERROR Instantiating HTTPClient. Exception received: " + ex.getMessage(), ex); } }
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(); }
public HttpClient build() { OkHttpClient.Builder okClient = new OkHttpClient.Builder() // make the default values of OkHttp explicit .followRedirects(true) .followSslRedirects(true) .retryOnConnectionFailure(true) // super high timeouts because Orchestrator targets build environments // (that are known to be slow or often under pressure...) .connectTimeout(30L, TimeUnit.SECONDS) .readTimeout(5L, TimeUnit.MINUTES) .writeTimeout(5L, TimeUnit.MINUTES); // OkHttp detects 'http.proxyHost' java property, but credentials should be filled String proxyLogin = system.getProperty("http.proxyUser"); if (!isEmpty(system.getProperty("http.proxyHost")) && !isEmpty(proxyLogin)) { okClient.proxyAuthenticator(new ProxyAuthenticator(proxyLogin, system.getProperty("http.proxyPassword"))); } return new HttpClient(okClient.build()); } }
/** * Constructs an {@link EventSource} using the builder's current properties. * @return the new EventSource instance */ public EventSource build() { if (proxy != null) { clientBuilder.proxy(proxy); } try { clientBuilder.sslSocketFactory(new ModernTLSSocketFactory(), defaultTrustManager()); } catch (GeneralSecurityException e) { // TLS is not available, so don't set up the socket factory, swallow the exception } if (proxyAuthenticator != null) { clientBuilder.proxyAuthenticator(proxyAuthenticator); } return new EventSource(this); }
@Override public Builder proxyAuthentication(String proxyUserName, String proxyUserPassword) { final String userName = proxyUserName; final String password = proxyUserPassword; builder.proxyAuthenticator( new Authenticator() { @Override public Request authenticate(Route route, Response response) throws IOException { String credential = Credentials.basic(userName, password); return response .request() .newBuilder() .header("Proxy-Authorization", credential) .build(); } }); return this; }
@Override public OkHttpClient getClient() { Builder clientBuilder = new OkHttpClient.Builder(); // TimeOuts clientBuilder.connectTimeout(connectionTimeout, TimeUnit.SECONDS); clientBuilder.readTimeout(2 * connectionTimeout, TimeUnit.SECONDS); // Own Cookie Jar clientBuilder.cookieJar(new SaveAllCookieJar()); // HTTP Proxy clientBuilder.proxy(new Proxy(type, new InetSocketAddress(host, port))); // Authentication if (StringUtils.isNotEmpty(login)) { clientBuilder.proxyAuthenticator(new ProxyBasicAuthenticator(login, pass)); } return clientBuilder.build(); }
public OkHttpClient getClient() { Builder clientBuilder = new OkHttpClient.Builder(); // TimeOuts clientBuilder.connectTimeout(connectionTimeout, TimeUnit.SECONDS); clientBuilder.readTimeout(2 * connectionTimeout, TimeUnit.SECONDS); // HTTP Proxy clientBuilder.proxy(new Proxy(type, new InetSocketAddress(host, port))); // Authentication if (StringUtils.isNotEmpty(login)) { clientBuilder.proxyAuthenticator(new ProxyBasicAuthenticator(login, pass)); } return clientBuilder.build(); }
@Override public void setProxyAuthentication(PasswordAuthentication proxyAuthentication) { clientBuilder.proxyAuthenticator(new ProxyAuthenticator(Credentials.basic (proxyAuthentication.getUserName(), new String(proxyAuthentication.getPassword()) ))); }
private OkHttpClient givenHttpClientWithProxyAuth(Authenticator authenticator) { return new OkHttpClient.Builder() .proxy(proxy) .proxyAuthenticator(authenticator) .addNetworkInterceptor(LOGGING_INTERCEPTOR) .build(); }
public FastHttpClientBuilder proxyAuthenticator(Authenticator proxyAuthenticator) { builder.proxyAuthenticator(proxyAuthenticator); return this; }
/** * Sets the proxy authenticator for the HTTP client. * * @param proxyAuthenticator the proxy authenticator to use * @return the builder itself for chaining */ public Builder withProxyAuthenticator(Authenticator proxyAuthenticator) { httpClientBuilder.proxyAuthenticator(proxyAuthenticator); return this; }
httpClientBuilder.proxyAuthenticator(new Authenticator() { @Override public Request authenticate(Route route, Response response) throws IOException {
if (proxyConfig.hasCredential()) { ProxyAuthenticator proxyAuthenticator = new ProxyAuthenticator(proxyConfig.getProxyUserName(), proxyConfig.getProxyUserPassword()); okHttpClientBuilder.proxyAuthenticator(proxyAuthenticator);
okHttpClient.proxyAuthenticator(new Authenticator() { @Override public Request authenticate(Route route, Response response) throws IOException {
@Override public Builder proxyAuthentication(String proxyUserName, String proxyUserPassword) { final String userName = proxyUserName; final String password = proxyUserPassword; builder.proxyAuthenticator( new Authenticator() { @Override public Request authenticate(Route route, Response response) throws IOException { String credential = Credentials.basic(userName, password); return response .request() .newBuilder() .header("Proxy-Authorization", credential) .build(); } }); return this; }