Search in sources :

Example 71 with Response

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;
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) JsonReader(com.squareup.moshi.JsonReader) ResponseBody(okhttp3.ResponseBody)

Example 72 with 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;
}
Also used : BraveExecutorService(com.github.kristofa.brave.BraveExecutorService) OkHttpClient(okhttp3.OkHttpClient) Dispatcher(okhttp3.Dispatcher) Interceptor(okhttp3.Interceptor) BraveTracingInterceptor(com.github.kristofa.brave.okhttp.BraveTracingInterceptor) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 73 with Response

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);
    }
}
Also used : Response(okhttp3.Response) Bitmap(android.graphics.Bitmap) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Request(okhttp3.Request) IOException(java.io.IOException) BitmapDrawable(android.graphics.drawable.BitmapDrawable) IOException(java.io.IOException)

Example 74 with Response

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);
        }
    });
}
Also used : Response(retrofit2.Response) UserFollowerService(com.meisolsson.githubsdk.service.users.UserFollowerService)

Example 75 with Response

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);
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Request(okhttp3.Request)

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