Spring-boot Resttemplate response.body is null while interceptor clearly shows body

Although the accepted answer has the reason, I believe the solution is also necessary.

Spring has a BufferingClientHttpRequestFactory that acts as a wrapper to Rest Template's default SimpleClientHttpRequestFactory. It can be passed to a Rest Template during creation. This forces the Rest Template to make interceptors use a copy of the response rather than destroying it.

ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory());

RestTemplate restTemplate = new RestTemplate(factory);

Source : http://objectpartners.com/2018/03/01/log-your-resttemplate-request-and-response-without-destroying-the-body/


You're consuming the response body in traceResponse; that's your problem. Also, please update your question to be specific; "all latest" means nothing. What's latest today isn't so tomorrow.