use of com.okta.sdk.impl.http.MediaType 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;
}
Aggregations