List of usage examples for com.squareup.okhttp OkHttpClient OkHttpClient
public OkHttpClient()
From source file:dulleh.akhyou.Utils.CloudflareHttpClient.java
License:Open Source License
/** * We use a persistent Cookie storage to minimize the need of doing the high-latency connections * to Cloudflare protected servers.//from w ww . ja va 2 s . c o m * @param context The Android application's context. It's used to get the cache directory. */ public void onCreate(android.content.Context context) { numInitialized = new AtomicInteger(0); client = new OkHttpClient(); cookieManager = new CookieManager(new PersistentCookieStore(context), CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(cookieManager); cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); client.setCookieHandler(cookieManager); registerSites(); }
From source file:edu.umich.flowfence.smartthings.SmartThingsService.java
License:Apache License
private SmartThingsService() { httpClient = new OkHttpClient(); devices = new ArrayList<SmartDevice>(); installationURL = ""; fullBaseURL = ""; Log.i(TAG, "create SmartThingsService"); //contact SmartThings and pull all devices we can access pullDevices(DEVICE_TYPE_URI_SWITCH); pullDevices(DEVICE_TYPE_URI_LOCKS); }
From source file:edu.umich.oasis.study.smartdevresponderexemplar.SmartThingsService.java
License:Apache License
private SmartThingsService() { httpClient = new OkHttpClient(); switches = new ArrayList<SmartSwitch>(); installationURL = ""; fullBaseURL = ""; Log.i(TAG, "create SmartThingsService"); //contact SmartThings and pull all devices we can access pullDevices();/*from w w w . j a v a 2s .c om*/ }
From source file:ens.ivr.demo.CreateConfCalls.java
public CreateConfCalls() { client = new OkHttpClient(); }
From source file:ens.ivr.demo.OutboundCalls.java
public OutboundCalls() { client = new OkHttpClient(); }
From source file:es.bsc.vmmclient.rest.VmmRestClient.java
License:Open Source License
public VmmRestClient(String url, long timeout, final String username, final String password) { if (url.startsWith("https://")) { // TODO: add the option to accept only Trusted HTTPS connections okHttpClient = getUnsafeOkHttpClient(); } else {//from w w w . j a v a 2s. c o m okHttpClient = new OkHttpClient(); } // Define our own okHttpClient to increase the timeout okHttpClient.setReadTimeout(timeout, TimeUnit.SECONDS); if (username != null && password != null) { okHttpClient.setAuthenticator(new Authenticator() { @Override public Request authenticate(Proxy proxy, Response response) throws IOException { String credential = Credentials.basic(username, password); return response.request().newBuilder().header("Authorization", credential).build(); } @Override public Request authenticateProxy(Proxy proxy, Response response) throws IOException { return null; } }); } RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(url).setClient(new OkClient(okHttpClient)) .build(); service = restAdapter.create(VmmService.class); }
From source file:es.bsc.vmmclient.rest.VmmRestClient.java
License:Open Source License
private static OkHttpClient getUnsafeOkHttpClient() { try {//from w ww .jav a2 s . c o m // Create a trust manager that does not validate certificate chains final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @Override public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { } @Override public java.security.cert.X509Certificate[] getAcceptedIssuers() { return new java.security.cert.X509Certificate[] {}; } } }; // Install the all-trusting trust manager final SSLContext sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); // Create an ssl socket factory with our all-trusting manager final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setSslSocketFactory(sslSocketFactory); okHttpClient.setHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }); return okHttpClient; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:es.ffgiraldez.comicsearch.data.api.RestDataSource.java
License:Apache License
public RestDataSource() { OkHttpClient client = new OkHttpClient(); HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(); httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); client.interceptors().add(httpLoggingInterceptor); endpoint = new Retrofit.Builder().baseUrl(ComicVineApi.BASE_URL).client(client) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()).build().create(ComicVineApi.class); }
From source file:es.upv.grycap.coreutils.fiber.http.Http2Clients.java
License:Apache License
/** * Gets a new instance of the HTTP2 client that is not managed by coreutils in any way. Use this client if your application * manages its own threads or if you use any other kind of concurrent execution outside coreutils. * @return An unmanaged instance of the HTTP2 client. *//* w w w .ja v a 2 s.c o m*/ public static Http2Client isolatedHttp2Client() { return new Http2Client(new OkHttpClient()); }
From source file:fiskinfoo.no.sintef.fiskinfoo.Http.BarentswatchApiRetrofit.BarentswatchApi.java
License:Apache License
public Request getRequestForAuthentication(String mEmail, String mPassword) { final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json;charset=utf-8"); final OkHttpClient client = new OkHttpClient(); RequestBody formBody = new FormEncodingBuilder().add("grant_type", "password").add("username", mEmail) .add("password", mPassword).build(); return new Request.Builder().url(currentPath + "/api/token") .header("content-type", "application/x-www-form-urlencoded").post(formBody).build(); }