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");
}
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);
}
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);
}
}
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);
}
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;
}
Aggregations