okhttp3.logging.HttpLoggingInterceptor Java Examples

The following examples show how to use okhttp3.logging.HttpLoggingInterceptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Example11.java    From AnDevCon-RxPatterns with Apache License 2.0 6 votes vote down vote up
private void createGithubClient() {
    if (mGitHubClient == null) {
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(loggingInterceptor)
                .addInterceptor(chain ->
                        chain.proceed(chain.request().newBuilder().addHeader("Authorization",
                                "token " + Secrets.GITHUB_PERSONAL_ACCESS_TOKEN).build())).build();

        mGitHubClient = new Retrofit.Builder()
                .addCallAdapterFactory(RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io()))
                .addConverterFactory(GsonConverterFactory.create())
                .client(client)
                .baseUrl(GITHUB_BASE_URL)
                .build()
                .create(GitHubClient.class);
    }
}
 
Example #2
Source File: RetroFactory.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
private static OkHttpClient initOkHttp() {
    return OkHttpEngine.getInstance()
            .getOkHttpClient()
            .newBuilder()
            .connectTimeout(5000, TimeUnit.MILLISECONDS)
            .readTimeout(5000, TimeUnit.MILLISECONDS)
            .addInterceptor(new GzipInterceptor())
            .addInterceptor(chain -> {
                Request original = chain.request();
                Request.Builder builder = original.newBuilder()
                        .header("Authorization", "Bearer " + AppConfig.getInstance().getToken());
                if (SoUtils.getInstance().isOfficialApplication()){
                    builder.header("User-Agent", "dandanplay/android " + CommonUtils.getAppVersion());
                }
                return chain.proceed(builder.build());
            })
            .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .build();

}
 
Example #3
Source File: RetrofitFactory.java    From TigerVideo with Apache License 2.0 6 votes vote down vote up
private static TtKbApi createTtKbService() {

        OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(TIME_OUT, TimeUnit.SECONDS)
                .readTimeout(TIME_OUT, TimeUnit.SECONDS)
                .writeTimeout(TIME_OUT, TimeUnit.SECONDS)
                .addInterceptor(new HttpLoggingInterceptor()
                .setLevel(HttpLoggingInterceptor.Level.BODY))
                .build();

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(TTKB_BASE_URL)
                .client(client)
                .addConverterFactory(ScalarsConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        return retrofit.create(TtKbApi.class);
    }
 
Example #4
Source File: AppApiHelper.java    From InstantAppStarter with MIT License 6 votes vote down vote up
private ApiClient getApiClient() {

        OkHttpClient.Builder client = new OkHttpClient.Builder();
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        client.addInterceptor(loggingInterceptor);

        OkHttpClient myClient = client.build();

        if (BuildConfig.DEBUG) {
            IdlingResources.registerOkHttp(myClient);
        }

        Retrofit retrofit = new Retrofit
                .Builder()
                .baseUrl(BuildConfig.BASE_URL)
                .client(myClient)
                .addConverterFactory(RaveConverterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        return retrofit.create(ApiClient.class);
    }
 
Example #5
Source File: RetroFactory.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
private static OkHttpClient initShooterOkHttp() {
    return OkHttpEngine.getInstance()
            .getOkHttpClient()
            .newBuilder()
            .connectTimeout(5000, TimeUnit.MILLISECONDS)
            .readTimeout(5000, TimeUnit.MILLISECONDS)
            .addInterceptor(chain -> {
                Request oldRequest = chain.request();
                Request.Builder newRequest = oldRequest.newBuilder();
                List<String> headerValues = oldRequest.headers("download_url");
                HttpUrl newBaseUrl = null;

                if (headerValues.size() > 0) {
                    newRequest.removeHeader("download_url");
                    newBaseUrl = HttpUrl.parse(headerValues.get(0));
                }

                if (newBaseUrl != null) {
                    return chain.proceed(newRequest.url(newBaseUrl).build());
                }
                return chain.proceed(oldRequest);
            })
            .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .build();

}
 
Example #6
Source File: RemotePresenterImpl.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
private OkHttpClient getOkHttpClient(String authorization) {
    OkHttpClient.Builder builder = OkHttpEngine.getInstance()
            .getOkHttpClient()
            .newBuilder()
            .connectTimeout(5000, TimeUnit.MILLISECONDS)
            .readTimeout(5000, TimeUnit.MILLISECONDS)
            .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY));
    //添加token验证
    if (!StringUtils.isEmpty(authorization)){
        builder.addInterceptor(chain -> {
            Request original = chain.request();
            Request.Builder requestBuilder = original.newBuilder()
                    .header("Authorization", "Bearer "+ authorization);
            return chain.proceed(requestBuilder.build());
        });
    }
    return builder.build();
}
 
