Search in sources :

Example 41 with HttpLoggingInterceptor

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);
}
Also used : Retrofit(retrofit2.Retrofit) HighScore(de.bahnhoefe.deutschlands.bahnhofsfotos.model.HighScore) GsonBuilder(com.google.gson.GsonBuilder) GsonBuilder(com.google.gson.GsonBuilder) License(de.bahnhoefe.deutschlands.bahnhofsfotos.model.License) Request(okhttp3.Request) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 42 with HttpLoggingInterceptor

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();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) X509TrustManager(javax.net.ssl.X509TrustManager) GsonBuilder(com.google.gson.GsonBuilder) SSLContext(javax.net.ssl.SSLContext) X509Certificate(java.security.cert.X509Certificate) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException)

Example 43 with HttpLoggingInterceptor

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;
}
Also used : OkHttpClient(okhttp3.OkHttpClient) GsonBuilder(com.google.gson.GsonBuilder) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 44 with HttpLoggingInterceptor

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;
}
Also used : OkHttpClient(okhttp3.OkHttpClient) GsonBuilder(com.google.gson.GsonBuilder) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 45 with HttpLoggingInterceptor

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;
}
Also used : OkHttpClient(okhttp3.OkHttpClient) GsonBuilder(com.google.gson.GsonBuilder) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Aggregations

HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)118 OkHttpClient (okhttp3.OkHttpClient)98 Retrofit (retrofit2.Retrofit)34 GsonBuilder (com.google.gson.GsonBuilder)30 Provides (dagger.Provides)27 Singleton (javax.inject.Singleton)24 Cache (okhttp3.Cache)19 Request (okhttp3.Request)18 Response (okhttp3.Response)17 IOException (java.io.IOException)16 Gson (com.google.gson.Gson)15 File (java.io.File)15 Interceptor (okhttp3.Interceptor)11 InfoInterceptor (com.eveningoutpost.dexdrip.tidepool.InfoInterceptor)6 StethoInterceptor (com.facebook.stetho.okhttp3.StethoInterceptor)6 List (java.util.List)5 ErrorInterceptor (me.postaddict.instagram.scraper.interceptor.ErrorInterceptor)5 FakeBrowserInterceptor (me.postaddict.instagram.scraper.interceptor.FakeBrowserInterceptor)5 ResponseBody (okhttp3.ResponseBody)5 BeforeClass (org.junit.BeforeClass)5