answer.setBody(extractResponseBody(exchange, httpExchange));
}
protected Exception populateHttpOperationFailedException(Exchange exchange, JettyContentExchange httpExchange,
int responseCode) throws IOException {
HttpOperationFailedException answer;
String uri = httpExchange.getUrl();
Map<String, String> headers = httpExchange.getHeaders();
Object responseBody = extractResponseBody(exchange, httpExchange);
if (transferException && responseBody != null && responseBody instanceof Exception) {
// if the response was a serialized exception then use that
return (Exception) responseBody;
}
// make a defensive copy of the response body in the exception so its detached from the cache
String copy = null;
if (responseBody != null) {
copy = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, responseBody);
}
if (responseCode >= 300 && responseCode < 400) {
String locationHeader = httpExchange.getResponseFields().getStringField("location");
if (locationHeader != null) {
answer = new HttpOperationFailedException(uri, responseCode, null, locationHeader, headers, copy);
} else {
// no redirect location
answer = new HttpOperationFailedException(uri, responseCode, null, null, headers, copy);
}
} else {
// internal server error (error code 500)
answer = new HttpOperationFailedException(uri, responseCode, null, null, headers, copy);
}
return answer;
}