List of usage examples for com.squareup.okhttp OkHttpClient OkHttpClient
public OkHttpClient()
From source file:net.qiujuer.common.okhttp.core.HttpCore.java
License:Apache License
public HttpCore(Resolver resolver, RequestBuilder builder) { mOkHttpClient = new OkHttpClient(); mResolver = resolver; mBuilder = builder; }
From source file:net.soulwolf.structure.component.OkHttpComponent.java
License:Apache License
public static void init(AppStructureConfig.HttpConfig config) { if (config == null) { throw new IllegalArgumentException( "OkHttpComponent HttpConfig initialization parameters can not be NULL!"); }/*from w w w .j a va 2 s . c om*/ if (mOkHttpClient == null) { synchronized (OkHttpComponent.class) { if (mOkHttpClient == null) { File cacheDir = new File(AppStructure.getInstance().getCacheDir(), config.getCacheDir()); mOkHttpClient = new OkHttpClient(); mOkHttpClient.setCache(new Cache(cacheDir, config.getCacheSize())); mOkHttpClient.setConnectTimeout(config.getConnectTimeout(), TimeUnit.MILLISECONDS); mOkHttpClient.setReadTimeout(config.getReadTimeout(), TimeUnit.MILLISECONDS); if (AppStructure.isDebug()) { TLog.i(LOG_TAG, "OkHttpComponent initialization!"); } } } } }
From source file:net.uiqui.oblivion.client.rest.RestClient.java
License:Apache License
public RestClient(final Cluster cluster) { client = new OkHttpClient(); client.setConnectTimeout(5, TimeUnit.SECONDS); client.setWriteTimeout(5, TimeUnit.SECONDS); client.setReadTimeout(5, TimeUnit.SECONDS); client.interceptors().add(new RetryHandler(cluster)); }
From source file:ninja.poepoe.basewrapper.rest.RestClient.java
License:Open Source License
/** * return Retrofit//from w w w . j ava2 s . co m */ public Retrofit RestClient() { HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); if (isDebug()) { logging.setLevel(logLevel()); } else { logging.setLevel(Level.NONE); } OkHttpClient client = new OkHttpClient(); client.interceptors().add(logging); client.interceptors().addAll(getInterceptors()); return new Retrofit.Builder().baseUrl(baseURL()).addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .addConverterFactory(getFactory()).client(client).build(); }
From source file:nl.esciencecenter.e3dchem.gpcrdb.client.ApiClient.java
License:Apache License
public ApiClient() { httpClient = new OkHttpClient(); verifyingSsl = true;// ww w. j a v a 2 s . c o m 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/2.0.0/java"); // Setup authentications (key: authentication name, value: authentication). authentications = new HashMap<String, Authentication>(); // Prevent the authentications from being modified. authentications = Collections.unmodifiableMap(authentications); }
From source file:objective.taskboard.jira.endpoint.JiraEndpoint.java
License:Open Source License
public <S> S request(Class<S> service, String username, String password) { OkHttpClient client = new OkHttpClient(); client.setReadTimeout(60, TimeUnit.SECONDS); client.setConnectTimeout(60, TimeUnit.SECONDS); client.interceptors().add(new AuthenticationInterceptor(username, password)); client.interceptors().add(new Interceptor() { @Override/*from w w w . ja v a2s. co m*/ public Response intercept(Chain chain) throws IOException { com.squareup.okhttp.Request request = chain.request(); Response response = chain.proceed(request); int retryCount = 0; while (response.code() == HttpStatus.GATEWAY_TIMEOUT.value() && retryCount < 3) { Uninterruptibles.sleepUninterruptibly(5, TimeUnit.SECONDS); response = chain.proceed(request); retryCount++; } if (!response.isSuccessful()) log.error(request.urlString() + " request failed."); return response; } }); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new TaskboardJacksonModule()); objectMapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false); RestAdapter retrofit = new RestAdapter.Builder().setEndpoint(jiraProperties.getUrl()) .setConverter(new JacksonConverter(objectMapper)).setClient(new OkClient(client)).build(); return retrofit.create(service); }
From source file:ooo.oxo.moments.InstaApplication.java
License:Open Source License
@Override public void onCreate() { super.onCreate(); //noinspection ConstantConditions if (TextUtils.isEmpty(BuildConfig.CLIENT_ID) || TextUtils.isEmpty(BuildConfig.CLIENT_SECRET)) { throw new IllegalStateException("Please create a \"client.properties\" in the same" + " directory of this module to specify your CLIENT_ID and CLIENT_SECRET."); }//w w w .j a va 2s.co m InstaSharedState.createInstance(this); httpClient = new OkHttpClient(); httpClient.interceptors().add(chain -> { Request request = chain.request(); Log.d("OkHttp", request.toString()); Response response = chain.proceed(request); Log.d("OkHttp", response.toString()); return response; }); InstaSharedState.getInstance().applyProxy(); Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .registerTypeAdapter(Date.class, new TimestampTypeAdapter()).create(); retrofit = new Retrofit.Builder().client(httpClient).addConverterFactory(GsonConverterFactory.create(gson)) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()).baseUrl("https://api.instagram.com/") .build(); }
From source file:ooo.oxo.mr.MrApplication.java
License:Open Source License
@Override public void onCreate() { super.onCreate(); LeakCanary.install(this); MrSharedState.createInstance();//from ww w . j a v a2s. c o m httpClient = new OkHttpClient(); httpClient.networkInterceptors().add(chain -> chain.proceed(chain.request().newBuilder() .header("Accept-Language", buildAcceptLanguage()).header("User-Agent", buildUserAgent()).build())); if (BuildConfig.DEBUG) { httpClient.networkInterceptors().add(new LoggingInterceptor()); } Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .setDateFormat(Image.DATE_FORMAT_PATTERN).registerTypeAdapter(Color.class, new ColorTypeAdapter()) .create(); retrofit = new Retrofit.Builder().client(httpClient).addConverterFactory(GsonConverterFactory.create(gson)) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()).baseUrl("http://119.29.45.113:1024/api/") .build(); }
From source file:org.addhen.birudo.data.net.BaseHttpClient.java
License:Apache License
public BaseHttpClient(String url) { this.url = url; this.params = new ArrayList<>(); this.header = new HashMap<>(); httpClient = new OkHttpClient(); httpClient.setConnectTimeout(TIME_OUT_CONNECTION, TimeUnit.SECONDS); httpClient.setWriteTimeout(TIME_OUT_CONNECTION, TimeUnit.SECONDS); httpClient.setReadTimeout(TIME_OUT_CONNECTION, TimeUnit.SECONDS); }
From source file:org.addhen.smssync.data.net.BaseHttpClient.java
License:Open Source License
public BaseHttpClient(Context context) { mContext = context;//from ww w.j a va 2 s.co m mParams = new ArrayList<>(); mHeader = new HashMap<>(); mHttpClient = new OkHttpClient(); mHttpClient.setConnectTimeout(TIME_OUT_CONNECTION, TimeUnit.SECONDS); mHttpClient.setWriteTimeout(TIME_OUT_CONNECTION, TimeUnit.SECONDS); mHttpClient.setReadTimeout(TIME_OUT_CONNECTION, TimeUnit.SECONDS); }