I have a RESTful service developed by Java Spring. I created some filters for authentications, get some custom headers, etc. etc. in one of the filters I need to log incoming Request and outgoing Response. Right now I stuck in logging the response. here is the filter
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException
servletResponse
is the object that I need to get the content.
I know there are some duplicate questions that already answered but for some reason none of those works for me.
I have a filter
and in doFilter
method after chain.doFilter
I want to log the response content.
I can see the JSON
object when I'm inspecting the response
in outputStream
or in writer
. But I cannot get it programmatically.
Can someone help me to resolve this? Thank you in advance!
Here are the links that I used and didn't help:
How to read and copy the HTTP servlet response output stream content for logging
Capture and log the response body
Logging response body (HTML) from HttpServletResponse using Spring MVC HandlerInterceptorAdapter