List of usage examples for com.squareup.okhttp OkHttpClient OkHttpClient
public OkHttpClient()
From source file:com.anony.okhttp.sample.RewriteResponseCacheControl.java
License:Apache License
public RewriteResponseCacheControl(File cacheDirectory) throws Exception { Cache cache = new Cache(cacheDirectory, 1024 * 1024); cache.evictAll();//w w w .j a va 2s . c om client = new OkHttpClient(); client.setCache(cache); }
From source file:com.apothesource.pillfill.network.PFNetworkManager.java
License:Open Source License
private static synchronized void initHttpClient(boolean allowWeakCiphers) { if (pfPinnedClient == null) { pfPinnedClient = new OkHttpClient(); String apiKey = ResourceUtil.getInstance().getPFApiKey(); if (apiKey == null) { throw new RuntimeException("API_KEY is not set."); }//from www . ja v a2 s .c om pfPinnedClient.setSslSocketFactory(new PFSSLSocketFactory(allowWeakCiphers)); pfPinnedClient.setHostnameVerifier(PFSSLSocketFactory.getPfHostnameVerifier()); pfPinnedClient.networkInterceptors().add(new ApiKeyInterceptor(apiKey)); pfPinnedClient.setCache(getDefaultCache()); } if (standardClient == null) { standardClient = new OkHttpClient(); pfPinnedClient.setCache(getDefaultCache()); } isHttpClientInit = true; }
From source file:com.apothesource.pillfill.service.drug.impl.DefaultDrugAlertServiceImpl.java
License:Open Source License
public DefaultDrugAlertServiceImpl() { externalHttpClient = new OkHttpClient(); cache = new DefaultNoOpCacheServiceImpl(); }
From source file:com.appstarter.utils.WebUtils.java
License:Apache License
public static String doHttpGet(String url) throws AppStarterException { if (BuildConfig.DEBUG) { Log.d(TAG, "doHttpGet - url: " + url); }/* w w w.j a v a 2s . c om*/ String ret = ""; OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(15, TimeUnit.SECONDS); // connect timeout client.setReadTimeout(15, TimeUnit.SECONDS); // socket timeout try { Request request = new Request.Builder().url(new URL(url)) // .header("User-Agent", "OkHttp Headers.java") // .addHeader("Accept", "application/json; q=0.5") .build(); Response response = client.newCall(request).execute(); if (!response.isSuccessful()) { String debugMessage = "doHttpGet - OkHttp.Response is not successful - " + response.message() + " (" + response.code() + ")"; throw new AppStarterException(AppStarterException.ERROR_SERVER, debugMessage); } ret = response.body().string(); } catch (IOException e) { throw new AppStarterException(e, AppStarterException.ERROR_NETWORK_GET); } return ret; }
From source file:com.appstarter.utils.WebUtils.java
License:Apache License
public static String doHttpPost(String url, List<NameValuePair> params) throws AppStarterException { if (BuildConfig.DEBUG) { Log.d(TAG, "doHttpPost - url: " + debugRequest(url, params)); }//www. j ava 2s .co m String ret = ""; OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(15, TimeUnit.SECONDS); // connect timeout client.setReadTimeout(15, TimeUnit.SECONDS); // socket timeout FormEncodingBuilder builder = new FormEncodingBuilder(); for (NameValuePair nvp : params) { builder.add(nvp.getName(), nvp.getValue()); } RequestBody formBody = builder.build(); try { Request request = new Request.Builder().url(new URL(url)) // .header("User-Agent", "OkHttp Headers.java") // .addHeader("Accept", "application/json; q=0.5") .post(formBody).build(); Response response = client.newCall(request).execute(); if (!response.isSuccessful()) { String debugMessage = "doHttpPost - OkHttp.Response is not successful - " + response.message() + " (" + response.code() + ")"; throw new AppStarterException(AppStarterException.ERROR_SERVER, debugMessage); } ret = response.body().string(); } catch (IOException e) { throw new AppStarterException(e, AppStarterException.ERROR_NETWORK_GET); } return ret; }
From source file:com.arbalest.http.ArbalestClientFactory.java
License:Open Source License
private OkHttpClient createOkHttpClient() { OkHttpClient client = new OkHttpClient(); SSLContext sslContext;/*ww w. j a va 2s . c o m*/ try { sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, null, null); } catch (GeneralSecurityException e) { throw new AssertionError(e); } client.setSslSocketFactory(sslContext.getSocketFactory()); return client; }
From source file:com.ariadnext.idcheckio.invoker.ApiClient.java
License:Apache License
public ApiClient() { httpClient = new OkHttpClient(); verifyingSsl = true;/*www. j a v a 2 s . c om*/ json = new JSON(this); /* * Use RFC3339 format for date and datetime. * See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14 */ this.dateFormat = new SimpleDateFormat("yyyy-MM-dd"); // Always use UTC as the default time zone when dealing with date (without time). this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); initDatetimeFormat(); // Be lenient on datetime formats when parsing datetime from string. // See <code>parseDatetime</code>. this.lenientDatetimeFormat = true; // Set default User-Agent. setUserAgent("Swagger-Codegen/1.0.0/java"); // Setup authentications (key: authentication name, value: authentication). authentications = new HashMap<String, Authentication>(); authentications.put("basic", new HttpBasicAuth()); // Prevent the authentications from being modified. authentications = Collections.unmodifiableMap(authentications); }
From source file:com.askfast.askfastapi.util.HttpUtil.java
License:Apache License
public HttpUtil() { client = new OkHttpClient(); }
From source file:com.auth0.android.authentication.AuthenticationAPIClient.java
License:Open Source License
/** * Creates a new API client instance providing Auth0 account info. * * @param auth0 account information/* w w w. j a v a2 s.c o m*/ */ public AuthenticationAPIClient(@NonNull Auth0 auth0) { this(auth0, new RequestFactory(), new OkHttpClient(), GsonProvider.buildGson()); }
From source file:com.auth0.android.lock.internal.configuration.ApplicationFetcherTest.java
License:Open Source License
@Before public void setUp() throws Exception { mockAPI = new ApplicationAPI(); final Options options = Mockito.mock(Options.class); Auth0 account = new Auth0("client_id", mockAPI.getDomain()); Mockito.when(options.getAccount()).thenReturn(account); OkHttpClient client = new OkHttpClient(); appFetcher = new ApplicationFetcher(account, client); }