use of okhttp3.Dispatcher in project CubedPay-Java by MelonDevelopment.
the class CubedPayAPI method shutdown.
default void shutdown() throws InterruptedException {
Dispatcher dispatcher = DispatcherMap.dispatcherMap.remove(this);
dispatcher.cancelAll();
dispatcher.executorService().shutdown();
dispatcher.executorService().awaitTermination(10, TimeUnit.SECONDS);
for (ExecutorService executor : EventMap.eventMap.values()) {
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
}
}
use of okhttp3.Dispatcher in project CubedPay-Java by MelonDevelopment.
the class CubedPayAPI method create.
static CubedPayAPI create(String appID, String accessToken, String apiUrl) {
Dispatcher dispatcher = new Dispatcher();
CubedPayAPI api = new Retrofit.Builder().baseUrl(apiUrl).addConverterFactory(new Converter.Factory() {
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
return super.responseBodyConverter(type, annotations, retrofit);
}
}).addConverterFactory(new APIEnvelopeTransformerConverterFactory(GsonConverterFactory.create())).addCallAdapterFactory(Java8CallAdapterFactory.create()).client(new OkHttpClient.Builder().addInterceptor(chain -> chain.proceed(chain.request().newBuilder().addHeader("app-id", appID).url(chain.request().url().newBuilder().addQueryParameter("access_token", accessToken).build()).build())).dispatcher(dispatcher).build()).build().create(CubedPayAPI.class);
DispatcherMap.dispatcherMap.put(api, dispatcher);
return api;
}
use of okhttp3.Dispatcher in project okhttp by square.
the class InterceptorTest method networkInterceptorReturnsNull.
@Test
public void networkInterceptorReturnsNull() throws Exception {
server.enqueue(new MockResponse());
Interceptor interceptor = chain -> {
chain.proceed(chain.request());
return null;
};
client = client.newBuilder().addNetworkInterceptor(interceptor).build();
ExceptionCatchingExecutor executor = new ExceptionCatchingExecutor();
client = client.newBuilder().dispatcher(new Dispatcher(executor)).build();
Request request = new Request.Builder().url(server.url("/")).build();
try {
client.newCall(request).execute();
fail();
} catch (NullPointerException expected) {
assertThat(expected.getMessage()).isEqualTo(("interceptor " + interceptor + " returned null"));
}
}
use of okhttp3.Dispatcher in project edx-app-android by edx.
the class HttpBaseTestCase method setUp.
@Override
public void setUp() throws Exception {
server = new MockWebServer();
server.setDispatcher(new MockResponseDispatcher());
server.start();
okHttpClient = new OkHttpClient.Builder().dispatcher(new Dispatcher(new RoboExecutorService())).addInterceptor(new JsonMergePatchInterceptor()).addInterceptor(new OnlyIfCachedStrippingInterceptor()).build();
super.setUp();
}
use of okhttp3.Dispatcher in project spring-security by spring-projects.
the class ClientRegistrationsTests method registrationOidcFallback.
/**
* Simulates a situation when the ClientRegistration is used with a legacy application
* where the OIDC Discovery Endpoint is "/issuer1/.well-known/openid-configuration"
* instead of "/.well-known/openid-configuration/issuer1" in which case the first
* attempt results in HTTP 404 and the subsequent call results in 200 OK.
*
* @see <a href="https://tools.ietf.org/html/rfc8414#section-5">Section 5</a> for more
* details.
*/
private ClientRegistration.Builder registrationOidcFallback(String path, String body) throws Exception {
this.issuer = createIssuerFromServer(path);
this.response.put("issuer", this.issuer);
String responseBody = (body != null) ? body : this.mapper.writeValueAsString(this.response);
final Dispatcher dispatcher = new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) {
switch(request.getPath()) {
case "/issuer1/.well-known/openid-configuration":
case "/.well-known/openid-configuration/":
return buildSuccessMockResponse(responseBody);
}
return new MockResponse().setResponseCode(404);
}
};
this.server.setDispatcher(dispatcher);
return ClientRegistrations.fromIssuerLocation(this.issuer).clientId("client-id").clientSecret("client-secret");
}
Aggregations