public static BeanstreamResponse fromHttpResponse(HttpResponse http) {

        int httpStatusCode = http.getStatusLine().getStatusCode();
        HttpEntity httpEntity = http.getEntity();
        String jsonPayload = null;

        try {
            jsonPayload = httpEntity != null ? EntityUtils.toString(httpEntity) : null;
        } catch (IOException e) {
            return new BeanstreamResponseBuilder()
                    .withHttpStatusCode(httpStatusCode)
                    .withMessage(e.getMessage())
                    .setMediaType(MediaType.ANY_TYPE)
                    .build();
        }
        
        String contentType = httpEntity.getContentType() != null ? httpEntity.getContentType().getValue() : null;
        MediaType responseType = contentType != null ? MediaType.parse(contentType) : null;

        // If the payload isn't json, or we got a 2XX response, just populate the responseBody field with the payload
        if (responseType == null || responseType != MediaType.JSON_UTF_8 || (httpStatusCode >= 200 && httpStatusCode < 300)) {
            return new BeanstreamResponseBuilder()
                    .withHttpStatusCode(httpStatusCode)
                    .withResponseBody(jsonPayload)
                    .setMediaType(responseType)
                    .build();
        }

        // else get the usual code/cat/msg/ref response
        return fromJson(httpStatusCode, jsonPayload, responseType);
    }