Search in sources :

Example 26 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project autorest.java by Azure.

the class CustomBaseUriMoreOptionsTests method setup.

@BeforeClass
public static void setup() {
    OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder().addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY));
    client = new AutoRestParameterizedCustomHostTestClientImpl(clientBuilder, new Retrofit.Builder());
    client.withSubscriptionId("test12");
}
Also used : OkHttpClient(okhttp3.OkHttpClient) AutoRestParameterizedCustomHostTestClientImpl(fixtures.custombaseurimoreoptions.implementation.AutoRestParameterizedCustomHostTestClientImpl) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) BeforeClass(org.junit.BeforeClass)

Example 27 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project kripton by xcesco.

the class NetworkClient method instance.

public static OkHttpClient instance() {
    if (client == null) {
        HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
        /* ConnectionSpec spec = new
                    ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
                    .tlsVersions(TlsVersion.TLS_1_2)
                    .cipherSuites(
                            CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
                            CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
                            CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256)
                    .build();*/
        client = (new OkHttpClient.Builder()).readTimeout(60, TimeUnit.SECONDS).connectTimeout(60, TimeUnit.SECONDS).addInterceptor(logging).build();
    }
    return client;
}
Also used : HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 28 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project open-event-android by fossasia.

the class APIClient method getOpenEventAPI.

public static OpenEventAPI getOpenEventAPI() {
    if (openEventAPI == null) {
        OkHttpClient okHttpClient = okHttpClientBuilder.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC)).authenticator(AuthUtil.getAuthenticator()).build();
        ObjectMapper objectMapper = getObjectMapper();
        Class[] classes = { Event.class, Track.class, Speaker.class, Sponsor.class, Session.class, Microlocation.class, User.class, FAQ.class, Notification.class, DiscountCode.class };
        openEventAPI = new Retrofit.Builder().client(okHttpClient).addCallAdapterFactory(RxJava2CallAdapterFactory.create()).addConverterFactory(new JSONAPIConverterFactory(objectMapper, classes)).addConverterFactory(JacksonConverterFactory.create(getObjectMapper())).baseUrl(Urls.BASE_URL).build().create(OpenEventAPI.class);
    }
    return openEventAPI;
}
Also used : OkHttpClient(okhttp3.OkHttpClient) JSONAPIConverterFactory(com.github.jasminb.jsonapi.retrofit.JSONAPIConverterFactory) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 29 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project anitrend-app by AniTrend.

the class WebFactory method createCrunchyService.

public static EpisodeModel createCrunchyService(boolean feeds, Context context) {
    if (mCrunchy == null) {
        OkHttpClient.Builder httpClient = new OkHttpClient.Builder().readTimeout(45, TimeUnit.SECONDS).connectTimeout(45, TimeUnit.SECONDS).addInterceptor(new CacheInterceptor(context, true)).addNetworkInterceptor(new NetworkCacheInterceptor(context, true)).cache(CompatUtil.cacheProvider(context));
        if (BuildConfig.DEBUG) {
            HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC);
            httpClient.addInterceptor(httpLoggingInterceptor);
        }
        crunchyBuilder.client(httpClient.build());
    }
    mCrunchy = crunchyBuilder.baseUrl(feeds ? BuildConfig.FEEDS_LINK : BuildConfig.CRUNCHY_LINK).build();
    return mCrunchy.create(EpisodeModel.class);
}
Also used : OkHttpClient(okhttp3.OkHttpClient) CacheInterceptor(com.mxt.anitrend.model.api.interceptor.CacheInterceptor) NetworkCacheInterceptor(com.mxt.anitrend.model.api.interceptor.NetworkCacheInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) NetworkCacheInterceptor(com.mxt.anitrend.model.api.interceptor.NetworkCacheInterceptor)

Example 30 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project anitrend-app by AniTrend.

the class WebFactory method createService.

/**
 * Generates retrofit service classes in a background thread
 * and handles creation of API tokens or renewal of them
 * <br/>
 *
 * @param serviceClass The interface class to use such as
 *
 * @param context A valid application, fragment or activity context but must be application context
 */
public static <S> S createService(@NonNull Class<S> serviceClass, Context context) {
    WebTokenRequest.getToken(context);
    if (mRetrofit == null) {
        OkHttpClient.Builder httpClient = new OkHttpClient.Builder().readTimeout(35, TimeUnit.SECONDS).connectTimeout(35, TimeUnit.SECONDS).addInterceptor(new AuthInterceptor(context));
        if (BuildConfig.DEBUG) {
            HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY);
            httpClient.addInterceptor(httpLoggingInterceptor);
        }
        mRetrofit = anitrendBuilder.client(httpClient.build()).addConverterFactory(GraphConverter.create(context)).build();
    }
    return mRetrofit.create(serviceClass);
}
Also used : OkHttpClient(okhttp3.OkHttpClient) AuthInterceptor(com.mxt.anitrend.model.api.interceptor.AuthInterceptor) 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