Example #7
Source File: AppliveryApiServiceBuilder.java    From applivery-android-sdk with Apache License 2.0 6 votes vote down vote up
public static AppliveryApiService getAppliveryApiInstance() {

        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder();
        okHttpClientBuilder.interceptors().add(new HeadersInterceptor());
        okHttpClientBuilder.interceptors().add(Injection.INSTANCE.provideSessionInterceptor());

        if (BuildConfig.DEBUG) {
            okHttpClientBuilder.interceptors().add(loggingInterceptor);
        }

        return new Retrofit.Builder().baseUrl(BuildConfig.API_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .client(okHttpClientBuilder.build())
                .build()
                .create(AppliveryApiService.class);
    }
 
Example #8
Source File: RemoteCommentService.java    From OfflineSampleApp with Apache License 2.0 6 votes vote down vote up
public RemoteCommentService() {

        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient httpClient = new OkHttpClient.Builder()
                .addInterceptor(loggingInterceptor)
                .build();

        Gson gson = new GsonBuilder()
                .excludeFieldsWithoutExposeAnnotation()
                .create();

        retrofit = new Retrofit.Builder()
                .client(httpClient)
                .baseUrl(BuildConfig.API_BASE_URL)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build();
    }
 
Example #9
Source File: CustomHttpClient.java    From SimpleAdapterDemo with Apache License 2.0 6 votes vote down vote up
public OkHttpClient createOkHttpClient() {
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
            .readTimeout(readTimeout, TimeUnit.MILLISECONDS)
            .writeTimeout(writeTimeout, TimeUnit.MILLISECONDS);
    //拦截服务器端的Log日志并打印,如果未debug状态就打印日志,否则就什么都不做
    builder.addInterceptor(new HttpLoggingInterceptor().setLevel(showLog ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE));

    if (headers != null && !headers.isEmpty())
        builder.addInterceptor(createHeaderInterceptor());

    if (interceptors != null && !interceptors.isEmpty()) {
        for (Interceptor it : interceptors) {
            builder.addInterceptor(it);
        }
    }

    if (cache != null) {
        builder.cache(cache);
        builder.addNetworkInterceptor(createCacheInterceptor());
    }
    return builder.build();
}
 
Example #10
Source File: RESTHelper.java    From android-java-connect-rest-sample with MIT License 6 votes vote down vote up
public Retrofit getRetrofit(Interceptor interceptor) {
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.HEADERS);

    OkHttpClient client = new OkHttpClient.Builder()
            .addInterceptor(interceptor)
            .addInterceptor(logging)
            .build();

    //Sets required properties in rest adaptor class before it is created.
    return new Retrofit.Builder()
            .baseUrl(Constants.MICROSOFT_GRAPH_API_ENDPOINT_RESOURCE_ID)
            .client(client)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
}
 
