Search in sources :

Example 16 with Headers

use of com.amazonaws.services.s3.Headers in project okhttp by square.

the class JavaApiConverter method createJavaCacheResponse.

/**
   * Creates a {@link java.net.CacheResponse} of the correct (sub)type using information gathered
   * from the supplied {@link Response}.
   */
public static CacheResponse createJavaCacheResponse(final Response response) {
    final Headers headers = withSyntheticHeaders(response);
    final ResponseBody body = response.body();
    if (response.request().isHttps()) {
        final Handshake handshake = response.handshake();
        return new SecureCacheResponse() {

            @Override
            public String getCipherSuite() {
                return handshake != null ? handshake.cipherSuite().javaName() : null;
            }

            @Override
            public List<Certificate> getLocalCertificateChain() {
                if (handshake == null)
                    return null;
                // Java requires null, not an empty list here.
                List<Certificate> certificates = handshake.localCertificates();
                return certificates.size() > 0 ? certificates : null;
            }

            @Override
            public List<Certificate> getServerCertificateChain() throws SSLPeerUnverifiedException {
                if (handshake == null)
                    return null;
                // Java requires null, not an empty list here.
                List<Certificate> certificates = handshake.peerCertificates();
                return certificates.size() > 0 ? certificates : null;
            }

            @Override
            public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
                if (handshake == null)
                    return null;
                return handshake.peerPrincipal();
            }

            @Override
            public Principal getLocalPrincipal() {
                if (handshake == null)
                    return null;
                return handshake.localPrincipal();
            }

            @Override
            public Map<String, List<String>> getHeaders() throws IOException {
                // Java requires that the entry with a null key be the status line.
                return JavaNetHeaders.toMultimap(headers, StatusLine.get(response).toString());
            }

            @Override
            public InputStream getBody() throws IOException {
                if (body == null)
                    return null;
                return body.byteStream();
            }
        };
    } else {
        return new CacheResponse() {

            @Override
            public Map<String, List<String>> getHeaders() throws IOException {
                // Java requires that the entry with a null key be the status line.
                return JavaNetHeaders.toMultimap(headers, StatusLine.get(response).toString());
            }

            @Override
            public InputStream getBody() throws IOException {
                if (body == null)
                    return null;
                return body.byteStream();
            }
        };
    }
}
Also used : CacheResponse(java.net.CacheResponse) SecureCacheResponse(java.net.SecureCacheResponse) SecureCacheResponse(java.net.SecureCacheResponse) HttpHeaders(okhttp3.internal.http.HttpHeaders) Headers(okhttp3.Headers) JavaNetHeaders(okhttp3.internal.JavaNetHeaders) List(java.util.List) ResponseBody(okhttp3.ResponseBody) Handshake(okhttp3.Handshake) Certificate(java.security.cert.Certificate)

Example 17 with Headers

use of com.amazonaws.services.s3.Headers in project okhttp by square.

the class MockWebServerTest method headersToList.

private List<String> headersToList(MockResponse response) {
    Headers headers = response.getHeaders();
    int size = headers.size();
    List<String> headerList = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        headerList.add(headers.name(i) + ": " + headers.value(i));
    }
    return headerList;
}
Also used : Headers(okhttp3.Headers) ArrayList(java.util.ArrayList)

Example 18 with Headers

use of com.amazonaws.services.s3.Headers in project retrofit by square.

the class ResponseTest method successWithHeaders.

@Test
public void successWithHeaders() {
    Object body = new Object();
    Headers headers = Headers.of("foo", "bar");
    Response<Object> response = Response.success(body, headers);
    assertThat(response.raw()).isNotNull();
    assertThat(response.code()).isEqualTo(200);
    assertThat(response.message()).isEqualTo("OK");
    assertThat(response.headers().toMultimap()).isEqualTo(headers.toMultimap());
    assertThat(response.isSuccessful()).isTrue();
    assertThat(response.body()).isSameAs(body);
    assertThat(response.errorBody()).isNull();
}
Also used : Headers(okhttp3.Headers) Test(org.junit.Test)

Example 19 with Headers

use of com.amazonaws.services.s3.Headers in project realm-java by realm.

the class HttpUtils method stopSyncServer.

public static void stopSyncServer() throws Exception {
    Request request = new Request.Builder().url(STOP_SERVER).build();
    Response response = client.newCall(request).execute();
    if (!response.isSuccessful())
        throw new IOException("Unexpected code " + response);
    Headers responseHeaders = response.headers();
    for (int i = 0; i < responseHeaders.size(); i++) {
        RealmLog.debug(responseHeaders.name(i) + ": " + responseHeaders.value(i));
    }
    RealmLog.debug(response.body().string());
}
Also used : Response(okhttp3.Response) Headers(okhttp3.Headers) Request(okhttp3.Request) IOException(java.io.IOException)

Example 20 with Headers

use of com.amazonaws.services.s3.Headers in project realm-java by realm.

the class HttpUtils method startSyncServer.

public static void startSyncServer() throws Exception {
    Request request = new Request.Builder().url(START_SERVER).build();
    Response response = client.newCall(request).execute();
    if (!response.isSuccessful())
        throw new IOException("Unexpected code " + response);
    Headers responseHeaders = response.headers();
    for (int i = 0; i < responseHeaders.size(); i++) {
        RealmLog.debug(responseHeaders.name(i) + ": " + responseHeaders.value(i));
    }
    RealmLog.debug(response.body().string());
    // FIXME: Server ready checking should be done in the control server side!
    if (!waitAuthServerReady()) {
        stopSyncServer();
        throw new RuntimeException("Auth server cannot be started.");
    }
}
Also used : Response(okhttp3.Response) Headers(okhttp3.Headers) Request(okhttp3.Request) IOException(java.io.IOException)

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