Search in sources :

Example 41 with HttpUrl

use of okhttp3.HttpUrl in project sonarqube by SonarSource.

the class WebhookCallerImplTest method redirects_throws_ISE_if_header_Location_does_not_relate_to_a_supported_protocol.

@Test
public void redirects_throws_ISE_if_header_Location_does_not_relate_to_a_supported_protocol() throws Exception {
    HttpUrl url = server.url("/redirect");
    Webhook webhook = new Webhook(PROJECT_UUID, CE_TASK_UUID, "my-webhook", url.toString());
    server.enqueue(new MockResponse().setResponseCode(307).setHeader("Location", "ftp://foo"));
    WebhookDelivery delivery = newSender().call(webhook, PAYLOAD);
    Throwable error = delivery.getError().get();
    assertThat(error).isInstanceOf(IllegalStateException.class).hasMessage("Unsupported protocol in redirect of " + url + " to ftp://foo");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Example 42 with HttpUrl

use of okhttp3.HttpUrl in project kickmaterial by byoutline.

the class KickMaterialRequestInterceptor method intercept.

@Override
public Response intercept(Chain chain) throws IOException {
    Request original = chain.request();
    HttpUrl.Builder urlBuilder = original.url().newBuilder();
    addBasicHeaders(urlBuilder);
    String accessToken = accessTokenProvider.get();
    if (!TextUtils.isEmpty(accessToken)) {
        urlBuilder.addQueryParameter("oauth_token", accessToken);
    }
    HttpUrl newUrl = urlBuilder.build();
    Request newRequest = original.newBuilder().url(newUrl).build();
    return chain.proceed(newRequest);
}
Also used : Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl)

Example 43 with HttpUrl

use of okhttp3.HttpUrl 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 44 with HttpUrl

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

Example 45 with HttpUrl

use of okhttp3.HttpUrl in project ride-read-android by Ride-Read.

the class RetrofitUtils method addQueryParameterInterceptor.

/**
     * 设置公共参数
     */
private static Interceptor addQueryParameterInterceptor() {
    Interceptor addQueryParameterInterceptor = new Interceptor() {

        @Override
        public Response intercept(Chain chain) throws IOException {
            Request originalRequest = chain.request();
            Request request;
            HttpUrl modifiedUrl = originalRequest.url().newBuilder().addQueryParameter("", Integer.toString(UserUtils.getUid())).addQueryParameter("token", UserUtils.getToken()).build();
            ;
            if (0 != UserUtils.getUid()) {
                modifiedUrl = originalRequest.url().newBuilder().addQueryParameter("uid", Integer.toString(UserUtils.getUid())).addQueryParameter("token", UserUtils.getToken()).build();
            }
            request = originalRequest.newBuilder().url(modifiedUrl).build();
            return chain.proceed(request);
        }
    };
    return addQueryParameterInterceptor;
}
Also used : Request(okhttp3.Request) Interceptor(okhttp3.Interceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) HttpUrl(okhttp3.HttpUrl)

Aggregations

HttpUrl (okhttp3.HttpUrl)72 Test (org.junit.Test)55 MockResponse (okhttp3.mockwebserver.MockResponse)53 Request (okhttp3.Request)28 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)25 IOException (java.io.IOException)20 Response (okhttp3.Response)17 MockWebServer (okhttp3.mockwebserver.MockWebServer)17 RequestBody (okhttp3.RequestBody)12 Moshi (com.squareup.moshi.Moshi)6 CookieManager (java.net.CookieManager)6 Call (retrofit2.Call)6 Callback (retrofit2.Callback)6 Response (retrofit2.Response)6 LoginFailedException (com.pokegoapi.exceptions.request.LoginFailedException)5 HttpCookie (java.net.HttpCookie)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 QueryRequest (zipkin.storage.QueryRequest)5 HashMap (java.util.HashMap)4