Search in sources :

Example 1 with DefaultResponse

use of com.okta.sdk.impl.http.support.DefaultResponse in project okta-sdk-java by okta.

the class HttpClientRequestExecutor method toSdkResponse.

protected Response toSdkResponse(HttpResponse httpResponse) throws IOException {
    int httpStatus = httpResponse.getStatusLine().getStatusCode();
    HttpHeaders headers = getHeaders(httpResponse);
    MediaType mediaType = headers.getContentType();
    HttpEntity entity = getHttpEntity(httpResponse);
    InputStream body = entity != null ? entity.getContent() : null;
    long contentLength = entity != null ? entity.getContentLength() : -1;
    // ensure that the content has been fully acquired before closing the http stream
    if (body != null) {
        byte[] bytes = toBytes(entity);
        if (bytes != null) {
            body = new ByteArrayInputStream(bytes);
        } else {
            body = null;
        }
    }
    Response response = new DefaultResponse(httpStatus, mediaType, body, contentLength);
    response.getHeaders().add(HttpHeaders.OKTA_REQUEST_ID, headers.getOktaRequestId());
    response.getHeaders().put(HttpHeaders.LINK, headers.getLinkHeaders());
    return response;
}
Also used : DefaultResponse(com.okta.sdk.impl.http.support.DefaultResponse) Response(com.okta.sdk.impl.http.Response) HttpResponse(org.apache.http.HttpResponse) DefaultResponse(com.okta.sdk.impl.http.support.DefaultResponse) HttpHeaders(com.okta.sdk.impl.http.HttpHeaders) HttpEntity(org.apache.http.HttpEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MediaType(com.okta.sdk.impl.http.MediaType)

Aggregations

HttpHeaders (com.okta.sdk.impl.http.HttpHeaders)1 MediaType (com.okta.sdk.impl.http.MediaType)1 Response (com.okta.sdk.impl.http.Response)1 DefaultResponse (com.okta.sdk.impl.http.support.DefaultResponse)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 HttpEntity (org.apache.http.HttpEntity)1 HttpResponse (org.apache.http.HttpResponse)1