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

  • Get body from ClientHttpResponse twice

    Hi!

    I need to check a response for a business error:


    restTemplate.setErrorHandler(new BusinessResponseErrorHandler());

    public class BusinessResponseErrorHandler implements ResponseErrorHandler {

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


    @Override
    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 java.io.EOFException: 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 or.java:76)


    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.

    Comment

    Working...
    X