use of okhttp3.logging.HttpLoggingInterceptor in project RSAndroidApp by RailwayStations.
the class RSAPIClient method createRSAPI.
private RSAPI createRSAPI() {
final var gson = new GsonBuilder();
gson.registerTypeAdapter(HighScore.class, new HighScore.HighScoreDeserializer());
gson.registerTypeAdapter(License.class, new License.LicenseDeserializer());
final var builder = new OkHttpClient.Builder().addInterceptor(new BaseApplication.UserAgentInterceptor(BuildConfig.APPLICATION_ID + "/" + BuildConfig.VERSION_NAME + "(" + BuildConfig.VERSION_CODE + "); Android " + Build.VERSION.RELEASE + "/" + Build.VERSION.SDK_INT)).addInterceptor(chain -> {
if (username != null && password != null) {
final Request.Builder builder1 = chain.request().newBuilder().header("Authorization", Credentials.basic(username, password));
final Request newRequest = builder1.build();
return chain.proceed(newRequest);
}
return chain.proceed(chain.request());
});
if (BuildConfig.DEBUG) {
final var loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
builder.addInterceptor(loggingInterceptor);
}
final Retrofit retrofit = new Retrofit.Builder().baseUrl(baseUrl).client(builder.build()).addConverterFactory(GsonConverterFactory.create(gson.create())).build();
return retrofit.create(RSAPI.class);
}
use of okhttp3.logging.HttpLoggingInterceptor in project ride-read-android by Ride-Read.
the class RetrofitUtils method configClient.
private static OkHttpClient configClient() {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.connectTimeout(TIMEOUT_SECONDS, TimeUnit.SECONDS).readTimeout(TIMEOUT_SECONDS, TimeUnit.SECONDS).writeTimeout(TIMEOUT_SECONDS, TimeUnit.SECONDS);
// .retryOnConnectionFailure(true);
try {
final X509TrustManager tm = new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
@Override
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
// Not implemented
}
@Override
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
// Not implemented
}
};
final SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, new TrustManager[] { tm }, new java.security.SecureRandom());
builder.sslSocketFactory(sc.getSocketFactory(), tm).hostnameVerifier((hostname, session) -> hostname.contains(".195."));
if (BuildConfig.DEBUG) {
// Log信息拦截器
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// 设置 Debug Log 模式
builder.addInterceptor(loggingInterceptor);
}
} catch (Exception e) {
e.printStackTrace();
}
return builder.build();
}
use of okhttp3.logging.HttpLoggingInterceptor in project xabber-android by redsolution.
the class HttpApiManager method getRetrofit.
public static Retrofit getRetrofit() {
if (retrofit == null) {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
// if debug enable http logging
if (BuildConfig.DEBUG)
httpClientBuilder.addInterceptor(loggingInterceptor);
OkHttpClient httpClient = httpClientBuilder.build();
Gson gson = new GsonBuilder().registerTypeAdapter(AuthManager.ListClientSettingsDTO.class, new ClientSettingsDeserializer()).setLenient().create();
retrofit = new Retrofit.Builder().baseUrl(SettingsManager.useDevelopAPI() ? XABBER_DEV_API_URL : XABBER_API_URL).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).addConverterFactory(GsonConverterFactory.create(gson)).client(httpClient).build();
}
return retrofit;
}
use of okhttp3.logging.HttpLoggingInterceptor in project xabber-android by redsolution.
the class HttpApiManager method getRetrofitXabberCom.
public static Retrofit getRetrofitXabberCom() {
if (retrofitXabberCom == null) {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
// if debug enable http logging
if (BuildConfig.DEBUG)
httpClientBuilder.addInterceptor(loggingInterceptor);
OkHttpClient httpClient = httpClientBuilder.build();
Gson gson = new GsonBuilder().setLenient().create();
retrofitXabberCom = new Retrofit.Builder().baseUrl(XABBER_COM_URL).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).addConverterFactory(GsonConverterFactory.create(gson)).client(httpClient).build();
}
return retrofitXabberCom;
}
use of okhttp3.logging.HttpLoggingInterceptor in project xabber-android by redsolution.
the class HttpApiManager method getCrowdfundingRetrofit.
private static Retrofit getCrowdfundingRetrofit() {
if (retrofitCrowdfunding == null) {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
// if debug enable http logging
if (BuildConfig.DEBUG)
httpClientBuilder.addInterceptor(loggingInterceptor);
OkHttpClient httpClient = httpClientBuilder.build();
Gson gson = new GsonBuilder().setLenient().create();
retrofitCrowdfunding = new Retrofit.Builder().baseUrl(SettingsManager.useDevelopAPI() ? CROWDFUNDING_DEV_URL : CROWDFUNDING_URL).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).addConverterFactory(GsonConverterFactory.create(gson)).client(httpClient).build();
}
return retrofitCrowdfunding;
}
Aggregations