Announcement Announcement Module
No announcement yet.
Get body from ClientHttpResponse twice Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get body from ClientHttpResponse twice


    I need to check a response for a business error:

    restTemplate.setErrorHandler(new BusinessResponseErrorHandler());

    public class BusinessResponseErrorHandler implements ResponseErrorHandler {

    public boolean hasError(ClientHttpResponse clientHttpResponse) throws IOException {
    // need to check for error
    String body = IOUtils.toString(clientHttpResponse.getBody());
    return false;

    public void handleError(ClientHttpResponse clientHttpResponse) throws IOException {



    but I have an error:

    org.springframework.http.converter.HttpMessageNotR eadableException: Could not read JSON: No content to map to Object due to end of input; nested exception is No content to map to Object due to end of input

    Why Robospice reads the body of a ClientHttpResponse again ? I found that it called

    at org.springframework.web.client.HttpMessageConverte rExtractor.extractData(HttpMessageConverterExtract

    So, how can I get the response body, without further error?

  • #2
    You can use the BufferingClientHttpRequestFactory, which is basically a wrapper around the other HTTP client. It allows for multiple reads from the response.