List of usage examples for com.squareup.okhttp OkHttpClient setReadTimeout
public void setReadTimeout(long timeout, TimeUnit unit)
From source file:ph.devcon.android.base.module.APIModule.java
License:Apache License
@Provides public RestAdapter provideRestAdapter() { int SIZE_OF_CACHE = 1024; OkHttpClient ok = new OkHttpClient(); ok.setReadTimeout(30, TimeUnit.SECONDS); ok.setConnectTimeout(30, TimeUnit.SECONDS); try {//from w ww.j a va2 s. c o m Cache responseCache = new Cache(DevConApplication.getInstance().getCacheDir(), SIZE_OF_CACHE); ok.setCache(responseCache); } catch (Exception e) { Log.d("OkHttp", "Unable to set http cache", e); } Executor executor = Executors.newCachedThreadPool(); return new RestAdapter.Builder().setExecutors(executor, executor).setClient(new OkClient(ok)) .setEndpoint(DevConApplication.API_ENDPOINT).setRequestInterceptor(new ApiRequestInterceptor()) // .setLogLevel(RestAdapter.LogLevel.FULL).setLog(new AndroidLog("RETROFIT")) .build(); }
From source file:retrofit.client.OkClient.java
License:Apache License
private static OkHttpClient generateDefaultOkHttp() { OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(Defaults.CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); client.setReadTimeout(Defaults.READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); return client; }
From source file:retrofit.MagnetRestAdapter.java
License:Apache License
/** * Get the OkHttpClient with proper timeout settings * @param method/* w ww. j a v a 2s.c o m*/ * @return */ private OkHttpClient getClient(Method method) { Timeout timeoutAnnotation = method.getAnnotation(Timeout.class); if (null != timeoutAnnotation) { if (0 != timeoutAnnotation.read() || 0 != timeoutAnnotation.write()) { OkHttpClient newClient = client.clone(); if (isTimeoutValid(timeoutAnnotation.read(), method, timeoutAnnotation)) { newClient.setReadTimeout(timeoutAnnotation.read(), TimeUnit.SECONDS); } if (isTimeoutValid(timeoutAnnotation.write(), method, timeoutAnnotation)) { newClient.setWriteTimeout(timeoutAnnotation.write(), TimeUnit.SECONDS); } Log.d(TAG, "Using new OkHttpClient with new timeout " + timeoutAnnotation + " for method " + method); return newClient; } } return client; }
From source file:retrofit.Platform.java
License:Apache License
OkHttpClient defaultClient() { OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(15, TimeUnit.SECONDS); client.setReadTimeout(15, TimeUnit.SECONDS); client.setWriteTimeout(15, TimeUnit.SECONDS); return client; }
From source file:stash.samples.hockeyloader.network.client.HttpClient.java
License:Apache License
private static OkHttpClient createDefault() { OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT_SECONDS, TimeUnit.SECONDS); client.setReadTimeout(DEFAULT_READ_TIMEOUT_SECONDS, TimeUnit.SECONDS); return client; }
From source file:syncthing.api.SyncthingApiLongpollModule.java
License:Open Source License
@Provides @SessionScope/*from w ww. jav a2 s . c om*/ @Named("longpoll") public SyncthingApi provideSyncthingApi(Gson gson, OkHttpClient okClient, SyncthingApiConfig config) { OkHttpClient client = okClient.clone(); client.setConnectTimeout(LONGPOLL_CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); client.setReadTimeout(LONGPOLL_READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); client.setSslSocketFactory(SyncthingSSLSocketFactory.create(config.getCACert())); client.setHostnameVerifier(new NullHostNameVerifier()); client.interceptors().add(new SyncthingApiInterceptor(config)); Retrofit.Builder b = new Retrofit.Builder().addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create(gson)).client(client).baseUrl(config.getBaseUrl()); if (BuildConfig.DEBUG) { b.validateEagerly(); } return b.build().create(SyncthingApi.class); }
From source file:syncthing.api.SyncthingApiModule.java
License:Open Source License
@Provides @SessionScope//from ww w. ja v a 2 s . c om public SyncthingApi provideSyncthingApi(Gson gson, OkHttpClient okClient, SyncthingApiConfig config) { OkHttpClient client = okClient.clone(); client.setConnectTimeout(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); client.setReadTimeout(READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); client.setSslSocketFactory(SyncthingSSLSocketFactory.create(config.getCACert())); client.setHostnameVerifier(new NullHostNameVerifier()); client.interceptors().add(new SyncthingApiInterceptor(config)); Retrofit.Builder b = new Retrofit.Builder().addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create(gson)).client(client).baseUrl(config.getBaseUrl()); if (BuildConfig.DEBUG) { b.validateEagerly(); } return b.build().create(SyncthingApi.class); }
From source file:zblibrary.demo.manager.HttpRequest.java
License:Apache License
/** * @param url//www . j a v a 2s . c o m * @return */ private OkHttpClient getHttpClient(String url) { Log.i(TAG, "getHttpClient url = " + url); if (StringUtil.isNotEmpty(url, true) == false) { Log.e(TAG, "getHttpClient StringUtil.isNotEmpty(url, true) == false >> return null;"); return null; } OkHttpClient client = new OkHttpClient(); client.setCookieHandler(new HttpHead()); client.setConnectTimeout(15, TimeUnit.SECONDS); client.setWriteTimeout(10, TimeUnit.SECONDS); client.setReadTimeout(10, TimeUnit.SECONDS); //https?,??,??? if (url.startsWith(StringUtil.URL_PREFIXs) && socketFactory != null) { client.setSslSocketFactory(socketFactory); } return client; }