protected void executeRequest(OkHttpClient httpClient, Request request) {
        Object fullBody = null;
        Throwable error = null;
        Response response = null;
        try {
            try {
                Log.v(TAG, "%s: BulkDownloader calling httpClient.execute, url: %s", this, url);
                call = httpClient.newCall(request);
                response = call.execute();
                Log.v(TAG, "%s: BulkDownloader called httpClient.execute, url: %s", this, url);

                storeCookie(response);

                // error
                if (response.code() >= 300) {
                    // conflict could be happen. So ERROR prints make developer confused.
                    if (response.code() == 409)
                        Log.w(TAG, "Got error status: %d for %s.  Reason: %s",
                                response.code(), request, response.message());
                    else
                        Log.i(TAG, "Got error status: %d for %s.  Reason: %s",
                                response.code(), request, response.message());
                    error = new RemoteRequestResponseException(response.code(), response.message());
                    RequestUtils.closeResponseBody(response);
                }
                // success
                else {
                    ResponseBody responseBody = response.body();
                    InputStream stream = response.body().byteStream();
                    try {
                        // decompress if contentEncoding is gzip
                        if (Utils.isGzip(response))
                            stream = new GZIPInputStream(stream);
                        MediaType type = responseBody.contentType();
                        if (type != null) {
                            // multipart
                            if (type.type().equals("multipart")) {
                                Log.v(TAG, "mediaType = %s", type);
                                _topReader = new MultipartReader(type.toString(), this);
                                byte[] buffer = new byte[BUF_LEN];
                                int nBytesRead;
                                while ((nBytesRead = stream.read(buffer)) != -1)
                                    _topReader.appendData(buffer, 0, nBytesRead);
                                _topReader.finished();
                            }
                            // JSON (non-multipart)
                            else {
                                Log.v(TAG, "contentTypeHeader is not multipart = %s",
                                        type.toString());
                                fullBody = Manager.getObjectMapper().readValue(
                                        stream, Object.class);
                            }
                        }
                    } finally {
                        try {
                            stream.close();
                        } catch (IOException e) {
                        }
                    }
                }
            } catch (Exception e) {
                // call.execute(), GZIPInputStream, or ObjectMapper.readValue()
                Log.w(TAG, "%s: executeRequest() Exception: %s.  url: %s", this, e, url);
                error = e;
            }
            respondWithResult(fullBody, error, response);
        } finally {
            RequestUtils.closeResponseBody(response);
        }
    }
protected void executeRequest ( OkHttpClient httpClient , Request request ) { Object fullBody = null ; Throwable error = null ; Response response = null ; try { try { Log . v ( TAG , "%s: BulkDownloader calling httpClient.execute, url: %s" , this , url ) ; call = httpClient . newCall ( request ) ; response = call . execute ( ) ; Log . v ( TAG , "%s: BulkDownloader called httpClient.execute, url: %s" , this , url ) ; storeCookie ( response ) ; if ( response . code ( ) >= 300 ) { if ( response . code ( ) == 409 ) Log . w ( TAG , "Got error status: %d for %s.  Reason: %s" , response . code ( ) , request , response . message ( ) ) ; else Log . i ( TAG , "Got error status: %d for %s.  Reason: %s" , response . code ( ) , request , response . message ( ) ) ; error = new RemoteRequestResponseException ( response . code ( ) , response . message ( ) ) ; RequestUtils . closeResponseBody ( response ) ; } else { ResponseBody responseBody = response . body ( ) ; InputStream stream = response . body ( ) . byteStream ( ) ; try { if ( Utils . isGzip ( response ) ) stream = new GZIPInputStream ( stream ) ; MediaType type = responseBody . contentType ( ) ; if ( type != null ) { if ( type . type ( ) . equals ( "multipart" ) ) { Log . v ( TAG , "mediaType = %s" , type ) ; _topReader = new MultipartReader ( type . toString ( ) , this ) ; byte [ ] buffer = new byte [ BUF_LEN ] ; int nBytesRead ; while ( ( nBytesRead = stream . read ( buffer ) ) != - 1 ) _topReader . appendData ( buffer , 0 , nBytesRead ) ; _topReader . finished ( ) ; } else { Log . v ( TAG , "contentTypeHeader is not multipart = %s" , type . toString ( ) ) ; fullBody = Manager . getObjectMapper ( ) . readValue ( stream , Object . class ) ; } } } finally { try { stream . close ( ) ; } catch ( IOException e ) { } } } } catch ( Exception e ) { Log . w ( TAG , "%s: executeRequest() Exception: %s.  url: %s" , this , e , url ) ; error = e ; } respondWithResult ( fullBody , error , response ) ; } finally { RequestUtils . closeResponseBody ( response ) ; } }
Execute request