I have seen that if I register a Spring GenericFilterBean
class, it invoked every time on request. Is it possible to invoke another filter (maybe another GeneircFilterBean
) only when service is returning the response? Basically, I wanted to achieve the same behavior as Jersey
ContainerResponseFilter
.
Thanks in advance
You can pass you code after chain.doFilter(request, response) method. Here is example.
public class SimpleLoggingFilter extends GenericFilterBean {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, response);
//This code will work after response
if ((response instanceof HttpServletResponse) && (request instanceof HttpServletRequest)) {
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
System.out.println("Response status is " + httpServletResponse.getStatus() +" " +
"Response content-length is " + httpServletResponse.getHeader("content-length"));
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.