use of okhttp3.Credentials in project JavaSDK by OpenGamma.
the class BasicTest method testAuthGoodHttpFactory.
public void testAuthGoodHttpFactory() {
AuthClient mockAuth = new TestingAuthClient();
try (ServiceInvoker invoker = ServiceInvoker.builder(CREDENTIALS).httpClientFactory(builder -> builder.addInterceptor(chain -> chain.proceed(chain.request())).followRedirects(false).build()).authClientFactory(inv -> mockAuth).build()) {
assertEquals(invoker.getServiceUrl(), SERVICE_URL);
// logging, user-agent & auth plus one from test
assertEquals(invoker.getHttpClient().interceptors().size(), 4);
assertEquals(invoker.getHttpClient().followRedirects(), false);
}
}
use of okhttp3.Credentials in project JavaSDK by OpenGamma.
the class BasicTest method testAuthGoodHttpClient.
public void testAuthGoodHttpClient() {
AuthClient mockAuth = new TestingAuthClient();
try (ServiceInvoker invoker = ServiceInvoker.builder(CREDENTIALS).httpClient(new OkHttpClient()).authClientFactory(inv -> mockAuth).build()) {
assertEquals(invoker.getServiceUrl(), SERVICE_URL);
// user-agent & auth
assertEquals(invoker.getHttpClient().interceptors().size(), 2);
}
}
use of okhttp3.Credentials in project mbed-cloud-sdk-java by ARMmbed.
the class HttpBasicAuth method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
// If the request already have an authorization (eg. Basic auth), do nothing
if (request.header("Authorization") == null) {
String credentials = Credentials.basic(username, password);
request = request.newBuilder().addHeader("Authorization", credentials).build();
}
return chain.proceed(request);
}
use of okhttp3.Credentials in project mbed-cloud-sdk-java by ARMmbed.
the class HttpBasicAuth method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
// If the request already have an authorization (eg. Basic auth), do nothing
if (request.header("Authorization") == null) {
String credentials = Credentials.basic(username, password);
request = request.newBuilder().addHeader("Authorization", credentials).build();
}
return chain.proceed(request);
}
use of okhttp3.Credentials in project mbed-cloud-sdk-java by ARMmbed.
the class HttpBasicAuth method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
// If the request already have an authorization (eg. Basic auth), do nothing
if (request.header("Authorization") == null) {
String credentials = Credentials.basic(username, password);
request = request.newBuilder().addHeader("Authorization", credentials).build();
}
return chain.proceed(request);
}
Aggregations