Search in sources :

Example 6 with Response

use of com.ecwid.consul.v1.Response in project okhttputils by hongyangAndroid.

the class LoggerInterceptor method logForResponse.

private Response logForResponse(Response response) {
    try {
        //===>response log
        Log.e(tag, "========response'log=======");
        Response.Builder builder = response.newBuilder();
        Response clone = builder.build();
        Log.e(tag, "url : " + clone.request().url());
        Log.e(tag, "code : " + clone.code());
        Log.e(tag, "protocol : " + clone.protocol());
        if (!TextUtils.isEmpty(clone.message()))
            Log.e(tag, "message : " + clone.message());
        if (showResponse) {
            ResponseBody body = clone.body();
            if (body != null) {
                MediaType mediaType = body.contentType();
                if (mediaType != null) {
                    Log.e(tag, "responseBody's contentType : " + mediaType.toString());
                    if (isText(mediaType)) {
                        String resp = body.string();
                        Log.e(tag, "responseBody's content : " + resp);
                        body = ResponseBody.create(mediaType, resp);
                        return response.newBuilder().body(body).build();
                    } else {
                        Log.e(tag, "responseBody's content : " + " maybe [file part] , too large too print , ignored!");
                    }
                }
            }
        }
        Log.e(tag, "========response'log=======end");
    } catch (Exception e) {
    //            e.printStackTrace();
    }
    return response;
}
Also used : Response(okhttp3.Response) MediaType(okhttp3.MediaType) IOException(java.io.IOException) ResponseBody(okhttp3.ResponseBody)

Example 7 with Response

use of com.ecwid.consul.v1.Response in project okhttputils by hongyangAndroid.

the class LoggerInterceptor method intercept.

@Override
public Response intercept(Chain chain) throws IOException {
    Request request = chain.request();
    logForRequest(request);
    Response response = chain.proceed(request);
    return logForResponse(response);
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request)

Example 8 with Response

use of com.ecwid.consul.v1.Response in project feign by OpenFeign.

the class OkHttpClient method execute.

@Override
public feign.Response execute(feign.Request input, feign.Request.Options options) throws IOException {
    okhttp3.OkHttpClient requestScoped;
    if (delegate.connectTimeoutMillis() != options.connectTimeoutMillis() || delegate.readTimeoutMillis() != options.readTimeoutMillis()) {
        requestScoped = delegate.newBuilder().connectTimeout(options.connectTimeoutMillis(), TimeUnit.MILLISECONDS).readTimeout(options.readTimeoutMillis(), TimeUnit.MILLISECONDS).build();
    } else {
        requestScoped = delegate;
    }
    Request request = toOkHttpRequest(input);
    Response response = requestScoped.newCall(request).execute();
    return toFeignResponse(response).toBuilder().request(input).build();
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request)

Example 9 with Response

use of com.ecwid.consul.v1.Response in project Signal-Android by WhisperSystems.

the class GiphyLoader method loadPage.

@NonNull
public List<GiphyImage> loadPage(int offset) {
    try {
        String url;
        if (TextUtils.isEmpty(searchString))
            url = String.format(getTrendingUrl(), offset);
        else
            url = String.format(getSearchUrl(), offset, Uri.encode(searchString));
        Request request = new Request.Builder().url(url).build();
        Response response = client.newCall(request).execute();
        if (!response.isSuccessful()) {
            throw new IOException("Unexpected code " + response);
        }
        GiphyResponse giphyResponse = JsonUtils.fromJson(response.body().byteStream(), GiphyResponse.class);
        List<GiphyImage> results = giphyResponse.getData();
        if (results == null)
            return new LinkedList<>();
        else
            return results;
    } catch (IOException e) {
        Log.w(TAG, e);
        return new LinkedList<>();
    }
}
Also used : GiphyResponse(org.thoughtcrime.securesms.giph.model.GiphyResponse) Response(okhttp3.Response) GiphyResponse(org.thoughtcrime.securesms.giph.model.GiphyResponse) GiphyImage(org.thoughtcrime.securesms.giph.model.GiphyImage) Request(okhttp3.Request) IOException(java.io.IOException) NonNull(android.support.annotation.NonNull)

Example 10 with Response

use of com.ecwid.consul.v1.Response in project Signal-Android by WhisperSystems.

the class OkHttpStreamFetcher method loadData.

@Override
public InputStream loadData(Priority priority) throws Exception {
    Request.Builder requestBuilder = new Request.Builder().url(url.toStringUrl());
    for (Map.Entry<String, String> headerEntry : url.getHeaders().entrySet()) {
        String key = headerEntry.getKey();
        requestBuilder.addHeader(key, headerEntry.getValue());
    }
    Request request = requestBuilder.build();
    Response response = client.newCall(request).execute();
    responseBody = response.body();
    if (!response.isSuccessful()) {
        throw new IOException("Request failed with code: " + response.code());
    }
    long contentLength = responseBody.contentLength();
    stream = ContentLengthInputStream.obtain(responseBody.byteStream(), contentLength);
    return stream;
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) IOException(java.io.IOException) Map(java.util.Map)

Aggregations

Response (okhttp3.Response)1475 Request (okhttp3.Request)1045 IOException (java.io.IOException)547 Test (org.junit.Test)438 Response (retrofit2.Response)338 Call (okhttp3.Call)293 OkHttpClient (okhttp3.OkHttpClient)287 ResponseBody (okhttp3.ResponseBody)245 ServiceResponse (com.microsoft.rest.ServiceResponse)179 RequestBody (okhttp3.RequestBody)153 MockResponse (okhttp3.mockwebserver.MockResponse)148 Callback (okhttp3.Callback)129 List (java.util.List)118 Observable (rx.Observable)114 JSONObject (org.json.JSONObject)93 ArrayList (java.util.ArrayList)90 HttpUrl (okhttp3.HttpUrl)87 ANResponse (com.androidnetworking.common.ANResponse)84 InputStream (java.io.InputStream)81 Map (java.util.Map)81