當前位置: 首頁>>代碼示例>>Java>>正文


Java StethoInterceptor類代碼示例

本文整理匯總了Java中com.facebook.stetho.okhttp3.StethoInterceptor的典型用法代碼示例。如果您正苦於以下問題:Java StethoInterceptor類的具體用法?Java StethoInterceptor怎麽用?Java StethoInterceptor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StethoInterceptor類屬於com.facebook.stetho.okhttp3包,在下文中一共展示了StethoInterceptor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initWeatherService

import com.facebook.stetho.okhttp3.StethoInterceptor; //導入依賴的package包/類
private static <T> T initWeatherService(String baseUrl, Class<T> clazz) {

        OkHttpClient.Builder builder = new OkHttpClient().newBuilder();
        if (BuildConfig.DEBUG) {
            HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
            httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            builder.addInterceptor(httpLoggingInterceptor).addNetworkInterceptor(new StethoInterceptor());
        }
        OkHttpClient client = builder.build();

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(baseUrl)
                .addConverterFactory(FastJsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(client)
                .build();

        return retrofit.create(clazz);
    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:ApiClient.java

示例2: create

import com.facebook.stetho.okhttp3.StethoInterceptor; //導入依賴的package包/類
private static Retrofit create() {
    OkHttpClient.Builder builder = new OkHttpClient().newBuilder();
    builder.readTimeout(10, TimeUnit.SECONDS);
    builder.connectTimeout(9, TimeUnit.SECONDS);
    builder.addNetworkInterceptor(new StethoInterceptor());

    if (BuildConfig.DEBUG) {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        builder.addInterceptor(interceptor);
    }

    return new Retrofit.Builder().baseUrl(ENDPOINT)
            .client(builder.build())
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:RetrofitProvider.java

示例3: getInstance

import com.facebook.stetho.okhttp3.StethoInterceptor; //導入依賴的package包/類
@SuppressLint("AuthLeak")
public static Retrofit getInstance(Context context) {
    if (httpClient == null) {
        httpClient = new OkHttpClient.Builder();
    }
    if (retrofit == null) {
        httpClient.addNetworkInterceptor(new StethoInterceptor())
                  .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                  .addInterceptor(provideOfflineCacheInterceptor(context))
                  .addNetworkInterceptor(provideCacheInterceptor())
                  .cache(provideCache(context));

        retrofit = new Retrofit.Builder()
                .baseUrl(baseUrl)
                .addConverterFactory(GsonConverterFactory.create())
                .client(httpClient.build())
                .build();
    }
    return retrofit;
}
 
開發者ID:barnhill,項目名稱:SimpleBible,代碼行數:21,代碼來源:DBTAPI.java

示例4: getInstance

import com.facebook.stetho.okhttp3.StethoInterceptor; //導入依賴的package包/類
@SuppressLint("AuthLeak")
public static Retrofit getInstance(Context context) {
    if (httpClient == null) {
        httpClient = new OkHttpClient.Builder();
    }
    if (retrofit == null) {
        httpClient.addNetworkInterceptor(new AuthenticationInterceptor(Credentials.basic(apiKey, "x")))
                  .addNetworkInterceptor(new StethoInterceptor())
                  .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                  .addInterceptor(provideOfflineCacheInterceptor(context))
                  .addNetworkInterceptor(provideCacheInterceptor())
                  .cache(provideCache(context));

        retrofit = new Retrofit.Builder()
                .baseUrl(baseUrl)
                .addConverterFactory(GsonConverterFactory.create())
                .client(httpClient.build())
                .build();
    }
    return retrofit;
}
 
開發者ID:barnhill,項目名稱:SimpleBible,代碼行數:22,代碼來源:BiblesOrgAPI.java

示例5: provideCall

import com.facebook.stetho.okhttp3.StethoInterceptor; //導入依賴的package包/類
@Provides
@Singleton
Retrofit provideCall() {
    OkHttpOAuthConsumer consumer = new OkHttpOAuthConsumer(App.getTwitterKey(),
            App.getTwitterSecret());
    consumer.setTokenWithSecret(
            App.getApplicationInstance().getTwitterSession().getAuthToken().token,
            App.getApplicationInstance().getTwitterSession().getAuthToken().secret);

    Retrofit.Builder builder =
            new Retrofit.Builder()
                    .baseUrl(baseUrl)
                    .addConverterFactory(GsonConverterFactory.create())
                    .addConverterFactory(ScalarsConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create());

    OkHttpClient client = new OkHttpClient.Builder()
            .addInterceptor(new SigningInterceptor(consumer))
            .addNetworkInterceptor(new StethoInterceptor())
            .build();

    return builder.client(client).build();
}
 
開發者ID:beraldofilippo,項目名稱:TWStreaming,代碼行數:24,代碼來源:NetworkModule.java

示例6: HttpRequestFactory

import com.facebook.stetho.okhttp3.StethoInterceptor; //導入依賴的package包/類
public HttpRequestFactory() {
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.HEADERS);

    OkHttpClient okHttpClient =
            new OkHttpClient.Builder().connectTimeout(TIMEOUT, TimeUnit.SECONDS)
                    .readTimeout(TIMEOUT, TimeUnit.SECONDS)
                    .writeTimeout(TIMEOUT, TimeUnit.SECONDS)
                    .cache(getCache())
                    .addInterceptor(logging)
                    .addNetworkInterceptor(mTokenInterceptor)
                    //應用攔截器,用於離線緩存
                    .addInterceptor(mCacheInterceptor)
                    //網絡攔截器,用於在線緩存
                    .addNetworkInterceptor(mCacheInterceptor)
                    .addNetworkInterceptor(new StethoInterceptor())
                    .build();

    Retrofit retrofit = new Retrofit.Builder().baseUrl(Constants.FanFou.FANFOU_API_URL)
            .addConverterFactory(ResponseConverterFactory.create())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .client(okHttpClient)
            .build();

    mServiceFactory = retrofit.create(ApiFactory.class);
}
 
開發者ID:betroy,項目名稱:xifan,代碼行數:27,代碼來源:HttpRequestFactory.java

示例7: onCreate

import com.facebook.stetho.okhttp3.StethoInterceptor; //導入依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();
    if (BuildConfig.DEBUG){
        Stetho.initializeWithDefaults(this);
    }
    ApiRESTful apiRESTful = ApiRESTful.getApiRESTful(this, false);
    apiRESTful.setModelUrl(AppConfig.HOST);
    apiRESTful.setPushWs("");
    apiRESTful.setAutoToWs(false);
    apiRESTful.setCardId("04df-ee031b69-0000-4e02-8a56-41736fc1226a-e0000000");
    apiRESTful.setHeadersPrefix("x-hz-");
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.addNetworkInterceptor(new StethoInterceptor());
    //apiRESTful.setOKHttpClientBuider(builder);
    ALog.debug = true;
}
 
開發者ID:huangjingqiang,項目名稱:SWDemo,代碼行數:18,代碼來源:AGApplication.java

示例8: post

import com.facebook.stetho.okhttp3.StethoInterceptor; //導入依賴的package包/類
/**
 * POST function that help to create and HTTP GET request
 * @param url A variable of type String
 * @param formBody A Variable of type Request Body
 * @return A Response of get request
 * @see Response
 */
static Response post(String url, RequestBody formBody){
    OkHttpClient.Builder httpBuilder = new OkHttpClient.Builder()
            .connectTimeout(timeout, TimeUnit.SECONDS)
            .readTimeout(timeout, TimeUnit.SECONDS);
    if(NyrisEndpoints.DEBUG)
        httpBuilder.networkInterceptors().add(new StethoInterceptor());
    OkHttpClient mHttpClient = httpBuilder.build();

    Request request = new Request.Builder()
            .url(url)
            .addHeader("User-Agent", userAgent)
            .post(formBody)
            .build();
    try{
        return mHttpClient.newCall(request).execute();
    }
    catch (Exception e){
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:nyris,項目名稱:Nyris.IMX.Android,代碼行數:29,代碼來源:HttpRequestHelper.java

示例9: GankRetrofit

import com.facebook.stetho.okhttp3.StethoInterceptor; //導入依賴的package包/類
GankRetrofit() {
  HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
  interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
  OkHttpClient client = new OkHttpClient.Builder()
      .addInterceptor(interceptor)
      .addNetworkInterceptor(new HeaderInterceptor())
      .addNetworkInterceptor(new StethoInterceptor())
      .retryOnConnectionFailure(true)
      .connectTimeout(15, TimeUnit.SECONDS)
      .build();

  Retrofit retrofit = new Retrofit.Builder()
      .baseUrl("http://gank.io/api/")
      .client(client)
      .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
      .addConverterFactory(GsonConverterFactory.create())
      .build();

  gankService = retrofit.create(GankApi.class);
}
 
開發者ID:zpjayyy,項目名稱:GankForMVP,代碼行數:21,代碼來源:GankRetrofit.java

示例10: initOkHttpClient

import com.facebook.stetho.okhttp3.StethoInterceptor; //導入依賴的package包/類
/**
 * 初始化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(MoeQuestApp.getContext().getCacheDir(), "HttpCache"),
            1024 * 1024 * 100);

        mOkHttpClient = new OkHttpClient.Builder()
            .cache(cache)
            .addInterceptor(interceptor)
            .addNetworkInterceptor(new StethoInterceptor())
            .retryOnConnectionFailure(true)
            .connectTimeout(20, TimeUnit.SECONDS)
            .build();
      }
    }
  }
}
 
開發者ID:HotBitmapGG,項目名稱:MoeQuest,代碼行數:26,代碼來源:RetrofitHelper.java

示例11: registerComponents

import com.facebook.stetho.okhttp3.StethoInterceptor; //導入依賴的package包/類
@Override public void registerComponents(Context context, Glide glide) {
		Stetho.initializeWithDefaults(context);
		final Cache cache = new Cache(new File(context.getCacheDir(), "okhttp"), IMAGE_CACHE_SIZE);

		HttpLoggingInterceptor logger = new HttpLoggingInterceptor();
//		logger.setLevel(Level.BASIC);

		OkHttpClient client = new OkHttpClient()
				.newBuilder()
				.cache(cache)
				.addNetworkInterceptor(new StethoInterceptor())
				.addInterceptor(logger)
				.build();

		glide.register(CachedGlideUrl.class, InputStream.class,
				superFactory(new OkHttpUrlLoader.Factory(client), CachedGlideUrl.class));
		glide.register(ForceLoadGlideUrl.class, InputStream.class,
				superFactory(new OkHttpUrlLoader.Factory(client), ForceLoadGlideUrl.class));
	}
 
開發者ID:TWiStErRob,項目名稱:glide-support,代碼行數:20,代碼來源:GlideModule.java

示例12: providerDataOkHttpClient

import com.facebook.stetho.okhttp3.StethoInterceptor; //導入依賴的package包/類
@Data
@Provides
@Singleton
OkHttpClient providerDataOkHttpClient(@Data OkHttpClient.Builder builder) {
    Preconditions.checkState("debug".equals(BuildConfig.BUILD_TYPE));

    //log
    builder.addNetworkInterceptor(new StethoInterceptor());
    //trust https
    try {
        X509TrustManager trustManager = new NullTrustManager();
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, new TrustManager[]{trustManager}, new SecureRandom());
        builder.sslSocketFactory(sslContext.getSocketFactory(), trustManager);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return builder.build();
}
 
開發者ID:ykrank,項目名稱:S1-Next,代碼行數:20,代碼來源:BuildTypeModule.java

示例13: providerImageOkHttpClient

import com.facebook.stetho.okhttp3.StethoInterceptor; //導入依賴的package包/類
@Image
@Provides
@Singleton
OkHttpClient providerImageOkHttpClient(@Image OkHttpClient.Builder builder) {
    Preconditions.checkState("debug".equals(BuildConfig.BUILD_TYPE));

    //log
    builder.addNetworkInterceptor(new StethoInterceptor());
    //trust https
    try {
        X509TrustManager trustManager = new NullTrustManager();
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, new TrustManager[]{trustManager}, new SecureRandom());
        builder.sslSocketFactory(sslContext.getSocketFactory(), trustManager);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return builder.build();
}
 
開發者ID:ykrank,項目名稱:S1-Next,代碼行數:20,代碼來源:BuildTypeModule.java

示例14: providerAppdataOkHttpClient

import com.facebook.stetho.okhttp3.StethoInterceptor; //導入依賴的package包/類
@AppData
@Provides
@Singleton
OkHttpClient providerAppdataOkHttpClient(@AppData OkHttpClient.Builder builder) {
    Preconditions.checkState("debug".equals(BuildConfig.BUILD_TYPE));

    //log
    builder.addNetworkInterceptor(new StethoInterceptor());
    //trust https
    try {
        X509TrustManager trustManager = new NullTrustManager();
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, new TrustManager[]{trustManager}, new SecureRandom());
        builder.sslSocketFactory(sslContext.getSocketFactory(), trustManager);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return builder.build();
}
 
開發者ID:ykrank,項目名稱:S1-Next,代碼行數:20,代碼來源:BuildTypeModule.java

示例15: initOkHttpClient

import com.facebook.stetho.okhttp3.StethoInterceptor; //導入依賴的package包/類
/**
 * 初始化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(GankApp.getContext().getCacheDir(), "HttpCache"),
            1024 * 1024 * 100);

        mOkHttpClient = new OkHttpClient.Builder()
            .cache(cache)
            .addInterceptor(interceptor)
            .addNetworkInterceptor(new StethoInterceptor())
            .retryOnConnectionFailure(true)
            .connectTimeout(15, TimeUnit.SECONDS)
            .build();
      }
    }
  }
}
 
開發者ID:HotBitmapGG,項目名稱:gank.io-unofficial-android-client,代碼行數:26,代碼來源:RetrofitHelper.java


注:本文中的com.facebook.stetho.okhttp3.StethoInterceptor類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。