Example #11
Source File: NetworkModule.java    From Retrofit2RxjavaDemo with Apache License 2.0 6 votes vote down vote up
@Provides
@AppScope
@Named("cached")
OkHttpClient provideOkHttpClient(Cache cache) {
    OkHttpClient client =
            new OkHttpClient.Builder()
                    .connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
                    .writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
                    .readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
                    .addNetworkInterceptor(
                            new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                    .retryOnConnectionFailure(true)
                    .cache(cache)
                    .build();
    return client;
}
 
Example #12
Source File: PushoverApi.java    From 600SeriesAndroidUploader with MIT License 6 votes vote down vote up
public PushoverApi(String baseURL) {

        OkHttpClient.Builder okHttpClient = new OkHttpClient().newBuilder()
                .connectTimeout(30, TimeUnit.SECONDS)
                .readTimeout(60, TimeUnit.SECONDS)
                .writeTimeout(60, TimeUnit.SECONDS);

        // dev debug logging only
        if (false & BuildConfig.DEBUG) {
            HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
            logging.setLevel(HttpLoggingInterceptor.Level.BODY);
            okHttpClient.addInterceptor(logging);
        }

        retrofit = new Retrofit.Builder()
                .baseUrl(baseURL)
                .client(okHttpClient.build())
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        pushoverEndpoints = retrofit.create(PushoverEndpoints.class);
    }
 
Example #13
Source File: RetrofitDao.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
private RetrofitDao(IBuildPublicParams iBuildPublicParams, CookieJar cookieJar) {
    if (mRetrofit == null) {
        if (NetworkConfig.getBaseUrl() == null || NetworkConfig.getBaseUrl().trim().equals("")) {
            throw new RuntimeException("网络模块必须设置在Application处调用 请求的地址 调用方法:NetworkConfig.setBaseUrl(String url)");
        }
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .connectTimeout(BuildConfig.CONNECT_TIMEOUT, TimeUnit.SECONDS)
                .writeTimeout(BuildConfig.WRITE_TIMEOUT, TimeUnit.SECONDS)
                .readTimeout(BuildConfig.READ_TIMEOUT, TimeUnit.SECONDS)
                .cookieJar(cookieJar)
                .addInterceptor(new HttpInterceptor(iBuildPublicParams))
                .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                .build();
        Gson gson = new GsonBuilder().setDateFormat(DATE_FORMAT).create();
        mRetrofit = new Retrofit.Builder()
                .baseUrl(NetworkConfig.getBaseUrl())
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(okHttpClient)
                .build();
    }
}
 
Example #14
Source File: RetrofitModule.java    From Nibo with MIT License 6 votes vote down vote up
private RetrofitModule() {
    if (retrofit == null) {
        HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
        httpClient.addInterceptor(logging);


        retrofit = new Retrofit.Builder()
                .baseUrl(NiboConstants.BASE_DIRECTIONS_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .client(httpClient.build())
                .build();
    }
}
 
Example #15
Source File: ServiceFactory.java    From ReadMark with Apache License 2.0 6 votes vote down vote up
public static OkHttpClient getOkHttpClient() {
    if (okHttpClient == null) {
        synchronized (OkHttpClient.class) {
            if (okHttpClient == null) {
                File cacheFile = new File(BaseApplication.getApplication().getCacheDir(), "responses");
                Cache cache = new Cache(cacheFile, DEFAULT_CACHE_SIZE);

                HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
                interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
                okHttpClient = new OkHttpClient.Builder()
                        .cache(cache)
                        .retryOnConnectionFailure(true)
                        //.addInterceptor(interceptor)
                        //.addInterceptor(REQUEST_INTERCEPTOR)
                        //.addNetworkInterceptor(RESPONSE_INTERCEPTOR)
                        //.addInterceptor(LoggingInterceptor)
                        .build();
            }
        }
    }
    return okHttpClient;
}
 
Example #16
Source File: OkHttpSmartyStreetsHttpClient.java    From Smarty-Streets-AutoCompleteTextView with Apache License 2.0 6 votes vote down vote up
OkHttpSmartyStreetsHttpClient(SmartyStreetsApiJsonParser parser) {
    super(parser);

    OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder()
            .readTimeout(15L, TimeUnit.SECONDS)
            .connectTimeout(15L, TimeUnit.SECONDS)
            .writeTimeout(15L, TimeUnit.SECONDS);

    // Logging Interceptor to see what is happening with the request/response in LogCat
    if (Constants.DEBUG) {
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        clientBuilder.addInterceptor(loggingInterceptor);
    }

    okHttpClient = clientBuilder.build();
}
 
Example #17
Source File: ServiceFactory.java    From ReadMark with Apache License 2.0 6 votes vote down vote up
public static OkHttpClient getOkHttpClient() {
    if (okHttpClient == null) {
        synchronized (OkHttpClient.class) {
            if (okHttpClient == null) {
                File cacheFile = new File(BaseApplication.getApplication().getCacheDir(), "responses");
                Cache cache = new Cache(cacheFile, DEFAULT_CACHE_SIZE);

                HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
                interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
                okHttpClient = new OkHttpClient.Builder()
                        .cache(cache)
                        .retryOnConnectionFailure(true)
                        //.addInterceptor(interceptor)
                        //.addInterceptor(REQUEST_INTERCEPTOR)
                        //.addNetworkInterceptor(RESPONSE_INTERCEPTOR)
                        //.addInterceptor(LoggingInterceptor)
                        .build();
            }
        }
    }
    return okHttpClient;
}
 
Example #18
Source File: Example1_NoRX.java    From AnDevCon-RxPatterns with Apache License 2.0 6 votes vote down vote up
private void createGithubClient() {
    if (mGitHubClient == null) {

        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(loggingInterceptor)
                .addInterceptor(chain ->
                        chain.proceed(chain.request().newBuilder().addHeader("Authorization",
                                "token " + Secrets.GITHUB_PERSONAL_ACCESS_TOKEN).build())).build();

        mGitHubClient = new Retrofit.Builder()
                .client(client)
                .baseUrl(GITHUB_BASE_URL)
                .build()
                .create(GitHubClient.class);
    }
}
 
Example #19
Source File: MapboxSpeech.java    From mapbox-java with MIT License 6 votes vote down vote up
@Override
public synchronized OkHttpClient getOkHttpClient() {
  if (okHttpClient == null) {
    OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
    if (isEnableDebug()) {
      HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
      logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
      httpClient.addInterceptor(logging);
    }
    if (cache() != null) {
      httpClient.cache(cache());
    }
    if (interceptor() != null) {
      httpClient.addInterceptor(interceptor());
    }
    if (networkInterceptor() != null) {
      httpClient.addNetworkInterceptor(networkInterceptor());
    }

    okHttpClient = httpClient.build();
  }
  return okHttpClient;
}
 
Example #20
Source File: AppModule.java    From RESTMock with Apache License 2.0 6 votes vote down vote up
@Provides
GithubApi provideRestService() {
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
    if (socketFactory != null && trustManager != null) {
        clientBuilder.sslSocketFactory(socketFactory, trustManager);
    }
    clientBuilder.addInterceptor(interceptor);

    Retrofit retrofit = new Retrofit.Builder().baseUrl(baseUrl)
        .client(clientBuilder.build())
        .addConverterFactory(GsonConverterFactory.create())
        .build();

    return retrofit.create(GithubApi.class);
}
 
Example #21
Source File: StocksService.java    From Stock-Hawk with Apache License 2.0 6 votes vote down vote up
public static StocksService newStocksService() {

            HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
            logging.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY
                    : HttpLoggingInterceptor.Level.NONE);

            OkHttpClient okHttpClient = new OkHttpClient.Builder()
                    .addInterceptor(logging)
                    .build();

            Gson gson = new GsonBuilder()
                    .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
                    .setLenient()
                    .create();

            Retrofit retrofit = new Retrofit.Builder()
                    .baseUrl(StocksService.ENDPOINT)
                    .client(okHttpClient)
                    .addConverterFactory(GsonConverterFactory.create(gson))
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .build();
            return retrofit.create(StocksService.class);
        }
 
Example #22
Source File: MarvelApiConfig.java    From MarvelApiClientAndroid with Apache License 2.0 6 votes vote down vote up
private Retrofit buildRetrofit() {
  OkHttpClient.Builder builder = new OkHttpClient.Builder()
    .addInterceptor(new AuthInterceptor(publicKey, privateKey, timeProvider));
  if (debug) {
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    builder.addInterceptor(interceptor);
  }

  OkHttpClient client = builder.build();
  
  return new Retrofit.Builder().baseUrl(baseUrl)
      .client(client)
      .addConverterFactory(GsonConverterFactory.create())
      .build();
}
 
Example #23
Source File: DebugModule.java    From cathode with Apache License 2.0 6 votes vote down vote up
@Provides @Named(NAMED_TRAKT) Retrofit provideRestAdapter(@Named(NAMED_TRAKT) OkHttpClient client,
    @Named(NAMED_TRAKT) Gson gson, @Named(NAMED_STATUS_CODE) final IntPreference httpStatusCode,
    HttpLoggingInterceptor loggingInterceptor) {
  OkHttpClient.Builder builder = client.newBuilder();
  builder.networkInterceptors().add(new Interceptor() {
    @Override public Response intercept(Chain chain) throws IOException {
      final int statusCode = httpStatusCode.get();
      Response response = chain.proceed(chain.request());
      if (statusCode != 200) {
        Timber.d("Rewriting status code: %d", statusCode);
        response = response.newBuilder().code(statusCode).build();
      }
      return response;
    }
  });
  builder.interceptors().add(loggingInterceptor);
  return new Retrofit.Builder() //
      .baseUrl(TraktModule.API_URL)
      .client(builder.build())
      .addConverterFactory(GsonConverterFactory.create(gson))
      .build();
}
 
Example #24
Source File: UberRidesApi.java    From rides-java-sdk with MIT License 6 votes vote down vote up
/**
 * Create the {@link UberRidesApi} to be used.
 * @return {@link UberRidesApi}
 */
public UberRidesApi build() {
    if (logLevel == null) {
        logLevel = HttpLoggingInterceptor.Level.NONE;
    }

    if (logger == null) {
        logger = HttpLoggingInterceptor.Logger.DEFAULT;
    }

    if (client == null) {
        client = new OkHttpClient();
    }

    HttpLoggingInterceptor loggingInterceptor = createLoggingInterceptor(logger, logLevel);
    OkHttpClient newClient = createClient(client, session, loggingInterceptor);
    Retrofit retrofit = createRetrofit(newClient, session);

    return new UberRidesApi(retrofit);
}
 
Example #25
Source File: RetrofitHelper.java    From LeisureRead with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化OKHttpClient
 */
private static void initOkHttpClient() {

  HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
  interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
  if (mOkHttpClient == null) {
    synchronized (RetrofitHelper.class) {
      if (mOkHttpClient == null) {
        //设置Http缓存
        Cache cache = new Cache(
            new File(LeisureReadApp.getAppContext().getCacheDir(), "HttpCache"),
            1024 * 1024 * 100);

        mOkHttpClient = new OkHttpClient.Builder()
            .cache(cache)
            .addNetworkInterceptor(new CacheInterceptor())
            .addInterceptor(interceptor)
            .retryOnConnectionFailure(true)
            .connectTimeout(15, TimeUnit.SECONDS)
            .build();
      }
    }
  }
}
 
Example #26
Source File: OAuth2ServiceTest.java    From rides-java-sdk with MIT License 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    final HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
    loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);

    final OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .addInterceptor(loggingInterceptor)
            .build();

    final Moshi moshi = new Moshi.Builder().add(new OAuthScopesAdapter()).build();

    oAuth2Service = new Retrofit.Builder().baseUrl("http://localhost:" + wireMockRule.port())
            .client(okHttpClient)
            .addConverterFactory(MoshiConverterFactory.create(moshi))
            .build()
            .create(OAuth2Service.class);
}
 
