Search in sources :

Example 26 with Interceptor

use of com.pushtorefresh.storio3.Interceptor in project mbed-cloud-sdk-java by ARMmbed.

the class GsonCustomConverterFactory method setCredentials.

/**
 * Helper method to configure the username/password for basic auth or password oauth
 * @param username Username
 * @param password Password
 * @return ApiClient
 */
public ApiClient setCredentials(String username, String password) {
    for (Interceptor apiAuthorization : apiAuthorizations.values()) {
        if (apiAuthorization instanceof HttpBasicAuth) {
            HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization;
            basicAuth.setCredentials(username, password);
            return this;
        }
        if (apiAuthorization instanceof OAuth) {
            OAuth oauth = (OAuth) apiAuthorization;
            oauth.getTokenRequestBuilder().setUsername(username).setPassword(password);
            return this;
        }
    }
    return this;
}
Also used : HttpBasicAuth(com.arm.mbed.cloud.sdk.internal.iam.auth.HttpBasicAuth) Interceptor(okhttp3.Interceptor) OAuth(com.arm.mbed.cloud.sdk.internal.iam.auth.OAuth)

Example 27 with Interceptor

use of com.pushtorefresh.storio3.Interceptor in project mbed-cloud-sdk-java by ARMmbed.

the class GsonCustomConverterFactory method setApiKey.

/**
 * Helper method to configure the first api key found
 * @param apiKey API key
 * @return ApiClient
 */
public ApiClient setApiKey(String apiKey) {
    for (Interceptor apiAuthorization : apiAuthorizations.values()) {
        if (apiAuthorization instanceof ApiKeyAuth) {
            ApiKeyAuth keyAuth = (ApiKeyAuth) apiAuthorization;
            keyAuth.setApiKey(apiKey);
            return this;
        }
    }
    return this;
}
Also used : ApiKeyAuth(com.arm.mbed.cloud.sdk.internal.iam.auth.ApiKeyAuth) Interceptor(okhttp3.Interceptor)

Example 28 with Interceptor

use of com.pushtorefresh.storio3.Interceptor in project mbed-cloud-sdk-java by ARMmbed.

the class GsonCustomConverterFactory method setCredentials.

/**
 * Helper method to configure the username/password for basic auth or password oauth
 * @param username Username
 * @param password Password
 * @return ApiClient
 */
public ApiClient setCredentials(String username, String password) {
    for (Interceptor apiAuthorization : apiAuthorizations.values()) {
        if (apiAuthorization instanceof HttpBasicAuth) {
            HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization;
            basicAuth.setCredentials(username, password);
            return this;
        }
        if (apiAuthorization instanceof OAuth) {
            OAuth oauth = (OAuth) apiAuthorization;
            oauth.getTokenRequestBuilder().setUsername(username).setPassword(password);
            return this;
        }
    }
    return this;
}
Also used : HttpBasicAuth(com.arm.mbed.cloud.sdk.internal.devicedirectory.auth.HttpBasicAuth) Interceptor(okhttp3.Interceptor) OAuth(com.arm.mbed.cloud.sdk.internal.devicedirectory.auth.OAuth)

Example 29 with Interceptor

use of com.pushtorefresh.storio3.Interceptor in project mbed-cloud-sdk-java by ARMmbed.

the class GsonCustomConverterFactory method setAccessToken.

/**
 * Helper method to pre-set the oauth access token of the first oauth found in the apiAuthorizations (there should be only one)
 * @param accessToken Access token
 * @return ApiClient
 */
public ApiClient setAccessToken(String accessToken) {
    for (Interceptor apiAuthorization : apiAuthorizations.values()) {
        if (apiAuthorization instanceof OAuth) {
            OAuth oauth = (OAuth) apiAuthorization;
            oauth.setAccessToken(accessToken);
            return this;
        }
    }
    return this;
}
Also used : Interceptor(okhttp3.Interceptor) OAuth(com.arm.mbed.cloud.sdk.internal.devicedirectory.auth.OAuth)

Example 30 with Interceptor

use of com.pushtorefresh.storio3.Interceptor in project MyBaseApplication by BanShouWeng.

the class NetUtils method initBaseData.

/**
 * 初始化数据
 *
 * @param action 当前请求的尾址
 */
private Retrofit initBaseData(final String action) {
    // 监听请求条件
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.connectTimeout(5, TimeUnit.SECONDS);
    builder.addInterceptor(new Interceptor() {

        @Override
        public okhttp3.Response intercept(Chain chain) throws IOException {
            Request request = chain.request();
            Logger.i("zzz", "request====" + action);
            Logger.i("zzz", "request====" + request.headers().toString());
            Logger.i("zzz", "request====" + request.toString());
            okhttp3.Response proceed = chain.proceed(request);
            Logger.i("zzz", "proceed====" + proceed.headers().toString());
            return proceed;
        }
    });
    Retrofit.Builder builder1 = new Retrofit.Builder().client(// 配置监听请求
    builder.build()).addConverterFactory(// 请求结果转换(当前为GSON)
    GsonConverterFactory.create()).addCallAdapterFactory(// 请求接受工具(当前为RxJava2)
    RxJava2CallAdapterFactory.create());
    builder1.baseUrl(BuildConfig.BASE_URL + action.substring(0, action.lastIndexOf("/") + 1));
    return builder1.build();
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) IOException(java.io.IOException) Interceptor(okhttp3.Interceptor)

Aggregations

Interceptor (okhttp3.Interceptor)138 Request (okhttp3.Request)61 OkHttpClient (okhttp3.OkHttpClient)54 Response (okhttp3.Response)51 IOException (java.io.IOException)45 Test (org.junit.Test)29 Retrofit (retrofit2.Retrofit)27 File (java.io.File)15 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)13 Cache (okhttp3.Cache)9 HttpUrl (okhttp3.HttpUrl)8 Interceptor (com.pushtorefresh.storio3.Interceptor)7 Dispatcher (okhttp3.Dispatcher)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 X509TrustManager (javax.net.ssl.X509TrustManager)6 CachingAuthenticator (com.burgstaller.okhttp.digest.CachingAuthenticator)5 Provides (dagger.Provides)5 Singleton (javax.inject.Singleton)5 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)5 OAuth (com.arm.mbed.cloud.sdk.internal.devicedirectory.auth.OAuth)4