Search in sources :

Example 91 with Dispatcher

use of okhttp3.Dispatcher in project spring-security by spring-projects.

the class JwtDecodersTests method prepareConfigurationResponses.

private void prepareConfigurationResponses(Map<String, MockResponse> responses) {
    Dispatcher dispatcher = new Dispatcher() {

        @Override
        public MockResponse dispatch(RecordedRequest request) {
            // @formatter:off
            return Optional.of(request).map(RecordedRequest::getRequestUrl).map(HttpUrl::toString).map(responses::get).orElse(new MockResponse().setResponseCode(404));
        // @formatter:on
        }
    };
    this.server.setDispatcher(dispatcher);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Dispatcher(okhttp3.mockwebserver.Dispatcher) HttpUrl(okhttp3.HttpUrl)

Example 92 with Dispatcher

use of okhttp3.Dispatcher in project iterable-android-sdk by Iterable.

the class IterableInboxTest method setUp.

@Before
public void setUp() throws IOException {
    server = new MockWebServer();
    dispatcher = new PathBasedQueueDispatcher();
    server.setDispatcher(dispatcher);
    inAppHandler = mock(IterableInAppHandler.class);
    customActionHandler = mock(IterableCustomActionHandler.class);
    urlHandler = mock(IterableUrlHandler.class);
    IterableApi.overrideURLEndpointPath(server.url("").toString());
    IterableApi.sharedInstance = new IterableApi();
    IterableTestUtils.createIterableApiNew(new IterableTestUtils.ConfigBuilderExtender() {

        @Override
        public IterableConfig.Builder run(IterableConfig.Builder builder) {
            return builder.setInAppHandler(inAppHandler).setCustomActionHandler(customActionHandler).setUrlHandler(urlHandler);
        }
    });
}
Also used : MockWebServer(okhttp3.mockwebserver.MockWebServer) PathBasedQueueDispatcher(com.iterable.iterableapi.unit.PathBasedQueueDispatcher) Before(org.junit.Before)

Example 93 with Dispatcher

use of okhttp3.Dispatcher in project iterable-android-sdk by Iterable.

the class IterableApiAuthTests method setUp.

@Before
public void setUp() {
    server = new MockWebServer();
    dispatcher = new PathBasedQueueDispatcher();
    server.setDispatcher(dispatcher);
    IterableApi.overrideURLEndpointPath(server.url("").toString());
    reInitIterableApi();
    IterableTestUtils.createIterableApiNew(new IterableTestUtils.ConfigBuilderExtender() {

        @Override
        public IterableConfig.Builder run(IterableConfig.Builder builder) {
            return builder.setAuthHandler(authHandler);
        }
    }, null);
}
Also used : MockWebServer(okhttp3.mockwebserver.MockWebServer) PathBasedQueueDispatcher(com.iterable.iterableapi.unit.PathBasedQueueDispatcher) Before(org.junit.Before)

Example 94 with Dispatcher

use of okhttp3.Dispatcher in project amhttp by Eddieyuan123.

the class OnDownloadListener method parseNetworkResponse.

@Override
public void parseNetworkResponse(final Response response, FileCard fileCard) throws Throwable {
    ResponseBody body = response.body();
    if (body == null) {
        throw new NullPointerException("response body is null");
    } else {
        final Dispatcher dispatcher = Dispatcher.getDispatcher(Looper.getMainLooper());
        InputStream is = body.byteStream();
        long contentLength = body.contentLength();
        final File file = FileUtils.saveFile(is, contentLength, fileCard, new OnSaveListener() {

            @Override
            public void OnProgress(final long progress, final long total) {
                dispatcher.dispatchToUIThread(new Runnable() {

                    @Override
                    public void run() {
                        onProgressChanged(progress, total);
                    }
                });
            }
        });
        dispatcher.dispatchToUIThread(new Runnable() {

            @Override
            public void run() {
                onResponseSuccess((T) file);
            }
        });
    }
}
Also used : InputStream(java.io.InputStream) Dispatcher(io.chelizi.amokhttp.Dispatcher) File(java.io.File) ResponseBody(okhttp3.ResponseBody)

Example 95 with Dispatcher

use of okhttp3.Dispatcher in project amhttp by Eddieyuan123.

the class OnFindListener method parseNetworkResponse.

@Override
public void parseNetworkResponse(Response response, FileCard fileCard) throws Throwable {
    ResponseBody responseBody = response.body();
    String responseStr = null;
    if (responseBody != null) {
        responseStr = responseBody.string();
    }
    Type type = ClassUtils.getType(OnFindListener.this.getClass());
    T bean = null;
    if (type != null) {
        if (TextUtils.equals(type.toString(), "class java.lang.String"))
            bean = (T) responseStr;
        else
            bean = new Gson().fromJson(responseStr, type);
    }
    final T finalBean = bean;
    Dispatcher dispatcher = Dispatcher.getDispatcher(Looper.getMainLooper());
    dispatcher.dispatchToUIThread(new Runnable() {

        @Override
        public void run() {
            onResponseSuccess(finalBean);
        }
    });
}
Also used : Type(java.lang.reflect.Type) Gson(com.google.gson.Gson) Dispatcher(io.chelizi.amokhttp.Dispatcher) ResponseBody(okhttp3.ResponseBody)

Aggregations

Dispatcher (okhttp3.Dispatcher)42 OkHttpClient (okhttp3.OkHttpClient)34 MockResponse (okhttp3.mockwebserver.MockResponse)28 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)26 Dispatcher (okhttp3.mockwebserver.Dispatcher)25 IOException (java.io.IOException)19 Before (org.junit.Before)18 MockWebServer (okhttp3.mockwebserver.MockWebServer)16 Test (org.junit.Test)15 Call (okhttp3.Call)11 LruNormalizedCacheFactory (com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory)10 ArrayList (java.util.ArrayList)8 Request (okhttp3.Request)8 Response (okhttp3.Response)8 Interceptor (okhttp3.Interceptor)7 ResponseBody (okhttp3.ResponseBody)7 Gson (com.google.gson.Gson)5 CloudantClient (com.cloudant.client.api.CloudantClient)4 RefineTest (com.google.refine.RefineTest)4 DataExtensionConfig (com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtensionConfig)4