本文整理匯總了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);
}
示例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();
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
}
}
}
示例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));
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
}
}
}