List of usage examples for com.squareup.okhttp OkHttpClient OkHttpClient
public OkHttpClient()
From source file:com.uwetrottmann.androidutils.AndroidUtils.java
License:Apache License
/** * Create an OkHttpClient with its own private SSL context. Avoids libssl crash because other * libraries do not expect the global SSL context to be changed. Also see * https://github.com/square/okhttp/issues/184. *//*w ww . j a v a 2 s.c o m*/ public static OkHttpClient createOkHttpClient() { OkHttpClient okHttpClient = new OkHttpClient(); SSLContext sslContext; try { sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, null, null); } catch (GeneralSecurityException e) { throw new AssertionError(); // The system has no TLS. Just give up. } okHttpClient.setSslSocketFactory(sslContext.getSocketFactory()); return okHttpClient; }
From source file:com.uwetrottmann.getglue.Utils.java
License:Apache License
/** * Create an OkHttpClient with sensible timeouts for mobile connections. *///from www.j a va 2 s. co m public static OkHttpClient createOkHttpClient() { OkHttpClient okHttpClient = new OkHttpClient(); // set timeouts okHttpClient.setConnectTimeout(15 * 1000, TimeUnit.MILLISECONDS); okHttpClient.setReadTimeout(20 * 1000, TimeUnit.MILLISECONDS); return 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);/*ww w. j a va 2 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.vavian.mockretrofitrequests.rest.service.RestClient.java
License:Apache License
public static IRestService getClient() { if (mRestService == null) { final OkHttpClient client = new OkHttpClient(); client.interceptors().add(new FakeInterceptor()); final Retrofit retrofit = new Retrofit.Builder() // Using custom Jackson Converter to parse JSON // Add dependencies: // com.squareup.retrofit:converter-jackson:2.0.0-beta2 .addConverterFactory(JacksonConverterFactory.create()) // Endpoint .baseUrl(IRestService.ENDPOINT).client(client).build(); mRestService = retrofit.create(IRestService.class); }// www. j a va 2s. c o m return mRestService; }
From source file:com.veaer.gank.request.LineRetrofit.java
License:Open Source License
LineRetrofit() { OkHttpClient client = new OkHttpClient(); client.setReadTimeout(12, TimeUnit.SECONDS); int cacheSize = 10 * 1024 * 1024; // 10 MiB cache = new Cache(FileUtils.getHttpCacheDir(), cacheSize); client.setCache(cache);/* ww w .j a v a 2 s . c o m*/ client.networkInterceptors().add(new CacheInterceptor()); RestAdapter restAdapter = new RestAdapter.Builder().setClient(new OkClient(client)) .setEndpoint("http://gank.avosapps.com/api/").setConverter(new GsonConverter(gson)).build(); service = restAdapter.create(Line.class); }
From source file:com.vfdev.gettingthingsdonemusicapp.core.SoundCloudHelper.java
public SoundCloudHelper() { CLIENT_ID = "1abbcf4f4c91b04bb5591fe5a9f60821"; mSoundCloudClient = new OkHttpClient(); }
From source file:com.volley.demo.ExampleSsSslHttpClient.java
License:Apache License
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ss_ssl_http_client); mTvResult = (TextView) findViewById(R.id.tv_result); Button btnSimpleRequest = (Button) findViewById(R.id.btn_simple_request); btnSimpleRequest.setOnClickListener(new OnClickListener() { @Override/*from ww w . j a v a 2 s. c o m*/ public void onClick(View v) { // Replace R.raw.test with your keystore InputStream keyStore = getResources().openRawResource(R.raw.test); // Usually getting the request queue shall be in singleton like in {@see Act_SimpleRequest} // Current approach is used just for brevity RequestQueue queue = Volley.newRequestQueue(ExampleSsSslHttpClient.this, new OkHttpStack(new OkHttpClient())); StringRequest myReq = new StringRequest(Method.GET, "https://ave.bolyartech.com:44401/https_test.html", createMyReqSuccessListener(), createMyReqErrorListener()); queue.add(myReq); } }); }
From source file:com.votzapp.app.RegistrationIntentService.java
License:Open Source License
/** * Persist registration to third-party servers. * * Modify this method to associate the user's GCM registration token with any server-side account * maintained by your application.//from www. j av a 2 s . co m * * @param token The new token. */ private void sendRegistrationToServer(String token, String email) { // Adding custom implementation OkHttpClient client = new OkHttpClient(); //Sending both GCM_TOKEN and EMAIL to the server RequestBody requestBody = new FormEncodingBuilder().add(KEY_TOKEN, token).add(EMAIL, email).build(); Request request = new Request.Builder().url(REGISTER_URL).post(requestBody).build(); try { Response response = client.newCall(request).execute(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.weather.hackathon.app.WeatherMapActivity.java
License:Open Source License
/** * This is where we can add markers or lines, add listeners or move the camera. In this case, we centered the map * on the US and initialized classes for loading the tiles. * <p/>//from ww w . j a v a 2 s . com * This should only be called once and when we are sure that {@link #map} is not null. */ private void setUpMap() { map.getUiSettings().setTiltGesturesEnabled(false); map.getUiSettings().setRotateGesturesEnabled(false); map.getUiSettings().setMyLocationButtonEnabled(true); CameraPosition position = CameraPosition.builder().target(new LatLng(39.8282, -98.5795)).zoom(3.5f).build(); map.moveCamera(CameraUpdateFactory.newCameraPosition(position)); layersFetcher = new LayersFetcher(new OkHttpClient()); layersFetcher.setLayersResultListener(new WeatherOverlayCreator(map, LAYER_TO_DISPLAY)); }
From source file:com.whiterabbit.robolectricdependency.client.GitHubClient.java
License:Apache License
public GitHubClient(Context c) { OkHttpClient okHttpClient = new OkHttpClient(); File cacheDir = c.getCacheDir(); Cache cache = null;// w ww . ja v a 2 s . com cache = new Cache(cacheDir, 1024); okHttpClient.setCache(cache); Retrofit retrofit = new Retrofit.Builder().baseUrl(API_URL) .addConverterFactory(GsonConverterFactory.create()).build(); // Create an instance of our GitHub API interface. mService = retrofit.create(GitHubService.class); }