Reputation:
I'm writing my first ever javax.servlet.Filter
impl and am trying to write the portion of the doFilter
method where I prevent the request from going any further in the chain:
@Override
public void doFilter(ServletRequest request, ServletResponse response)
FilterChain chain) throws IOException, ServletException {
// Check for some stuff in the request...
boolean passesInspection = inspect(request);
if(!passesInspection)
// How do I prevent the request from going any further?
// I don't want it even getting to the servlet at this point!
}
How do I "block" the request from even making it to the listening servlet? Thanks in advance.
Upvotes: 0
Views: 1778
Reputation: 20691
Simply don't call chain.doFilter()
. The doFilter()
call is what progresses the call. Don't call this and the processing stalls. This is not a good design however. You need to at least inform the caller
Upvotes: 4