use of okhttp3.logging.HttpLoggingInterceptor in project drift-sdk-android by Driftt.
the class APIManager method setupRestClient.
private static void setupRestClient() {
Gson gson = generateGson();
// HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
// if (!BuildConfig.DEBUG) {
// loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.NONE);
// } else {
// loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// }
OkHttpClient customerClient = new OkHttpClient.Builder().addInterceptor(new APIAuthTokenInterceptor()).build();
Retrofit retrofit = new Retrofit.Builder().baseUrl(API_CUSTOMER_URL).callFactory(customerClient).addConverterFactory(GsonConverterFactory.create(gson)).build();
REST_CUSTOMER_CLIENT = retrofit.create(APICustomerAPIBuilder.class);
OkHttpClient conversationClient = new OkHttpClient.Builder().addInterceptor(new APIAuthTokenInterceptor()).build();
Retrofit retrofitV2 = new Retrofit.Builder().baseUrl(API_CONVERSATION_URL).callFactory(conversationClient).addConverterFactory(GsonConverterFactory.create(gson)).build();
REST_CONVERSATION_CLIENT = retrofitV2.create(APIConversationAPIBuilder.class);
OkHttpClient authlessClient = new OkHttpClient.Builder().build();
Retrofit retrofitV3 = new Retrofit.Builder().baseUrl(API_CONVERSATION_URL).callFactory(authlessClient).addConverterFactory(GsonConverterFactory.create(gson)).build();
REST_AUTHLESS_CLIENT = retrofitV3.create(APIAuthlessBuilder.class);
}
use of okhttp3.logging.HttpLoggingInterceptor in project Audient by komamj.
the class AudientRepositoryModule method provideOkHttpClient.
@Singleton
@Provides
OkHttpClient provideOkHttpClient(Cache cache, final SharedPreferences sharedPreferences, final Gson gson) {
final HttpLoggingInterceptor logInterceptor = new HttpLoggingInterceptor();
if (BuildConfig.DEBUG) {
logInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
}
return new OkHttpClient.Builder().authenticator(new Authenticator() {
@Nullable
@Override
public Request authenticate(Route route, Response response) throws IOException {
String refershToken = sharedPreferences.getString(Constants.REFRESH_TOKEN, "");
Retrofit retrofit = new Retrofit.Builder().baseUrl(Constants.AUDIENT_HOST).client(new OkHttpClient.Builder().addInterceptor(logInterceptor).build()).addConverterFactory(GsonConverterFactory.create(gson)).addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build();
AudientApi audientApi = retrofit.create(AudientApi.class);
audientApi.refreshAccessToken(GRANT_TYPE, refershToken, Constants.CLIENT_ID, Constants.CLIENT_SECRET).subscribeWith(new DisposableSubscriber<Token>() {
@Override
public void onNext(Token token) {
sharedPreferences.edit().putString(Constants.ACCESS_TOKEN, token.accessToken).commit();
sharedPreferences.edit().putString(Constants.REFRESH_TOKEN, token.refreshToken).commit();
}
@Override
public void onError(Throwable t) {
LogUtils.e(TAG, "refresh token error :" + t.getMessage());
sharedPreferences.edit().putBoolean(Constants.LOGIN_STATUS, false).commit();
android.os.Process.killProcess(android.os.Process.myPid());
}
@Override
public void onComplete() {
}
});
return response.request().newBuilder().header("Authorization", "Bearer " + sharedPreferences.getString(Constants.ACCESS_TOKEN, "")).build();
}
}).addInterceptor(new TokenInterceptor(sharedPreferences)).addInterceptor(logInterceptor).cache(cache).connectTimeout(15, TimeUnit.SECONDS).readTimeout(20, TimeUnit.SECONDS).writeTimeout(20, TimeUnit.SECONDS).retryOnConnectionFailure(true).build();
}
use of okhttp3.logging.HttpLoggingInterceptor in project android-bootstrap by sahiljain5040.
the class NetworkModule method provideOkHttpClient.
@Provides
@Singleton
OkHttpClient provideOkHttpClient(Cache cache) {
Log.d(TAG, "provideOkHttpClientNectors called");
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder builder = new OkHttpClient.Builder().cache(cache);
builder.networkInterceptors().add(interceptor);
OkHttpClient client = builder.build();
return client;
}
use of okhttp3.logging.HttpLoggingInterceptor in project AndroidQuick by ddnosh.
the class RetrofitManager method initOkHttp.
private void initOkHttp() {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
if (BuildConfig.DEBUG) {
// Log信息拦截器
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
// 这里可以选择拦截级别
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// 设置 Debug Log 模式
builder.addInterceptor(loggingInterceptor);
// 配置SSL证书检测
builder.sslSocketFactory(SSLSocketClient.getNoSSLSocketFactory());
builder.hostnameVerifier(SSLSocketClient.getHostnameVerifier());
}
// 错误重连
builder.retryOnConnectionFailure(true);
okHttpClient = builder.build();
LogUtil.i(TAG, "initOkHttp:getNoSSLSocketFactory");
}
use of okhttp3.logging.HttpLoggingInterceptor in project MovieGuide by esoxjem.
the class NetworkModule method provideOkHttpClient.
@Provides
@Singleton
OkHttpClient provideOkHttpClient(RequestInterceptor requestInterceptor) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.connectTimeout(CONNECT_TIMEOUT_IN_MS, TimeUnit.MILLISECONDS).addInterceptor(requestInterceptor);
if (BuildConfig.DEBUG) {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
builder.addInterceptor(loggingInterceptor);
}
return builder.build();
}
Aggregations