Tabnine Logo
OkHttpClient$Builder.addNetworkInterceptor
Code IndexAdd Tabnine to your IDE (free)

How to use
addNetworkInterceptor
method
in
okhttp3.OkHttpClient$Builder

Best Java code snippets using okhttp3.OkHttpClient$Builder.addNetworkInterceptor (Showing top 20 results out of 1,314)

origin: square/okhttp

public void run() throws Exception {
 for (int i = 0; i < 5; i++) {
  System.out.println("    Request: " + i);
  Request request = new Request.Builder()
    .url("https://api.github.com/search/repositories?q=http")
    .build();
  OkHttpClient clientForCall;
  if (i == 2) {
   // Force this request's response to be written to the cache. This way, subsequent responses
   // can be read from the cache.
   System.out.println("Force cache: true");
   clientForCall = client.newBuilder()
     .addNetworkInterceptor(REWRITE_CACHE_CONTROL_INTERCEPTOR)
     .build();
  } else {
   System.out.println("Force cache: false");
   clientForCall = client;
  }
  try (Response response = clientForCall.newCall(request).execute()) {
   if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
   System.out.println("    Network: " + (response.networkResponse() != null));
   System.out.println();
  }
 }
}
origin: square/okhttp

.addNetworkInterceptor(chain -> {
 Response originalResponse = chain.proceed(chain.request());
 return originalResponse.newBuilder()
origin: cymcsg/UltimateAndroid

private GithubApiService() {
  OkHttpClient.Builder httpclientBuilder = new OkHttpClient.Builder();
  httpclientBuilder.connectTimeout(5, TimeUnit.SECONDS);
  httpclientBuilder.addNetworkInterceptor(new StethoInterceptor());
  retrofit = new Retrofit.Builder().client(httpclientBuilder.build()).addConverterFactory(GsonConverterFactory.create()).
      addCallAdapterFactory(RxJavaCallAdapterFactory.create()).baseUrl(BASE_URL).build();
  githubApiServiceInterface = retrofit.create(GithubApiServiceInterface.class);
}
origin: sunfusheng/GlideImageView

public static OkHttpClient getOkHttpClient() {
  if (okHttpClient == null) {
    okHttpClient = new OkHttpClient.Builder()
        .addNetworkInterceptor(chain -> {
          Request request = chain.request();
          Response response = chain.proceed(request);
          return response.newBuilder()
              .body(new ProgressResponseBody(request.url().toString(), LISTENER, response.body()))
              .build();
        })
        .build();
  }
  return okHttpClient;
}
origin: amitshekhariitbhu/Fast-Android-Networking

      .addNetworkInterceptor(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
} else {
  okHttpClient = sHttpClient.newBuilder()
      .addNetworkInterceptor(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
origin: commonsguy/cw-omnibus

 .addNetworkInterceptor(nightTrain)
 .build();
Request request=
origin: commonsguy/cw-omnibus

 .addNetworkInterceptor(nightTrain)
 .build();
Request request=
origin: hidroh/materialistic

.addNetworkInterceptor(new CacheOverrideNetworkInterceptor())
.addInterceptor(new ConnectionAwareInterceptor(context))
.addInterceptor(new LoggingInterceptor())
origin: jaydenxiao2016/AndroidFire

.connectTimeout(CONNECT_TIME_OUT, TimeUnit.MILLISECONDS)
.addInterceptor(mRewriteCacheControlInterceptor)
.addNetworkInterceptor(mRewriteCacheControlInterceptor)
.addInterceptor(headerInterceptor)
.addInterceptor(logInterceptor)
origin: amitshekhariitbhu/Fast-Android-Networking

      .newBuilder()
      .cache(InternalNetworking.sHttpClient.cache())
      .addNetworkInterceptor(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
} else {
  okHttpClient = InternalNetworking.sHttpClient.newBuilder()
      .addNetworkInterceptor(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
origin: amitshekhariitbhu/Fast-Android-Networking

      .newBuilder()
      .cache(InternalNetworking.sHttpClient.cache())
      .addNetworkInterceptor(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
} else {
  okHttpClient = InternalNetworking.sHttpClient.newBuilder()
      .addNetworkInterceptor(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
origin: testcontainers/testcontainers-java

.addNetworkInterceptor(chain -> {
  Response response = chain.proceed(chain.request());
  if (response.isSuccessful()) {
origin: Rukey7/MvpApp

/**
 * 初始化网络通信服务
 */
public static void init() {
  // 指定缓存路径,缓存大小100Mb
  Cache cache = new Cache(new File(AndroidApplication.getContext().getCacheDir(), "HttpCache"),
      1024 * 1024 * 100);
  OkHttpClient okHttpClient = new OkHttpClient.Builder().cache(cache)
      .retryOnConnectionFailure(true)
      .addInterceptor(sLoggingInterceptor)
      .addInterceptor(sRewriteCacheControlInterceptor)
      .addNetworkInterceptor(sRewriteCacheControlInterceptor)
      .connectTimeout(10, TimeUnit.SECONDS)
      .build();
  Retrofit retrofit = new Retrofit.Builder()
      .client(okHttpClient)
      .addConverterFactory(GsonConverterFactory.create())
      .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
      .baseUrl(NEWS_HOST)
      .build();
  sNewsService = retrofit.create(INewsApi.class);
  retrofit = new Retrofit.Builder()
      .client(okHttpClient)
      .addConverterFactory(GsonConverterFactory.create())
      .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
      .baseUrl(WELFARE_HOST)
      .build();
  sWelfareService = retrofit.create(IWelfareApi.class);
}
origin: JessYanCoding/MVPArms

.connectTimeout(TIME_OUT, TimeUnit.SECONDS)
.readTimeout(TIME_OUT, TimeUnit.SECONDS)
.addNetworkInterceptor(intercept);
origin: SonarSource/sonarqube

 builder.readTimeout(readTimeoutMs, TimeUnit.MILLISECONDS);
builder.addNetworkInterceptor(this::addHeaders);
if (proxyLogin != null) {
 builder.proxyAuthenticator((route, response) -> {
origin: north2016/T-MVP

private Api() {
  HttpLoggingInterceptor logInterceptor = new HttpLoggingInterceptor();
  logInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
  File cacheFile = new File(App.getAppContext().getCacheDir(), "cache");
  Cache cache = new Cache(cacheFile, 1024 * 1024 * 100); //100Mb
  OkHttpClient okHttpClient = new OkHttpClient.Builder()
      .readTimeout(7676, TimeUnit.MILLISECONDS)
      .connectTimeout(7676, TimeUnit.MILLISECONDS)
      .addInterceptor(headInterceptor)
      .addInterceptor(logInterceptor)
      .addNetworkInterceptor(new HttpCacheInterceptor())
      .cache(cache)
      .build();
  Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").serializeNulls().create();
  retrofit = new Retrofit.Builder()
      .client(okHttpClient)
      .addConverterFactory(GsonConverterFactory.create(gson))
      .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
      .baseUrl(C.BASE_URL)
      .build();
  service = retrofit.create(ApiService.class);
}
origin: HotBitmapGG/bilibili-android-client

/**
 * 初始化OKHttpClient,设置缓存,设置超时时间,设置打印日志,设置UA拦截器
 */
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(BilibiliApp.getInstance().getCacheDir(), "HttpCache"), 1024 * 1024 * 10);
        mOkHttpClient = new OkHttpClient.Builder()
            .cache(cache)
            .addInterceptor(interceptor)
            .addNetworkInterceptor(new CacheInterceptor())
            .addNetworkInterceptor(new StethoInterceptor())
            .retryOnConnectionFailure(true)
            .connectTimeout(30, TimeUnit.SECONDS)
            .writeTimeout(20, TimeUnit.SECONDS)
            .readTimeout(20, TimeUnit.SECONDS)
            .addInterceptor(new UserAgentInterceptor())
            .build();
      }
    }
  }
}
origin: JessYanCoding/ProgressManager

/**
 * 将 {@link okhttp3.OkHttpClient.Builder} 传入,配置一些本管理器需要的参数
 *
 * @param builder
 * @return
 */
public OkHttpClient.Builder with(OkHttpClient.Builder builder) {
  checkNotNull(builder, "builder cannot be null");
  return builder
      .addNetworkInterceptor(mInterceptor);
}
origin: Piasy/BigImageViewer

public static void init(Glide glide, OkHttpClient okHttpClient) {
  OkHttpClient.Builder builder;
  if (okHttpClient != null) {
    builder = okHttpClient.newBuilder();
  } else {
    builder = new OkHttpClient.Builder();
  }
  builder.addNetworkInterceptor(createInterceptor(new DispatchingProgressListener()));
  glide.getRegistry().replace(GlideUrl.class, InputStream.class,
      new OkHttpUrlLoader.Factory(builder.build()));
}
origin: facebook/stetho

@Before
public void setUp() {
 PowerMockito.mockStatic(NetworkEventReporterImpl.class);
 mMockEventReporter = mock(NetworkEventReporter.class);
 Mockito.when(mMockEventReporter.isEnabled()).thenReturn(true);
 PowerMockito.when(NetworkEventReporterImpl.get()).thenReturn(mMockEventReporter);
 mInterceptor = new StethoInterceptor();
 mClientWithInterceptor = new OkHttpClient.Builder()
     .addNetworkInterceptor(mInterceptor)
     .build();
}
okhttp3OkHttpClient$BuilderaddNetworkInterceptor

Popular methods of OkHttpClient$Builder

  • build
  • <init>
  • connectTimeout
    Sets the default connect timeout for new connections. A value of 0 means no timeout, otherwise value
  • addInterceptor
  • readTimeout
    Sets the default read timeout for new connections. A value of 0 means no timeout, otherwise values m
  • writeTimeout
    Sets the default write timeout for new connections. A value of 0 means no timeout, otherwise values
  • sslSocketFactory
    Sets the socket factory and trust manager used to secure HTTPS connections. If unset, the system def
  • cache
    Sets the response cache to be used to read and write cached responses.
  • hostnameVerifier
    Sets the verifier used to confirm that response certificates apply to requested hostnames for HTTPS
  • retryOnConnectionFailure
    Configure this client to retry or not when a connectivity problem is encountered. By default, this c
  • cookieJar
    Sets the handler that can accept cookies from incoming HTTP responses and provides cookies to outgoi
  • proxy
    Sets the HTTP proxy that will be used by connections created by this client. This takes precedence o
  • cookieJar,
  • proxy,
  • followRedirects,
  • proxyAuthenticator,
  • connectionPool,
  • connectionSpecs,
  • authenticator,
  • followSslRedirects,
  • dispatcher

Popular in Java

  • Reactive rest calls using spring rest template
  • onCreateOptionsMenu (Activity)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • startActivity (Activity)
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • Socket (java.net)
    Provides a client-side TCP socket.
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Top 12 Jupyter Notebook Extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now