List of usage examples for com.squareup.okhttp OkHttpClient setWriteTimeout
public void setWriteTimeout(long timeout, TimeUnit unit)
From source file:com.spotify.apollo.http.client.OkHttpClientProvider.java
License:Apache License
@Override public OkHttpClient get() { final OkHttpClient client = new OkHttpClient(); //timeouts settings config.connectTimeoutMillis().ifPresent(millis -> client.setConnectTimeout(millis, TimeUnit.MILLISECONDS)); config.readTimeoutMillis().ifPresent(millis -> client.setReadTimeout(millis, TimeUnit.MILLISECONDS)); config.writeTimeoutMillis().ifPresent(millis -> client.setWriteTimeout(millis, TimeUnit.MILLISECONDS)); // connection pool settings client.setConnectionPool(new ConnectionPool( // defaults that come from com.squareup.okhttp.ConnectionPool config.maxIdleConnections().orElse(5), config.connectionKeepAliveDurationMillis().orElse(5 * 60 * 1000))); // async dispatcher settings config.maxAsyncRequests().ifPresent(max -> client.getDispatcher().setMaxRequests(max)); config.maxAsyncRequestsPerHost().ifPresent(max -> client.getDispatcher().setMaxRequestsPerHost(max)); closer.register(ExecutorServiceCloser.of(client.getDispatcher().getExecutorService())); return client; }
From source file:com.squareup.picasso.OkHttpDownloader.java
License:Apache License
private static OkHttpClient defaultOkHttpClient() { OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(Utils.DEFAULT_CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); client.setReadTimeout(Utils.DEFAULT_READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); client.setWriteTimeout(Utils.DEFAULT_WRITE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); return client; }
From source file:com.uditgupta.udacity.popularmovies.data.DataModule.java
License:Apache License
static OkHttpClient createOkHttpClient(Application app) { OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(10, SECONDS); client.setReadTimeout(10, SECONDS);// w w w. j a v a2 s .c o m client.setWriteTimeout(10, SECONDS); File cacheDir = new File(app.getCacheDir(), "http"); Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE); client.setCache(cache); return client; }
From source file:com.urswolfer.gerrit.client.rest.http.GerritRestClient.java
License:Apache License
private HttpClientBuilder getHttpClient(HttpContext httpContext) { HttpClientBuilder client = HttpClients.custom(); client.useSystemProperties(); // see also: com.intellij.util.net.ssl.CertificateManager OkHttpClient c = new OkHttpClient(); c.setFollowRedirects(true);/*from w w w .j a va 2 s.c o m*/ // we need to get redirected result after login (which is done with POST) for extracting xGerritAuth client.setRedirectStrategy(new LaxRedirectStrategy()); c.setCookieHandler(cookieManager); c.setConnectTimeout(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS); c.setReadTimeout(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS); c.setWriteTimeout(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS); CredentialsProvider credentialsProvider = getCredentialsProvider(); client.setDefaultCredentialsProvider(credentialsProvider); if (authData.isLoginAndPasswordAvailable()) { credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(authData.getLogin(), authData.getPassword())); BasicScheme basicAuth = new BasicScheme(); httpContext.setAttribute(PREEMPTIVE_AUTH, basicAuth); client.addInterceptorFirst(new PreemptiveAuthHttpRequestInterceptor(authData)); } client.addInterceptorLast(new UserAgentHttpRequestInterceptor()); for (HttpClientBuilderExtension httpClientBuilderExtension : httpClientBuilderExtensions) { client = httpClientBuilderExtension.extend(client, authData); credentialsProvider = httpClientBuilderExtension.extendCredentialProvider(client, credentialsProvider, authData); } return client; }
From source file:com.ushahidi.android.presentation.di.modules.AppModule.java
License:Open Source License
/** * Provides {@link HttpClientWrap} object * * @param context The calling context//from ww w . j a v a2 s . co m * @return The http client wrap object */ @Provides @Singleton HttpClientWrap provideOkHttpClient(Context context) { final OkHttpClient okHttpClient = createOkHttpClient(context.getApplicationContext()); okHttpClient.setCookieHandler(CookieHandler.getDefault()); okHttpClient.setConnectTimeout(10, TimeUnit.SECONDS); okHttpClient.setReadTimeout(10, TimeUnit.SECONDS); okHttpClient.setWriteTimeout(10, TimeUnit.SECONDS); return new HttpClientWrap(context, new OkClient(okHttpClient)); }
From source file:com.vaporwarecorp.mirror.app.MirrorApplication.java
License:Apache License
private void initializeGlide() { Cache cache = new Cache(new File(getCacheDir(), "http"), 25 * 1024 * 1024); OkHttpClient mOkHttpClient = new OkHttpClient(); mOkHttpClient.setCache(cache);/*from www .j av a2 s .c o m*/ mOkHttpClient.setConnectTimeout(10, SECONDS); mOkHttpClient.setReadTimeout(10, SECONDS); mOkHttpClient.setWriteTimeout(10, SECONDS); Glide.get(getApplicationContext()).register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(mOkHttpClient)); }
From source file:com.wialon.remote.OkSdkHttpClient.java
License:Apache License
public OkHttpClient getHttpClient(int timeout) { if ((timeout == 0 || timeout == DEFAULT_SOCKET_TIMEOUT) && defaultClient != null) return defaultClient; else {//from www . ja v a 2 s.com OkHttpClient client = new OkHttpClient(); timeout = timeout == 0 ? DEFAULT_SOCKET_TIMEOUT : timeout; client.setConnectTimeout(timeout, TimeUnit.MILLISECONDS); client.setWriteTimeout(timeout, TimeUnit.MILLISECONDS); client.setReadTimeout(timeout, TimeUnit.MILLISECONDS); return client; } }
From source file:com.yandex.disk.rest.OkHttpClientFactory.java
License:Apache License
public static OkHttpClient makeClient() { OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); client.setReadTimeout(READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); client.setWriteTimeout(WRITE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); client.setFollowSslRedirects(true);/*from w w w .j a va 2s . co m*/ client.setFollowRedirects(true); return client; }
From source file:com.ydh.gva.util.net.volley.toolbox.OkHttpStack.java
License:Open Source License
@Override public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { OkHttpClient client = mClient.clone(); int timeoutMs = request.getTimeoutMs(); client.setConnectTimeout(timeoutMs, TimeUnit.MILLISECONDS); client.setReadTimeout(timeoutMs, TimeUnit.MILLISECONDS); client.setWriteTimeout(timeoutMs, TimeUnit.MILLISECONDS); com.squareup.okhttp.Request.Builder okHttpRequestBuilder = new com.squareup.okhttp.Request.Builder(); okHttpRequestBuilder.url(request.getUrl()); Map<String, String> headers = request.getHeaders(); okHttpRequestBuilder.addHeader("clientos", "101"); okHttpRequestBuilder.addHeader("osversion", SystemVal.sdk + ""); okHttpRequestBuilder.addHeader("clientphone", SystemVal.model + ""); okHttpRequestBuilder.addHeader("weiLeversion", SystemVal.versionCode + ""); for (final String name : headers.keySet()) { okHttpRequestBuilder.addHeader(name, headers.get(name)); }/* w w w . j a v a 2 s . co m*/ for (final String name : additionalHeaders.keySet()) { okHttpRequestBuilder.addHeader(name, additionalHeaders.get(name)); } setConnectionParametersForRequest(okHttpRequestBuilder, request); com.squareup.okhttp.Request okHttpRequest = okHttpRequestBuilder.build(); Call okHttpCall = client.newCall(okHttpRequest); Response okHttpResponse = okHttpCall.execute(); StatusLine responseStatus = new BasicStatusLine(parseProtocol(okHttpResponse.protocol()), okHttpResponse.code(), okHttpResponse.message()); BasicHttpResponse response = new BasicHttpResponse(responseStatus); response.setEntity(entityFromOkHttpResponse(okHttpResponse)); Headers responseHeaders = okHttpResponse.headers(); for (int i = 0, len = responseHeaders.size(); i < len; i++) { final String name = responseHeaders.name(i), value = responseHeaders.value(i); if (name != null) { response.addHeader(new BasicHeader(name, value)); } } return response; }
From source file:com.yetanotherdevblog.rottentomatoes.api.RottenTomatoes.java
License:Apache License
/** * Return the current {@link retrofit.RestAdapter} instance. If none exists (first call, API key changed), * builds a new one./*from w w w. j av a 2s . co m*/ * <p> * When building, sets the endpoint, a custom converter ({@link RottenTomatoesHelper#getGsonBuilder()}) * and a {@link retrofit.RequestInterceptor} which adds the API key as query param. */ protected RestAdapter getRestAdapter() { if (restAdapter == null) { RestAdapter.Builder builder = newRestAdapterBuilder(); builder.setEndpoint(API_URL); builder.setConverter(new GsonConverter(RottenTomatoesHelper.getGsonBuilder().create())); builder.setRequestInterceptor(new RequestInterceptor() { public void intercept(RequestFacade requestFacade) { requestFacade.addQueryParam(PARAM_API_KEY, apiKey); } }); OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(10, TimeUnit.SECONDS); client.setReadTimeout(10, TimeUnit.SECONDS); client.setWriteTimeout(10, TimeUnit.SECONDS); builder.setClient(new OkClient(client)); if (isDebug) { builder.setLogLevel(RestAdapter.LogLevel.FULL); } restAdapter = builder.build(); } return restAdapter; }