本文整理汇总了Java中com.facebook.stetho.okhttp.StethoInterceptor类的典型用法代码示例。如果您正苦于以下问题:Java StethoInterceptor类的具体用法?Java StethoInterceptor怎么用?Java StethoInterceptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StethoInterceptor类属于com.facebook.stetho.okhttp包,在下文中一共展示了StethoInterceptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRestAdapter
import com.facebook.stetho.okhttp.StethoInterceptor; //导入依赖的package包/类
/**
* Initializes the adapter and returns it
* The REST Adapter is created with Retrofit methods defined in MainApiClient
* Injects authorization headers into request
* Inspects status codes from response
* @return rest adapter
*/
private MainApiClient getRestAdapter() {
httpClient = new OkHttpClient();
httpClient.networkInterceptors().add(new StethoInterceptor());
httpClient.interceptors().add(new Interceptor() {
@Override
public com.squareup.okhttp.Response intercept(Chain chain) throws IOException {
Request request = chain.request();
com.squareup.okhttp.Response response = chain.proceed(request);
statusCode = response.code();
return response;
}
});
mRestAdapter = new RestAdapter.Builder()
.setEndpoint(URL_UAT)
.setClient(new OkClient(httpClient))
.setRequestInterceptor(authHeader())
.setLogLevel(RestAdapter.LogLevel.FULL)
.build();
return mRestAdapter.create(MainApiClient.class);
}
示例2: instance
import com.facebook.stetho.okhttp.StethoInterceptor; //导入依赖的package包/类
public static APIService instance() {
synchronized (APIFactory.class) {
if (sAPIServiceInstance == null) {
Gson gson = new GsonBuilder()
.create();
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(new StethoInterceptor());
/**
* please see http://git.io/vcure to setup your own server
* or PM @joshlopes to ask for our domain/clientId/secret
*/
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(LoopAnimeAPISettings.BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();
sAPIServiceInstance = retrofit.create(APIService.class);
}
}
return sAPIServiceInstance;
}
示例3: instance
import com.facebook.stetho.okhttp.StethoInterceptor; //导入依赖的package包/类
public static API instance() {
if (instance == null) {
OkHttpClient client = new OkHttpClient();
if (BuildConfig.DEBUG) {
client.networkInterceptors().add(new StethoInterceptor());
}
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(BASE_URL)
.setClient(new OkClient(client))
.setLogLevel(RestAdapter.LogLevel.FULL)
.build();
instance = new API(restAdapter.create(APIGet.class));
}
return instance;
}
示例4: setPicasso
import com.facebook.stetho.okhttp.StethoInterceptor; //导入依赖的package包/类
public void setPicasso() {
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(new StethoInterceptor());
File cache = new File(this.getCacheDir(), PICASSO_CACHE);
if (!cache.exists()) {
//noinspection ResultOfMethodCallIgnored
cache.mkdirs();
}
try {
client.setCache(new Cache(cache, PICASSO_CACHE_SIZE));
} catch (IOException e) {
e.printStackTrace();
}
Picasso picasso = new Picasso.Builder(this)
.downloader(new OkHttpDownloader(client))
.build();
Picasso.setSingletonInstance(picasso);
}
示例5: providesOkHttpClient
import com.facebook.stetho.okhttp.StethoInterceptor; //导入依赖的package包/类
@Provides
@Singleton
public OkHttpClient providesOkHttpClient(Context context) {
OkHttpClient client = new OkHttpClient();
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
client.interceptors().add(interceptor);
client.networkInterceptors().add(new StethoInterceptor());
File httpCacheDir = new File(context.getCacheDir() + "/okhttp");
httpCacheDir.mkdirs();
cleanDir(httpCacheDir);
long httpCacheSize = 50 * 1024 * 1024; // 50 MiB
Cache cache = new Cache(httpCacheDir, httpCacheSize);
client.setCache(cache);
return client;
}
示例6: LoginViewModel
import com.facebook.stetho.okhttp.StethoInterceptor; //导入依赖的package包/类
public LoginViewModel() {
List<Interceptor> interceptors = new ArrayList<>();
interceptors.add(new StethoInterceptor());
interceptors.add(chain -> {
Response response = chain.proceed(chain.request());
List<String> cookieHeaders = response.headers("set-cookie");
for (String header : cookieHeaders) {
if (header.contains("user")) {
mUserCookie = header.split(";")[0];
}
else if(header.contains("__cfduid")){
mCfduid = header.split(";")[0];
}
}
return response;
});
DaggerNetworkServiceComponent.builder()
.okClientModule(new OkClientModule(interceptors))
.appModule(HackerNewsApplication.getAppModule())
.appComponent(HackerNewsApplication.getAppComponent())
.build()
.inject(this);
}
示例7: NetworkingModule
import com.facebook.stetho.okhttp.StethoInterceptor; //导入依赖的package包/类
NetworkingModule(
ReactApplicationContext reactContext,
@Nullable String defaultUserAgent,
OkHttpClient client) {
super(reactContext);
mClient = client;
mClient.networkInterceptors().add(new StethoInterceptor());
mCookieHandler = new ForwardingCookieHandler(reactContext);
mShuttingDown = false;
mDefaultUserAgent = defaultUserAgent;
}
示例8: provideOkHttp
import com.facebook.stetho.okhttp.StethoInterceptor; //导入依赖的package包/类
@Provides
@Singleton
OkHttpClient provideOkHttp(final Cache cache, LoggerInterceptor loggerInterceptor,
StethoInterceptor stethoInterceptor) {
final OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setCache(cache);
okHttpClient.networkInterceptors().add(loggerInterceptor);
okHttpClient.networkInterceptors().add(stethoInterceptor);
okHttpClient.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
okHttpClient.setReadTimeout(DEFAULT_READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
okHttpClient.setWriteTimeout(DEFAULT_WRITE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
return okHttpClient;
}
示例9: getOkClient
import com.facebook.stetho.okhttp.StethoInterceptor; //导入依赖的package包/类
/**
* 用于Stethoscope调试的ttpClient
*/
public static OkClient getOkClient() {
OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
client.setReadTimeout(READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
client.networkInterceptors().add(new StethoInterceptor());
return new OkClient(client);
}
示例10: onCreate
import com.facebook.stetho.okhttp.StethoInterceptor; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(new StethoInterceptor());
}
示例11: provideOkHttpClient
import com.facebook.stetho.okhttp.StethoInterceptor; //导入依赖的package包/类
@Provides
@Singleton
OkHttpClient provideOkHttpClient(Interceptor interceptor) {
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.interceptors().add(interceptor);
if (BuildConfig.DEBUG)
okHttpClient.networkInterceptors().add(new StethoInterceptor());
return okHttpClient;
}
示例12: getClient
import com.facebook.stetho.okhttp.StethoInterceptor; //导入依赖的package包/类
public static OkHttpClient getClient() {
if (client == null) {
client = new OkHttpClient();
client.setReadTimeout(10, TimeUnit.SECONDS);
client.networkInterceptors().add(new StethoInterceptor());
}
return client;
}
示例13: createClient
import com.facebook.stetho.okhttp.StethoInterceptor; //导入依赖的package包/类
private OkHttpClient createClient() {
HttpLoggingInterceptor.Level logLevel = HttpLoggingInterceptor.Level.BODY;
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(logLevel);
final OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.networkInterceptors().add(new StethoInterceptor());
okHttpClient.networkInterceptors().add(httpLoggingInterceptor);
okHttpClient.setReadTimeout(10000, TimeUnit.MILLISECONDS);
okHttpClient.setConnectTimeout(15000, TimeUnit.MILLISECONDS);
return okHttpClient;
}
示例14: providesOkClient
import com.facebook.stetho.okhttp.StethoInterceptor; //导入依赖的package包/类
@Provides
@Named("okclient")
OkClient providesOkClient(){
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setFollowRedirects(true);
okHttpClient.setFollowSslRedirects(true);
if(mInterceptorList != null){
okHttpClient.networkInterceptors().addAll(mInterceptorList);
}
okHttpClient.networkInterceptors().add(new StethoInterceptor());
return new OkClient(okHttpClient);
}
示例15: provideNetworkInterceptors
import com.facebook.stetho.okhttp.StethoInterceptor; //导入依赖的package包/类
@Provides
@Singleton
@ApiModule.NetworkInterceptors
List<Interceptor> provideNetworkInterceptors() {
ArrayList<Interceptor> networkInterceptors = new ArrayList<>();
networkInterceptors.add(new StethoInterceptor());
return networkInterceptors;
}