use of org.springframework.web.client.HttpMessageConverterExtractor in project component-runtime by Talend.
the class SpringRestClient method toException.
private WebException toException(final HttpServerErrorException hsee) {
try {
return new WebException(hsee, hsee.getRawStatusCode(), new HttpMessageConverterExtractor<Map<String, Object>>(mapType.getType(), delegate.getMessageConverters()).extractData(new ClientHttpResponse() {
@Override
public HttpStatus getStatusCode() {
return HttpStatus.OK;
}
@Override
public int getRawStatusCode() {
return 200;
}
@Override
public String getStatusText() {
return "";
}
@Override
public void close() {
// no-op
}
@Override
public InputStream getBody() {
return new ByteArrayInputStream(hsee.getResponseBodyAsByteArray());
}
@Override
public HttpHeaders getHeaders() {
final HttpHeaders json = json();
json.add(HttpHeaders.CONTENT_TYPE, "application/json");
return json;
}
}));
} catch (final IOException e) {
throw new IllegalStateException(e);
}
}
use of org.springframework.web.client.HttpMessageConverterExtractor in project commons by craftercms.
the class HttpMessageConvertingResponseErrorHandler method handleError.
@Override
public void handleError(ClientHttpResponse response) throws IOException {
HttpStatus status = response.getStatusCode();
HttpMessageConverterExtractor<?> responseExtractor = new HttpMessageConverterExtractor<>(responseType, messageConverters);
Object errorDetails;
try {
errorDetails = responseExtractor.extractData(response);
} catch (RestClientException e) {
// the response body as string
throw new RestServiceException(status, getResponseBodyAsString(response));
}
throw new RestServiceException(status, errorDetails);
}
Aggregations