Issue
Is it possible to intercept all responses with redirection via location header to enrich the payload with HTML meta refresh or redirection via JS?
Solution
Current Solution that works for me and is used during authentication redirection:
Configure a Filter after LogoutFilter.class
. This Filter wraps HttpServletResponse
. This wrapper of HttpServletResponse
overrides HttpServletResponse#sendRedirect(String)
to print to response writer and HttpServletResponse#setHeader(String)
to also print to response writer -- in case someone didn't use #sendRedirect(String)
but set Location header.
The Reason to override #sendRedirect(String)
ist that the response stream is reset before at the beginn and closes the stream at the end.
No embedded implementation provides by default a payload for redirection. Tomcat can use 'coyoteResponse.sendRedirect.note' property and print it in redirect. Jetty and Undertow do not print to response writer any payload.
Note: Not using Location header to redirect slows website response and IMHO makes a horrible user experience.
Answered By - Paul
Answer Checked By - Marilyn (JavaFixing Volunteer)