use of okhttp3.ConnectionPool in project okhttp by square.
the class CallTest method leakedResponseBodyLogsStackTrace.
@Test
public void leakedResponseBodyLogsStackTrace() throws Exception {
server.enqueue(new MockResponse().setBody("This gets leaked."));
client = defaultClient().newBuilder().connectionPool(new ConnectionPool(0, 10, TimeUnit.MILLISECONDS)).build();
Request request = new Request.Builder().url(server.url("/")).build();
Level original = logger.getLevel();
logger.setLevel(Level.FINE);
logHandler.setFormatter(new SimpleFormatter());
try {
// Ignore the response so it gets leaked then GC'd.
client.newCall(request).execute();
awaitGarbageCollection();
String message = logHandler.take();
assertTrue(message.contains("A connection to " + server.url("/") + " was leaked." + " Did you forget to close a response body?"));
assertTrue(message.contains("okhttp3.RealCall.execute("));
assertTrue(message.contains("okhttp3.CallTest.leakedResponseBodyLogsStackTrace("));
} finally {
logger.setLevel(original);
}
}
use of okhttp3.ConnectionPool in project hmftools by hartwigmedical.
the class SlicerHttpClient method create.
@NotNull
static OkHttpClient create(final int maxRequests) {
final Dispatcher requestDispatcher = new Dispatcher();
requestDispatcher.setMaxRequests(maxRequests);
requestDispatcher.setMaxRequestsPerHost(maxRequests);
return new OkHttpClient.Builder().connectionPool(new ConnectionPool(20, 1, TimeUnit.MINUTES)).readTimeout(20, TimeUnit.SECONDS).connectTimeout(20, TimeUnit.SECONDS).writeTimeout(20, TimeUnit.SECONDS).dispatcher(requestDispatcher).build();
}
use of okhttp3.ConnectionPool in project apollo by spotify.
the class OkHttpClientProvider method get.
@Override
public OkHttpClient get() {
final OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
// timeouts settings
config.connectTimeoutMillis().ifPresent(millis -> clientBuilder.connectTimeout(millis, TimeUnit.MILLISECONDS));
config.readTimeoutMillis().ifPresent(millis -> clientBuilder.readTimeout(millis, TimeUnit.MILLISECONDS));
config.writeTimeoutMillis().ifPresent(millis -> clientBuilder.writeTimeout(millis, TimeUnit.MILLISECONDS));
// connection pool settings
clientBuilder.connectionPool(new ConnectionPool(// defaults that come from com.squareup.okhttp.ConnectionPool
config.maxIdleConnections().orElse(5), config.connectionKeepAliveDurationMillis().orElse(5 * 60 * 1000), TimeUnit.MILLISECONDS));
config.followRedirects().ifPresent(clientBuilder::followRedirects);
final OkHttpClient client = clientBuilder.build();
// async dispatcher settings
config.maxAsyncRequests().ifPresent(max -> client.dispatcher().setMaxRequests(max));
config.maxAsyncRequestsPerHost().ifPresent(max -> client.dispatcher().setMaxRequestsPerHost(max));
closer.register(ExecutorServiceCloser.of(client.dispatcher().executorService()));
return client;
}
use of okhttp3.ConnectionPool in project jianshi by wingjay.
the class AppModule method provideOkHttpClient.
@Provides
@Singleton
OkHttpClient provideOkHttpClient(GlobalRequestInterceptor globalRequestInterceptor) {
OkHttpClient.Builder builder = new OkHttpClient.Builder().connectionPool(new ConnectionPool(5, 59, TimeUnit.SECONDS)).connectTimeout(20, TimeUnit.SECONDS).readTimeout(20, TimeUnit.SECONDS).addInterceptor(globalRequestInterceptor).retryOnConnectionFailure(false);
if (BuildConfig.DEBUG) {
builder.addNetworkInterceptor(new StethoInterceptor());
}
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE);
builder.addInterceptor(httpLoggingInterceptor);
return builder.build();
}
use of okhttp3.ConnectionPool in project Signal-Android by WhisperSystems.
the class PushServiceSocket method createConnectionClient.
private static OkHttpClient createConnectionClient(SignalUrl url, List<Interceptor> interceptors, Optional<Dns> dns, Optional<SignalProxy> proxy) {
try {
TrustManager[] trustManagers = BlacklistingTrustManager.createFor(url.getTrustStore());
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, trustManagers, null);
OkHttpClient.Builder builder = new OkHttpClient.Builder().sslSocketFactory(new Tls12SocketFactory(context.getSocketFactory()), (X509TrustManager) trustManagers[0]).connectionSpecs(url.getConnectionSpecs().or(Util.immutableList(ConnectionSpec.RESTRICTED_TLS))).dns(dns.or(Dns.SYSTEM));
if (proxy.isPresent()) {
builder.socketFactory(new TlsProxySocketFactory(proxy.get().getHost(), proxy.get().getPort(), dns));
}
builder.sslSocketFactory(new Tls12SocketFactory(context.getSocketFactory()), (X509TrustManager) trustManagers[0]).connectionSpecs(url.getConnectionSpecs().or(Util.immutableList(ConnectionSpec.RESTRICTED_TLS))).build();
builder.connectionPool(new ConnectionPool(5, 45, TimeUnit.SECONDS));
for (Interceptor interceptor : interceptors) {
builder.addInterceptor(interceptor);
}
return builder.build();
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new AssertionError(e);
}
}
Aggregations