Example #27
Source File: RetrofitBase.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static Retrofit getRetrofitInstance(final String TAG, final String url, boolean useGzip) throws IllegalArgumentException {

        Retrofit instance = instances.get(TAG);
        if (instance == null || !urls.get(TAG).equals(url)) {
            synchronized (instances) {
                if (emptyString(url)) {
                    UserError.Log.d(TAG, "Empty url - cannot create instance");
                    return null;
                }
                UserError.Log.d(TAG, "Creating new instance for: " + url);
                final HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
                if (D) {
                    httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
                }
                final OkHttpClient client = enableTls12OnPreLollipop(new OkHttpClient.Builder())
                        .addInterceptor(httpLoggingInterceptor)
                        .addInterceptor(new InfoInterceptor(TAG))
                        .addInterceptor(useGzip ? new GzipRequestInterceptor() : new NullInterceptor())
                        .build();

                instances.put(TAG, instance = new retrofit2.Retrofit.Builder()
                        .baseUrl(url)
                        .client(client)
                        .addConverterFactory(GsonConverterFactory.create())
                        .build());
                urls.put(TAG, url); // save creation url for quick search
            }
        }
        return instance;
    }
 
Example #28
Source File: AuthAPITest.java    From auth0-java with MIT License 5 votes vote down vote up
@Test
public void shouldDisableLoggingInterceptor() throws Exception {
    AuthAPI api = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET);
    assertThat(api.getClient().interceptors(), hasItem(isA(HttpLoggingInterceptor.class)));
    api.setLoggingEnabled(false);

    for (Interceptor i : api.getClient().interceptors()) {
        if (i instanceof HttpLoggingInterceptor) {
            HttpLoggingInterceptor logging = (HttpLoggingInterceptor) i;
            assertThat(logging.getLevel(), is(Level.NONE));
        }
    }
}
 
Example #29
Source File: AppModule.java    From Open-Mam with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
public OkHttpClient provideMainOkHttp() {
    return new OkHttpClient.Builder()
            .addInterceptor(new StethoInterceptor())
            .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .build();
}
 
Example #30
Source File: FtsRetrofitModule.java    From fingen with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
HttpLoggingInterceptor provideHttpLoggingInterceptor() {
	HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
	interceptor.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE);
	return interceptor;
}