Search in sources :

Example 86 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project iNGAGE by davis123123.

the class UserInfoHandler method enqueue.

public void enqueue(String username, String ip) {
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
    httpClient.addInterceptor(logging);
    String url = "http://" + ip + "/user_profile.php/";
    Retrofit retrofit = new Retrofit.Builder().client(httpClient.build()).addConverterFactory(GsonConverterFactory.create()).baseUrl(url).build();
    Interface service = retrofit.create(Interface.class);
    Call<ResponseBody> call = service.get(username, url);
    call.enqueue(new Callback<ResponseBody>() {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            Log.i("STATE", "Retrofit response code: " + response.code());
            if (response.isSuccessful()) {
                Log.i("STATE", "Retrofit POST Success");
                try {
                    serverResponse = response.body().string();
                    callBackData.notifyChange(serverResponse);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                Log.i("Retrofit Error Code:", String.valueOf(response.code()));
                Log.i("Retrofit Error Body", response.errorBody().toString());
            }
        }

        @Override
        public void onFailure(Call<ResponseBody> call, Throwable t) {
            Log.i("STATE", "Retrofit Failure");
        }
    });
}
Also used : OkHttpClient(okhttp3.OkHttpClient) IOException(java.io.IOException) ResponseBody(okhttp3.ResponseBody) Retrofit(retrofit2.Retrofit) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 87 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.

the class ServiceGenerator method createService.

public static <S> S createService(Class<S> serviceClass, Context context) {
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    if (BuildConfig.DEBUG) {
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);
    } else {
        logging.setLevel(HttpLoggingInterceptor.Level.NONE);
    }
    PersistentCookieStore cookieStore = new PersistentCookieStore(context);
    java.net.CookieManager cookieManager = new java.net.CookieManager(cookieStore, CookiePolicy.ACCEPT_ALL);
    OkHttpClient.Builder httpClient = new OkHttpClient.Builder().cookieJar(new JavaNetCookieJar(cookieManager)).addInterceptor(logging).addNetworkInterceptor(new StethoInterceptor());
    Gson gson = new GsonBuilder().setLenient().create();
    Retrofit retorfit = new Retrofit.Builder().baseUrl(MafiaRemoteService.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)).client(httpClient.build()).build();
    return retorfit.create(serviceClass);
}
Also used : PersistentCookieStore(com.zimincom.mafiaonline.PersistentCookieStore) JavaNetCookieJar(okhttp3.internal.JavaNetCookieJar) OkHttpClient(okhttp3.OkHttpClient) GsonBuilder(com.google.gson.GsonBuilder) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) Retrofit(retrofit2.Retrofit) StethoInterceptor(com.facebook.stetho.okhttp3.StethoInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 88 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project Cobinhood.Java by jd-alexander.

the class TradingTests method setup.

@Before
public void setup() {
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.BODY);
    cobinhoodService = new CobinhoodApi.Builder().setLoggingInterceptor(logging).setAccessToken(BuildConfig.API_KEY).build();
}
Also used : HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Before(org.junit.Before)

Example 89 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project FastHub by k0shk0sh.

the class JsoupProvider method provideOkHttpClient.

private static OkHttpClient provideOkHttpClient() {
    if (okHttpClient == null) {
        OkHttpClient.Builder client = new OkHttpClient.Builder();
        if (BuildConfig.DEBUG) {
            client.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY));
        }
        client.addInterceptor(new AuthenticationInterceptor(true));
        okHttpClient = client.build();
    }
    return okHttpClient;
}
Also used : OkHttpClient(okhttp3.OkHttpClient) AuthenticationInterceptor(com.fastaccess.provider.rest.interceptors.AuthenticationInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 90 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project FastHub by k0shk0sh.

the class ImgurProvider method provideOkHttpClient.

private static OkHttpClient provideOkHttpClient() {
    OkHttpClient.Builder client = new OkHttpClient.Builder();
    if (BuildConfig.DEBUG) {
        client.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY));
    }
    client.addInterceptor(chain -> {
        Request original = chain.request();
        Request.Builder requestBuilder = original.newBuilder();
        requestBuilder.header("Authorization", "Client-ID " + BuildConfig.IMGUR_CLIENT_ID);
        requestBuilder.method(original.method(), original.body());
        Request request = requestBuilder.build();
        return chain.proceed(request);
    });
    return client.build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) GsonBuilder(com.google.gson.GsonBuilder) Request(okhttp3.Request) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Aggregations

HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)107 OkHttpClient (okhttp3.OkHttpClient)87 Provides (dagger.Provides)27 Retrofit (retrofit2.Retrofit)25 GsonBuilder (com.google.gson.GsonBuilder)24 Singleton (javax.inject.Singleton)24 Cache (okhttp3.Cache)19 Request (okhttp3.Request)16 File (java.io.File)15 Response (okhttp3.Response)15 IOException (java.io.IOException)14 Gson (com.google.gson.Gson)13 Interceptor (okhttp3.Interceptor)11 StethoInterceptor (com.facebook.stetho.okhttp3.StethoInterceptor)6 LoggingInterceptor (com.toshi.manager.network.interceptor.LoggingInterceptor)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