Search in sources :

Example 51 with Interceptor

use of com.pushtorefresh.storio3.Interceptor in project azure-iot-sdk-java by Azure.

the class ServiceClientCredentialsProvider method applyCredentialsFilter.

@Override
public void applyCredentialsFilter(OkHttpClient.Builder clientBuilder) {
    Interceptor authenticationInterceptor = chain -> {
        Request authenticatedRequest = chain.request().newBuilder().header(AUTHORIZATION, sasTokenProvider.getSasToken()).build();
        return chain.proceed(authenticatedRequest);
    };
    clientBuilder.interceptors().add(authenticationInterceptor);
}
Also used : Interceptor(okhttp3.Interceptor) Request(okhttp3.Request) OkHttpClient(okhttp3.OkHttpClient) NonNull(lombok.NonNull) ServiceClientCredentials(com.microsoft.rest.credentials.ServiceClientCredentials) AllArgsConstructor(lombok.AllArgsConstructor) Request(okhttp3.Request) Interceptor(okhttp3.Interceptor)

Example 52 with Interceptor

use of com.pushtorefresh.storio3.Interceptor in project azure-iot-sdk-java by Azure.

the class ServiceClientBearerTokenCredentialProvider method applyCredentialsFilter.

@Override
public void applyCredentialsFilter(OkHttpClient.Builder clientBuilder) {
    Interceptor authenticationInterceptor = chain -> {
        String authorizationValue = tokenProvider.getBearerToken();
        Request authenticatedRequest = chain.request().newBuilder().header(AUTHORIZATION, authorizationValue).build();
        return chain.proceed(authenticatedRequest);
    };
    clientBuilder.interceptors().add(authenticationInterceptor);
}
Also used : Interceptor(okhttp3.Interceptor) Request(okhttp3.Request) OkHttpClient(okhttp3.OkHttpClient) NonNull(lombok.NonNull) ServiceClientCredentials(com.microsoft.rest.credentials.ServiceClientCredentials) AllArgsConstructor(lombok.AllArgsConstructor) Request(okhttp3.Request) Interceptor(okhttp3.Interceptor)

Example 53 with Interceptor

use of com.pushtorefresh.storio3.Interceptor in project BigImageViewer by Piasy.

the class GlideProgressSupport method createInterceptor.

private static Interceptor createInterceptor(final ResponseProgressListener listener) {
    return new Interceptor() {

        @Override
        public Response intercept(Chain chain) throws IOException {
            Request request = chain.request();
            Response response = chain.proceed(request);
            return response.newBuilder().body(new OkHttpProgressResponseBody(request.url(), response.body(), listener)).build();
        }
    };
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) Interceptor(okhttp3.Interceptor)

Example 54 with Interceptor

use of com.pushtorefresh.storio3.Interceptor in project storio by pushtorefresh.

the class ChainImpl method proceed.

// can be null on PreparedGetObject
@Nullable
@Override
public <Result, WrappedResult, Data> Result proceed(@NonNull PreparedOperation<Result, WrappedResult, Data> operation) {
    if (!interceptors.hasNext()) {
        throw new IllegalStateException("proceed was called on empty iterator");
    }
    calls++;
    // Confirm that this is the only call to chain.proceed().
    if (calls > 1) {
        throw new IllegalStateException("nextInterceptor " + interceptors.previous() + " must call proceed() exactly once");
    }
    // Call the nextChain nextInterceptor in the chain.
    final Interceptor nextInterceptor = interceptors.next();
    final ChainImpl nextChain = new ChainImpl(interceptors);
    return nextInterceptor.intercept(operation, nextChain);
}
Also used : Interceptor(com.pushtorefresh.storio3.Interceptor) Nullable(android.support.annotation.Nullable)

Example 55 with Interceptor

use of com.pushtorefresh.storio3.Interceptor in project storio by pushtorefresh.

the class ChainImpl method buildChain.

@NonNull
public static Interceptor.Chain buildChain(@NonNull List<Interceptor> registeredInterceptors, @NonNull Interceptor realInterceptor) {
    final List<Interceptor> interceptors = new ArrayList<Interceptor>(registeredInterceptors.size() + 1);
    interceptors.addAll(registeredInterceptors);
    interceptors.add(realInterceptor);
    for (Interceptor interceptor : interceptors) {
        if (interceptor == null) {
            throw new IllegalArgumentException("Interceptor should not be null");
        }
    }
    return new ChainImpl(interceptors.listIterator());
}
Also used : ArrayList(java.util.ArrayList) Interceptor(com.pushtorefresh.storio3.Interceptor) NonNull(android.support.annotation.NonNull)

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