private OkHttpClient createClient() { OkHttpClient client = new OkHttpClient(); client.setFollowProtocolRedirects(followRedirects); if (connectTimeout != DEFAULT_TIMEOUT) { client.setConnectTimeout(connectTimeout, SECONDS); } if (readTimeout != DEFAULT_TIMEOUT) { client.setReadTimeout(readTimeout, SECONDS); } if (allowInsecure) { client.setSslSocketFactory(createInsecureSslSocketFactory()); } // If we don't set this reference, there's no way to clean shutdown persistent connections. client.setConnectionPool(ConnectionPool.getDefault()); return client; }
/** * @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 OkHttpClient createDefaultHttpClient() { OkHttpClient httpClient = new OkHttpClient(); httpClient.setConnectTimeout(10, TimeUnit.SECONDS); httpClient.setReadTimeout(10, TimeUnit.SECONDS); httpClient.setWriteTimeout(20, TimeUnit.SECONDS); httpClient.setConnectionPool(new ConnectionPool(20, 2 * 60 * 1000)); return httpClient; }
public RouteSelector(Address address, URI uri, ProxySelector proxySelector, ConnectionPool pool, Dns dns, RouteDatabase routeDatabase) { this.address = address; this.uri = uri; this.proxySelector = proxySelector; this.pool = pool; this.dns = dns; this.routeDatabase = routeDatabase; this.postponedRoutes = new LinkedList<Route>(); resetNextProxy(uri, address.getProxy()); }
public void startPollingOnChangeEndpoint( OnServerContentChangeListener onServerContentChangeListener) { if (mOnChangePollingEnabled) { // polling already enabled return; } mOnChangePollingEnabled = true; mOnServerContentChangeListener = onServerContentChangeListener; mOnChangePollingClient = new OkHttpClient(); mOnChangePollingClient .setConnectionPool(new ConnectionPool(1, LONG_POLL_KEEP_ALIVE_DURATION_MS)) .setConnectTimeout(HTTP_CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS); enqueueOnChangeEndpointLongPolling(); }
@Bean @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) OkClient okClient() { val client = okHttpClientConfig.create(); client.setConnectionPool(new ConnectionPool(maxIdleConnections, keepAliveDurationMs)); client.setRetryOnConnectionFailure(retryOnConnectionFailure); client.interceptors().add(new RetryingInterceptor(maxElapsedBackoffMs)); return new OkClient(client); }
@Bean @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) OkClient okClient() { OkHttpClient client = okHttpClientConfig.create(); client.setConnectionPool(new ConnectionPool(maxIdleConnections, keepAliveDurationMs)); client.setRetryOnConnectionFailure(retryOnConnectionFailure); return new OkClient(client); }
public HttpConnection(ConnectionPool paramConnectionPool, Connection paramConnection, Socket paramSocket) throws IOException { this.pool = paramConnectionPool; this.connection = paramConnection; this.socket = paramSocket; this.source = Okio.buffer(Okio.source(paramSocket)); this.sink = Okio.buffer(Okio.sink(paramSocket)); }
@Provides @Singleton Client provideClient(OkHttpClient client) { client = new OkHttpClient(); client.setConnectTimeout(30, TimeUnit.SECONDS); // connect timeout client.setReadTimeout(30, TimeUnit.SECONDS); // socket timeout client.setConnectionPool(new ConnectionPool(0, 5 * 60 * 1000)); return new OkClient(client); }