I inherited a Struts 1 app that heavily utilizes FilterChain and I don't understand the benefit of this extremely obfuscating code.
"In the Servlet API, you normally use a Servlet when you want to control, preprocess and/or postprocess specific requests. But when you want to filter/modify common requests and/or responses based on specific conditions, then a Filter is much more suitable."
Every request in my app is based on specific conditions, e.g., a merchant id or a search term. But it seems like placing a request inside a whole chain of stuff that completely hides what is going on from the developer trying to trace the cause of an error, is nuts.
The FilterChain#doFilter()
call just continues the HTTP request to the destination, following exactly the same path as if you didn't use a filter in first place. This is usually a servlet class or even a JSP file. So, in order to debug problematic code, better put a breakpoint in the target code, not in the filter if it doesn't contain any code of interest.
My coworker (who's not registered on SO) explained that it's for applying global functionality to an app that you don't want to do in every single controller, such as checking if the user is logged in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With