JavaOmnibus
J2EE Intercepting Filter
J2EE pattern • Presentation
J2EEPresentationJava example

Intercepting Filter solves a specific structural problem in the design.

Run reusable request processing steps before the core handler.

Pattern overview

J2EE pattern

Run reusable request processing steps before the core handler.

Intent

Create a configurable pipeline of request-processing steps such as authentication, logging, and normalization.

Problem

Cross-cutting request behavior is duplicated across controllers or servlets.

Solution

Chain reusable filters that inspect or modify the request before delegating onward.

Fit and tradeoffs

FamilyJ2EE
CategoryPresentation
Best used when
  • For auth, tracing, audit, compression, and request decoration.
Tradeoffs
  • Order matters and can be confusing without conventions.

Java example

This example is intentionally compact so the pattern shape stays easy to see.

public final class CorrelationIdFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
        request.setAttribute("correlationId", UUID.randomUUID().toString());
        chain.doFilter(request, response);
    }
}

Related pages

Keep exploring