Search in sources :

Example 66 with Response

use of okhttp3.Response in project zipkin by openzipkin.

the class ZipkinRuleTest method postSpans_sendErrorResponse400.

@Test
public void postSpans_sendErrorResponse400() throws IOException {
    zipkin.enqueueFailure(HttpFailure.sendErrorResponse(400, "Invalid Format"));
    Response response = postSpans(TRACE);
    assertThat(response.code()).isEqualTo(400);
    assertThat(response.body().string()).isEqualTo("Invalid Format");
    // Zipkin didn't store the spans, as they shouldn't have been readable, due to the error
    assertThat(zipkin.getTraces()).isEmpty();
    // The failure shouldn't affect later requests
    assertThat(postSpans(TRACE).code()).isEqualTo(202);
}
Also used : Response(okhttp3.Response) Test(org.junit.Test)

Example 67 with Response

use of okhttp3.Response in project zipkin by openzipkin.

the class HttpSpanStore method getDependencies.

@Override
public List<DependencyLink> getDependencies(long endTs, @Nullable Long lookback) {
    HttpUrl.Builder url = baseUrl.newBuilder("/api/v1/dependencies?endTs=" + endTs);
    if (lookback != null)
        url.addQueryParameter("lookback", lookback.toString());
    Response response = call(new Request.Builder().url(url.build()).build());
    return Codec.JSON.readDependencyLinks(responseBytes(response));
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) QueryRequest(zipkin.storage.QueryRequest) HttpUrl(okhttp3.HttpUrl)

Example 68 with Response

use of okhttp3.Response 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 69 with Response

use of okhttp3.Response in project Pokemap by omkarmoghe.

the class NetworkRequestLoggingInterceptor method intercept.

@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
    final Request request = chain.request();
    // Log request
    Log.d(TAG, MessageFormat.format(REQUEST_SEND_LOG, request.method(), sanitize(request.url()), chain.connection(), request.headers()));
    if (request.method().compareToIgnoreCase("post") == 0)
        Log.d(TAG, MessageFormat.format(REQUEST_BODY_LOG, convertRequestBodyToString(request)));
    final long requestStart = System.currentTimeMillis();
    final Response response = chain.proceed(request);
    final long requestEnd = System.currentTimeMillis();
    final long responseTime = requestEnd - requestStart;
    // Log response
    Log.d(TAG, MessageFormat.format(RESPONSE_RECEIVE_LOG, responseTime, sanitize(response.request().url()), response.headers()));
    final String responseBodyString = response.body().string();
    if (responseBodyString.length() > 0)
        Log.d(TAG, MessageFormat.format(RESPONSE_BODY_LOG, responseBodyString.trim()));
    return response.newBuilder().body(ResponseBody.create(response.body().contentType(), responseBodyString)).build();
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request)

Example 70 with Response

use of okhttp3.Response 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

Test (org.junit.Test)471 Response (okhttp3.Response)444 MockResponse (okhttp3.mockwebserver.MockResponse)380 Request (okhttp3.Request)377 ResponseBody (okhttp3.ResponseBody)351 IOException (java.io.IOException)220 DateTime (org.joda.time.DateTime)194 DateTimeRfc1123 (com.microsoft.rest.DateTimeRfc1123)192 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)178 Response (retrofit2.Response)150 ServiceCall (com.microsoft.rest.ServiceCall)140 ServiceResponse (com.microsoft.rest.ServiceResponse)114 Observable (rx.Observable)104 Call (okhttp3.Call)103 List (java.util.List)95 RequestBody (okhttp3.RequestBody)85 PagedList (com.microsoft.azure.PagedList)80 ServiceResponseWithHeaders (com.microsoft.rest.ServiceResponseWithHeaders)78 OkHttpClient (okhttp3.OkHttpClient)78 HttpURLConnection (java.net.HttpURLConnection)47