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;
}
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;
}
use of com.pushtorefresh.storio3.Interceptor in project okhttp-digest by rburgst.
the class AuthenticationCacheInterceptorTest method testCaching__whenNoConnectionExists__shouldNotBombOut.
@Test
public void testCaching__whenNoConnectionExists__shouldNotBombOut() throws IOException {
Map<String, CachingAuthenticator> authCache = new ConcurrentHashMap<>();
Interceptor interceptor = new AuthenticationCacheInterceptor(authCache);
String auth = whenInterceptAuthenticationForUrlWithNoConnection(interceptor, "https://myhost.com:443");
assertNull(auth);
}
use of com.pushtorefresh.storio3.Interceptor in project okhttp-digest by rburgst.
the class DispatchingAuthenticatorTest method createUnauthorizedServerResponse.
private Response createUnauthorizedServerResponse() throws IOException {
final Map<String, CachingAuthenticator> authCache = new ConcurrentHashMap<>();
Interceptor interceptor = new AuthenticationCacheInterceptor(authCache);
return interceptor.intercept(new ChainAdapter(createDummyRequest(), mockConnection) {
@Override
public Response proceed(Request request) throws IOException {
return new Response.Builder().body(ResponseBody.create(MediaType.parse("text/plain"), "Unauthorized")).request(request).protocol(Protocol.HTTP_1_1).code(HTTP_UNAUTHORIZED).message("Unauthorized").header("WWW-Authenticate", "Basic realm=\"myrealm\"").build();
}
});
}
use of com.pushtorefresh.storio3.Interceptor in project autorest.java by Azure.
the class CustomBaseUriTests method getEmptyMultipleThreads.
@Test
public void getEmptyMultipleThreads() throws Exception {
final CountDownLatch latch = new CountDownLatch(2);
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder().addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// do nothing
}
return chain.proceed(chain.request());
}
});
final AutoRestParameterizedHostTestClient client1 = new AutoRestParameterizedHostTestClientImpl(clientBuilder, new Retrofit.Builder());
client1.withHost("host:3000");
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
try {
client1.paths().getEmpty("badlocal");
fail();
} catch (RuntimeException e) {
latch.countDown();
} catch (Exception e) {
fail();
}
}
});
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
try {
client1.paths().getEmpty("local");
latch.countDown();
} catch (Exception ex) {
fail();
}
}
});
t1.start();
t2.start();
Assert.assertTrue(latch.await(15, TimeUnit.SECONDS));
}
Aggregations