You must provide your own wrapper for the Writer HttpServletResponse (via the HttpServletResponseWrapper in Filter ), and each time you write to this writer, also save it in StringBuilder .
This is just a sketch of the code, there are a sufficient number of examples, but the main steps are:
- create filter
- wrap
PrintWriter so that it saves every entry in the builder - expand
HttpServletResponseWrapper and make it return author wrapper - create
chain.doFilter(request, new HttpServletResponseWrapper(response))
Bozho source share