Search in sources :

Example 41 with Headers

use of com.amazonaws.services.s3.Headers in project instructure-android by instructure.

the class APIHelperTest method parseLinkHeaderResponse.

@Test
public void parseLinkHeaderResponse() throws Exception {
    Headers headers = new Headers.Builder().add("link: <https://mobiledev.instructure.com/api/v1/courses/123456/discussion_topics.json?page2>; rel=\"next\"").build();
    LinkHeaders linkHeaders = APIHelper.parseLinkHeaderResponse(headers);
    assertEquals(linkHeaders.nextUrl, "courses/123456/discussion_topics.json?page2");
}
Also used : LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) Headers(okhttp3.Headers) Test(org.junit.Test)

Example 42 with Headers

use of com.amazonaws.services.s3.Headers in project hmftools by hartwigmedical.

the class ChunkHttpBuffer method readUrlBytes.

@NotNull
private ListenableFuture<byte[]> readUrlBytes(final long offset, final long count) {
    final Headers httpHeaders = new Headers.Builder().add("Range", "bytes=" + offset + "-" + (offset + count - 1)).build();
    final Request request = new Request.Builder().url(url).headers(httpHeaders).build();
    final SettableFuture<byte[]> bytesFuture = SettableFuture.create();
    httpClient.newCall(request).enqueue(retryingCallback(10, bytesFuture));
    return bytesFuture;
}
Also used : Headers(okhttp3.Headers) CacheBuilder(com.google.common.cache.CacheBuilder) Request(okhttp3.Request) NotNull(org.jetbrains.annotations.NotNull)

Example 43 with Headers

use of com.amazonaws.services.s3.Headers in project YhLibraryForAndroid by android-coco.

the class LoggerInterceptor method logForRequest.

private void logForRequest(Request request) {
    try {
        String url = request.url().toString();
        Headers headers = request.headers();
        LogUtils.e(tag, "============请求'LogUtils=====开始");
        LogUtils.e(tag, "请求方式 : " + request.method());
        LogUtils.e(tag, "请求URL : " + url);
        if (headers != null && headers.size() > 0) {
            LogUtils.e(tag, "请求头 : " + headers.toString());
        }
        RequestBody requestBody = request.body();
        if (requestBody != null) {
            MediaType mediaType = requestBody.contentType();
            if (mediaType != null) {
                LogUtils.e(tag, "请求参数类型 : " + mediaType);
                LogUtils.e(tag, "请求参数内容 : " + bodyToString(request).replace("&", "   "));
            // if (isText(mediaType))
            // {
            // LogUtils.e(tag, "请求参数内容 : " + bodyToString(request));
            // } else
            // {
            // LogUtils.e(tag, "请求参数内容 : " + " 也许[文件部分],太大了太大了,忽略了!");
            // }
            }
        }
        LogUtils.e(tag, "============请求'LogUtils============结束");
    } catch (Exception e) {
    // e.printStackTrace();
    }
}
Also used : Headers(okhttp3.Headers) MediaType(okhttp3.MediaType) IOException(java.io.IOException) RequestBody(okhttp3.RequestBody)

Example 44 with Headers

use of com.amazonaws.services.s3.Headers in project BaseProject by feer921.

the class HttpLoggingInterceptor method logForRequest.

private void logForRequest(Request request, Connection connection) throws IOException {
    boolean logBody = (printLevel == Level.BODY);
    boolean logHeaders = (printLevel == Level.BODY || printLevel == Level.HEADERS);
    RequestBody requestBody = request.body();
    boolean hasRequestBody = requestBody != null;
    Protocol protocol = connection != null ? connection.protocol() : Protocol.HTTP_1_1;
    try {
        String requestStartMessage = "--> " + request.method() + ' ' + request.url() + ' ' + protocol;
        log(requestStartMessage);
        if (logHeaders) {
            log("\n**headers**");
            Headers headers = request.headers();
            for (int i = 0, count = headers.size(); i < count; i++) {
                log("\t" + headers.name(i) + ": " + headers.value(i));
            }
            log("**end headers**");
            if (logBody && hasRequestBody) {
                if (isPlaintext(requestBody.contentType())) {
                    bodyToString(request);
                } else {
                    log("\tbody: maybe [file part] , too large too print , ignored!");
                }
            }
        }
    } catch (Exception e) {
        OkLogger.e(e);
    } finally {
        log("--> END " + request.method());
    }
}
Also used : HttpHeaders(okhttp3.internal.http.HttpHeaders) Headers(okhttp3.Headers) Protocol(okhttp3.Protocol) IOException(java.io.IOException) RequestBody(okhttp3.RequestBody)

Example 45 with Headers

use of com.amazonaws.services.s3.Headers in project openhab-android by openhab.

the class OpenHABNotificationFragment method loadNotifications.

private void loadNotifications() {
    Connection conn = ConnectionFactory.getConnection(Connection.TYPE_CLOUD);
    if (conn == null) {
        return;
    }
    startProgressIndicator();
    mRequestHandle = conn.getAsyncHttpClient().get("/api/v1/notifications?limit=20", new MyHttpClient.ResponseHandler() {

        @Override
        public void onSuccess(Call call, int statusCode, Headers headers, byte[] responseBody) {
            stopProgressIndicator();
            Log.d(TAG, "Notifications request success");
            try {
                String jsonString = new String(responseBody, "UTF-8");
                JSONArray jsonArray = new JSONArray(jsonString);
                Log.d(TAG, jsonArray.toString());
                mNotifications.clear();
                for (int i = 0; i < jsonArray.length(); i++) {
                    try {
                        JSONObject sitemapJson = jsonArray.getJSONObject(i);
                        mNotifications.add(OpenHABNotification.fromJson(sitemapJson));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                mNotificationAdapter.notifyDataSetChanged();
            } catch (UnsupportedEncodingException | JSONException e) {
                Log.d(TAG, e.getMessage(), e);
            }
        }

        @Override
        public void onFailure(Call call, int statusCode, Headers headers, byte[] responseBody, Throwable error) {
            stopProgressIndicator();
            Log.e(TAG, "Notifications request failure");
        }
    });
}
Also used : Call(okhttp3.Call) JSONObject(org.json.JSONObject) Headers(okhttp3.Headers) Connection(org.openhab.habdroid.core.connection.Connection) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

Headers (okhttp3.Headers)128 Request (okhttp3.Request)61 Response (okhttp3.Response)54 Test (org.junit.Test)40 IOException (java.io.IOException)32 Call (okhttp3.Call)30 RequestBody (okhttp3.RequestBody)25 CancelledException (com.hippo.ehviewer.client.exception.CancelledException)20 EhException (com.hippo.ehviewer.client.exception.EhException)20 NoHAtHClientException (com.hippo.ehviewer.client.exception.NoHAtHClientException)20 ParseException (com.hippo.ehviewer.client.exception.ParseException)20 StatusCodeException (com.hippo.network.StatusCodeException)20 ResponseBody (okhttp3.ResponseBody)18 HttpHeaders (okhttp3.internal.http.HttpHeaders)18 MediaType (okhttp3.MediaType)15 ServiceResponseWithHeaders (com.microsoft.rest.ServiceResponseWithHeaders)14 HeaderResponseBoolHeaders (fixtures.header.models.HeaderResponseBoolHeaders)14 HeaderResponseByteHeaders (fixtures.header.models.HeaderResponseByteHeaders)14 HeaderResponseDateHeaders (fixtures.header.models.HeaderResponseDateHeaders)14 HeaderResponseDatetimeHeaders (fixtures.header.models.HeaderResponseDatetimeHeaders)14