use of okhttp3.Response in project zipkin by openzipkin.
the class AWSSignatureVersion4 method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
Request input = chain.request();
Request signed = sign(input);
Response response = chain.proceed(signed);
if (response.code() == 403) {
try (ResponseBody body = response.body()) {
JsonReader message = enterPath(JsonReader.of(body.source()), "message");
if (message != null)
throw new IllegalStateException(message.nextString());
}
throw new IllegalStateException(response.toString());
}
return response;
}
use of okhttp3.Response in project zipkin by openzipkin.
the class TraceZipkinElasticsearchHttpStorageAutoConfiguration method elasticsearchOkHttpClientBuilder.
@Bean
@Qualifier("zipkinElasticsearchHttp")
@ConditionalOnMissingBean
OkHttpClient.Builder elasticsearchOkHttpClientBuilder() {
// have to indirect to unwind a circular dependency
Interceptor tracingInterceptor = new Interceptor() {
Interceptor delegate = BraveTracingInterceptor.builder(brave).serverName("elasticsearch").build();
@Override
public Response intercept(Chain chain) throws IOException {
// Only join traces, don't start them. This prevents LocalCollector's thread from amplifying.
if (brave.serverSpanThreadBinder().getCurrentServerSpan() != null && brave.serverSpanThreadBinder().getCurrentServerSpan().getSpan() != null) {
return delegate.intercept(chain);
}
return chain.proceed(chain.request());
}
};
BraveExecutorService tracePropagatingExecutor = BraveExecutorService.wrap(new Dispatcher().executorService(), brave);
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.addInterceptor(tracingInterceptor);
builder.addNetworkInterceptor(tracingInterceptor);
builder.dispatcher(new Dispatcher(tracePropagatingExecutor));
return builder;
}
use of okhttp3.Response in project PocketHub by pockethub.
the class HttpImageGetter method getDrawable.
@Override
public Drawable getDrawable(final String source) {
try {
Drawable repositoryImage = requestRepositoryImage(source);
if (repositoryImage != null) {
return repositoryImage;
}
} catch (Exception e) {
// Ignore and attempt request over regular HTTP request
}
try {
String logMessage = "Loading image: " + source;
Log.d(getClass().getSimpleName(), logMessage);
Bugsnag.leaveBreadcrumb(logMessage);
Request request = new Request.Builder().get().url(source).build();
Response response = okHttpClient.newCall(request).execute();
if (!response.isSuccessful()) {
throw new IOException("Unexpected response code: " + response.code());
}
Bitmap bitmap = BitmapFactory.decodeStream(response.body().byteStream());
if (bitmap == null) {
return loading.getDrawable(source);
}
BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap);
drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
return drawable;
} catch (IOException e) {
Log.e(getClass().getSimpleName(), "Error loading image", e);
Bugsnag.notify(e);
return loading.getDrawable(source);
}
}
use of okhttp3.Response in project PocketHub by pockethub.
the class UserViewActivity method followUser.
private void followUser() {
UserFollowerService service = ServiceGenerator.createService(this, UserFollowerService.class);
Single<Response<Boolean>> followSingle;
if (isFollowing) {
followSingle = service.unfollowUser(user.login());
} else {
followSingle = service.followUser(user.login());
}
followSingle.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(this.<Response<Boolean>>bindToLifecycle()).subscribe(new ObserverAdapter<Response<Boolean>>() {
@Override
public void onSuccess(Response<Boolean> aBoolean) {
isFollowing = !isFollowing;
}
@Override
public void onError(Throwable e) {
ToastUtils.show(UserViewActivity.this, isFollowing ? R.string.error_unfollowing_person : R.string.error_following_person);
}
});
}
use of okhttp3.Response in project realm-java by realm.
the class OkHttpAuthenticationServer method logout.
private LogoutResponse logout(URL logoutUrl, String requestBody) throws Exception {
Request request = new Request.Builder().url(logoutUrl).addHeader("Content-Type", "application/json").addHeader("Accept", "application/json").post(RequestBody.create(JSON, requestBody)).build();
Call call = client.newCall(request);
Response response = call.execute();
return LogoutResponse.from(response);
}
Aggregations