private void bindOkHttpClient() { mOkHttpClient.setSslSocketFactory(mSSLSocketFactory); mOkHttpClient.setHostnameVerifier(mHostnameVerifier); mOkHttpClient.setProxy(mProxy); mOkHttpClient.setConnectTimeout(mConnectTimeout, TimeUnit.MILLISECONDS); mOkHttpClient.setReadTimeout(mReadTimeout, TimeUnit.MILLISECONDS); mOkHttpClient.setWriteTimeout(mWriteTimeout, TimeUnit.MILLISECONDS); if (!mPinners.isEmpty()) { Set<Map.Entry<String, String>> sets = mPinners.entrySet(); CertificatePinner.Builder cBuilder = new CertificatePinner.Builder(); for (Map.Entry<String, String> entry : sets) { cBuilder.add(entry.getKey(), entry.getValue()); } mOkHttpClient.setCertificatePinner(cBuilder.build()); } }
private void bindOkHttpClient() { mRequestEngine.okHttpClient.setSslSocketFactory(mSSLSocketFactory); mRequestEngine.okHttpClient.setHostnameVerifier(mHostnameVerifier); mRequestEngine.okHttpClient.setProxy(mProxy); mRequestEngine.okHttpClient.setConnectTimeout(mConnectTimeout, TimeUnit.MILLISECONDS); mRequestEngine.okHttpClient.setReadTimeout(mReadTimeout, TimeUnit.MILLISECONDS); mRequestEngine.okHttpClient.setWriteTimeout(mWriteTimeout, TimeUnit.MILLISECONDS); if (!mPinners.isEmpty()) { Set<Map.Entry<String, String>> sets = mPinners.entrySet(); CertificatePinner.Builder cBuilder = new CertificatePinner.Builder(); for (Map.Entry<String, String> entry : sets) { cBuilder.add(entry.getKey(), entry.getValue()); } mRequestEngine.okHttpClient.setCertificatePinner(cBuilder.build()); } }
/** * @return a new http client */ private OkHttpClient createHttpClient() { OkHttpClient client = new OkHttpClient(); client.setReadTimeout(connectorOptions.getReadTimeout(), TimeUnit.SECONDS); client.setWriteTimeout(connectorOptions.getWriteTimeout(), TimeUnit.SECONDS); client.setConnectTimeout(connectorOptions.getConnectTimeout(), TimeUnit.SECONDS); client.setFollowRedirects(connectorOptions.isFollowRedirects()); client.setFollowSslRedirects(connectorOptions.isFollowRedirects()); client.setProxySelector(ProxySelector.getDefault()); client.setCookieHandler(CookieHandler.getDefault()); client.setCertificatePinner(CertificatePinner.DEFAULT); client.setAuthenticator(AuthenticatorAdapter.INSTANCE); client.setConnectionPool(ConnectionPool.getDefault()); client.setProtocols(Util.immutableList(Protocol.HTTP_1_1)); client.setConnectionSpecs(DEFAULT_CONNECTION_SPECS); client.setSocketFactory(SocketFactory.getDefault()); Internal.instance.setNetwork(client, Network.DEFAULT); return client; }
/** * Constructor. * @param metricsServer */ public HawkularMetricsClient(URL metricsServer) { this.serverUrl = metricsServer; httpClient = new OkHttpClient(); httpClient.setReadTimeout(DEFAULT_READ_TIMEOUT, TimeUnit.SECONDS); httpClient.setWriteTimeout(DEFAULT_WRITE_TIMEOUT, TimeUnit.SECONDS); httpClient.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT, TimeUnit.SECONDS); httpClient.setFollowRedirects(true); httpClient.setFollowSslRedirects(true); httpClient.setProxySelector(ProxySelector.getDefault()); httpClient.setCookieHandler(CookieHandler.getDefault()); httpClient.setCertificatePinner(CertificatePinner.DEFAULT); httpClient.setAuthenticator(AuthenticatorAdapter.INSTANCE); httpClient.setConnectionPool(ConnectionPool.getDefault()); httpClient.setProtocols(Util.immutableList(Protocol.HTTP_1_1)); httpClient.setConnectionSpecs(DEFAULT_CONNECTION_SPECS); httpClient.setSocketFactory(SocketFactory.getDefault()); Internal.instance.setNetwork(httpClient, Network.DEFAULT); }
private static Address createAddress(OkHttpClient client, Request request) { SSLSocketFactory sslSocketFactory = null; HostnameVerifier hostnameVerifier = null; CertificatePinner certificatePinner = null; if (request.isHttps()) { sslSocketFactory = client.getSslSocketFactory(); hostnameVerifier = client.getHostnameVerifier(); certificatePinner = client.getCertificatePinner(); } return new Address(request.httpUrl().host(), request.httpUrl().port(), client.getDns(), client.getSocketFactory(), sslSocketFactory, hostnameVerifier, certificatePinner, client.getAuthenticator(), client.getProxy(), client.getProtocols(), client.getConnectionSpecs(), client.getProxySelector()); }