/** * 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); }
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; }
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; }
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); }
@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; }
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); }
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; }
@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; }
/** * 用于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); }
@Override public void onCreate() { super.onCreate(); Stetho.initializeWithDefaults(this); OkHttpClient client = new OkHttpClient(); client.networkInterceptors().add(new StethoInterceptor()); }
@Provides @Singleton OkHttpClient provideOkHttpClient(Interceptor interceptor) { OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.interceptors().add(interceptor); if (BuildConfig.DEBUG) okHttpClient.networkInterceptors().add(new StethoInterceptor()); return okHttpClient; }
public static OkHttpClient getClient() { if (client == null) { client = new OkHttpClient(); client.setReadTimeout(10, TimeUnit.SECONDS); client.networkInterceptors().add(new StethoInterceptor()); } return client; }
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; }
@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); }
@Provides @Singleton @ApiModule.NetworkInterceptors List<Interceptor> provideNetworkInterceptors() { ArrayList<Interceptor> networkInterceptors = new ArrayList<>(); networkInterceptors.add(new StethoInterceptor()); return networkInterceptors; }
@Override public void registerComponents(Context context, Glide glide) { if (BuildConfig.DEBUG) { OkHttpClient client = new OkHttpClient(); client.networkInterceptors().add(new StethoInterceptor()); OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory(client); glide.register(GlideUrl.class, InputStream.class, factory); } }
@Provides @Singleton OkHttpClient provideOkHttpClient() { OkHttpClient client = new OkHttpClient(); client.networkInterceptors().add(new StethoInterceptor()); return client; }
@Provides @Singleton StethoInterceptor stethoInterceptor() { return new StethoInterceptor(); }
public static void addStethoInterceptor(OkHttpClient client) { client.networkInterceptors().add(new StethoInterceptor()); }
public static RestClient getInstance(final Credentials credentials) { OkHttpClient client = OkHttpClientFactory.makeClient(); client.networkInterceptors().add(new StethoInterceptor()); return new RestClient(credentials, client); }
public static OkHttpClient getClient() { OkHttpClient client = new OkHttpClient(); client.networkInterceptors().add(new StethoInterceptor()); return client; }
@Override public OkHttpClient provideOkHttpClient(Application app) { OkHttpClient client = super.provideOkHttpClient(app); client.networkInterceptors().add(new StethoInterceptor()); return client; }