Search in sources :

Example 36 with Callback

use of okhttp3.Callback in project zipkin by openzipkin.

the class HttpCallTest method propagatesOnDispatcherThreadWhenFatal.

@Test
public void propagatesOnDispatcherThreadWhenFatal() throws Exception {
    mws.enqueue(new MockResponse());
    http.newCall(request, b -> {
        throw new LinkageError();
    }).submit(callback);
    SimpleTimeLimiter timeLimiter = new SimpleTimeLimiter();
    try {
        timeLimiter.callWithTimeout(callback::get, 100, TimeUnit.MILLISECONDS, true);
        failBecauseExceptionWasNotThrown(UncheckedTimeoutException.class);
    } catch (UncheckedTimeoutException expected) {
    }
}
Also used : Request(okhttp3.Request) SimpleTimeLimiter(com.google.common.util.concurrent.SimpleTimeLimiter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) OkHttpClient(okhttp3.OkHttpClient) Rule(org.junit.Rule) After(org.junit.After) MockWebServer(okhttp3.mockwebserver.MockWebServer) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException) MockResponse(okhttp3.mockwebserver.MockResponse) CallbackCaptor(zipkin.internal.CallbackCaptor) Assertions.failBecauseExceptionWasNotThrown(org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown) MockResponse(okhttp3.mockwebserver.MockResponse) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException) SimpleTimeLimiter(com.google.common.util.concurrent.SimpleTimeLimiter) Test(org.junit.Test)

Example 37 with Callback

use of okhttp3.Callback in project zipkin by openzipkin.

the class HttpCallTest method executionException_conversionException.

@Test
public void executionException_conversionException() throws Exception {
    mws.enqueue(new MockResponse());
    http.newCall(request, b -> {
        throw new IllegalArgumentException("eeek");
    }).submit(callback);
    try {
        callback.get();
        failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
    } catch (IllegalArgumentException expected) {
        assertThat(expected).isInstanceOf(IllegalArgumentException.class);
    }
}
Also used : Request(okhttp3.Request) SimpleTimeLimiter(com.google.common.util.concurrent.SimpleTimeLimiter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) OkHttpClient(okhttp3.OkHttpClient) Rule(org.junit.Rule) After(org.junit.After) MockWebServer(okhttp3.mockwebserver.MockWebServer) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException) MockResponse(okhttp3.mockwebserver.MockResponse) CallbackCaptor(zipkin.internal.CallbackCaptor) Assertions.failBecauseExceptionWasNotThrown(org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 38 with Callback

use of okhttp3.Callback in project zipkin by openzipkin.

the class HttpBulkSpanIndexerTest method doesntWriteSpanId.

@Test
public void doesntWriteSpanId() throws Exception {
    es.enqueue(new MockResponse());
    indexer.add("test_zipkin_http-2016-10-01", TestObjects.LOTS_OF_SPANS[0], (Long) null);
    indexer.execute(callback);
    callback.get();
    RecordedRequest request = es.takeRequest();
    assertThat(request.getBody().readByteString().utf8()).doesNotContain("\"_id\"");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 39 with Callback

use of okhttp3.Callback in project Pokemap by omkarmoghe.

the class GoogleManager method refreshToken.

public void refreshToken(String refreshToken, final RefreshListener listener) {
    HttpUrl url = HttpUrl.parse(OAUTH_TOKEN_ENDPOINT).newBuilder().addQueryParameter("client_id", CLIENT_ID).addQueryParameter("client_secret", SECRET).addQueryParameter("refresh_token", refreshToken).addQueryParameter("grant_type", "refresh_token").build();
    Callback<GoogleService.TokenResponse> googleCallback = new Callback<GoogleService.TokenResponse>() {

        @Override
        public void onResponse(Call<GoogleService.TokenResponse> call, Response<GoogleService.TokenResponse> response) {
            if (response != null && response.body() != null) {
                listener.refreshSuccessful(response.body().getIdToken(), response.body().getRefreshToken());
            } else {
                listener.refreshFailed("Failed on requesting the id token");
            }
        }

        @Override
        public void onFailure(Call<GoogleService.TokenResponse> call, Throwable t) {
            t.printStackTrace();
            listener.refreshFailed("Failed on requesting the id token");
        }
    };
    if (mGoogleService != null) {
        Call<GoogleService.TokenResponse> call = mGoogleService.requestToken(url.toString());
        call.enqueue(googleCallback);
    }
}
Also used : Response(retrofit2.Response) Call(retrofit2.Call) Callback(retrofit2.Callback) HttpUrl(okhttp3.HttpUrl)

Example 40 with Callback

use of okhttp3.Callback in project Pokemap by omkarmoghe.

the class NianticManager method loginPTC.

private void loginPTC(final String username, final String password, NianticService.LoginValues values, final LoginListener loginListener) {
    HttpUrl url = HttpUrl.parse(LOGIN_URL).newBuilder().addQueryParameter("lt", values.getLt()).addQueryParameter("execution", values.getExecution()).addQueryParameter("_eventId", "submit").addQueryParameter("username", username).addQueryParameter("password", password).build();
    OkHttpClient client = mClient.newBuilder().followRedirects(false).followSslRedirects(false).build();
    NianticService service = new Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).client(client).build().create(NianticService.class);
    Callback<NianticService.LoginResponse> loginCallback = new Callback<NianticService.LoginResponse>() {

        @Override
        public void onResponse(Call<NianticService.LoginResponse> call, Response<NianticService.LoginResponse> response) {
            String location = response.headers().get("location");
            if (location != null && location.split("ticket=").length > 0) {
                String ticket = location.split("ticket=")[1];
                requestToken(ticket, loginListener);
            } else {
                Log.e(TAG, "PTC login failed via loginPTC(). There was no location header in response.");
                loginListener.authFailed("Pokemon Trainer Club Login Failed");
            }
        }

        @Override
        public void onFailure(Call<NianticService.LoginResponse> call, Throwable t) {
            t.printStackTrace();
            Log.e(TAG, "PTC login failed via loginPTC(). loginCallback.onFailure() threw: " + t.getMessage());
            loginListener.authFailed("Pokemon Trainer Club Login Failed");
        }
    };
    Call<NianticService.LoginResponse> call = service.login(url.toString());
    call.enqueue(loginCallback);
}
Also used : Call(retrofit2.Call) OkHttpClient(okhttp3.OkHttpClient) HttpUrl(okhttp3.HttpUrl) Response(retrofit2.Response) Retrofit(retrofit2.Retrofit) Callback(retrofit2.Callback)

Aggregations

ResponseBody (okhttp3.ResponseBody)180 DateTimeRfc1123 (com.microsoft.rest.DateTimeRfc1123)166 DateTime (org.joda.time.DateTime)166 ServiceCall (com.microsoft.rest.ServiceCall)140 IOException (java.io.IOException)74 Test (org.junit.Test)60 MockResponse (okhttp3.mockwebserver.MockResponse)58 List (java.util.List)54 Request (okhttp3.Request)54 PagedList (com.microsoft.azure.PagedList)52 ServiceResponseWithHeaders (com.microsoft.rest.ServiceResponseWithHeaders)52 Call (okhttp3.Call)52 Response (okhttp3.Response)51 Callback (okhttp3.Callback)44 RequestBody (okhttp3.RequestBody)29 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)27 OkHttpClient (okhttp3.OkHttpClient)20 CountDownLatch (java.util.concurrent.CountDownLatch)16 Call (retrofit2.Call)16 Callback (retrofit2.Callback)15