2

I want to get the actual content of the response as a string from HttpServletResponse object in afterCompletion method in my Spring interceptor.

Note: I need to get this in Interceptor only, not using Filters. Any options available ?

@Component
public class RestInterceptor implements HandlerInterceptor {

@Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

         // Need to get the actual response content here from HttpServletResponse
    }
}
Somu
  • 71
  • 1
  • 1
  • 7
  • 1
    Does this answer your question? [How to read and copy the HTTP servlet response output stream content for logging](https://stackoverflow.com/questions/8933054/how-to-read-and-copy-the-http-servlet-response-output-stream-content-for-logging) – Mike Dec 02 '19 at 22:14
  • Does this answer your question? [How to read httpServletResponse in the interceptor?](https://stackoverflow.com/questions/45879552/how-to-read-httpservletresponse-in-the-interceptor) – Alan Hay Dec 03 '19 at 12:05
  • Didn't help any fo them. I need to get the response body content in Interceptor, not in filter. In filter i am able to get it, but i need it in interceptor. – Somu Dec 05 '19 at 04:44
  • I looked all over the places for exactly this. But no luck. How did you solve this @somu – NaveeNeo Jun 09 '22 at 09:13
  • try use implementation from question: https://stackoverflow.com/questions/75220192/how-to-get-response-from-httpservletresponse-and-save-to-database-in-java-via-in – svz Jan 24 '23 at 10:30

0 Answers0