encyclopegia.org

Intercepting filter pattern

Intercepting Filter is a JavaEE pattern which creates pluggable filters to process common services in a standard manner without requiring changes to core request processing code. The filters intercept incoming requests and outgoing responses, allowing preprocessing and post-processing, and these filters can be added or removed unobtrusively without changing existing code. This pattern applies reusable processing transparently before and after the actual request execution by the front and page controllers.

Intercepting Filter is a JavaEE pattern which creates pluggable filters to process common services in a standard manner without requiring changes to core request processing code. The filters intercept incoming requests and outgoing responses, allowing preprocessing and post-processing, and these filters can be added or removed unobtrusively without changing existing code. This pattern applies reusable processing transparently before and after the actual request execution by the front and page controllers. ==Structure== Filter manager, filter chain, filters and target are components of the pattern. ===Filter manager=== This manages filter processing and creates the filter chain with the appropriate filters, in the correct order, and initiates processing. ===Filter chain=== A Filter Chain is a specific series of filters, composed so as to form a logical chain. ===Filters=== These are the individual filters that are mapped to a target and their processing is coordinated by filter chain. ===Target=== This is the resource requested by the client. ==Consequences== Following benefits can be considered: Improved reusability: Common code is centralized in pluggable components enhancing reuse. Increased flexibility: Generic common components can be applied and removed declaratively, improving flexibility. Reduced performance can be a concern, as unnecessarily long chains of interceptors and filters may hurt performance. ==Sample code== Sample code implementation for filters with custom filter strategy is given below. Code for implementing a filter - debugging filter: import java.io.IOException; import javax.annotation.processing.Processor; import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; public class DebuggingFilter implements Processor { private Processor target; public DebuggingFilter(Processor myTarget) { target = myTarget; } public void execute(ServletRequest req, ServletResponse res) throws IOException, ServletException { // Do some filter processing here, such as // displaying request parameters target.execute(req, res); } } Code for implementing a filter - core processor: import java.io.IOException; import javax.annotation.processing.Processor; import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; public class CoreProcessor implements Processor { private Processor target; public CoreProcessor() { this(null); } public CoreProcessor(Processor myTarget) { target = myTarget; } public void execute(ServletRequest req, ServletResponse res) throws IOException, ServletException { // Do core processing here } } Code for handling requests: import java.io.IOException; import javax.annotation.processing.Processor; import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; public void processRequest(ServletRequest req, ServletResponse res) throws IOException, ServletException { Processor processors = new DebuggingFilter(new AuthenticationFilter(new CoreProcessor())); processors.execute(req, res); //Then dispatch to next resource, which is probably // the View to display dispatcher.dispatch(req, res); } Code for filter manager: import java.io.IOException; import javax.annotation.processing.Processor; import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; public void processRequest(ServletRequest req, ServletResponse res) throws IOException, ServletException { Processor processors = new DebuggingFilter(new AuthenticationFilter(new CoreProcessor())); processors.execute(req, res); // Then dispatch to next resource, which is probably // the View to display dispatcher.dispatch(req, res); } Code for filter chain: import jakarta.servlet.Filter; public class FilterChain { // filter chain // apply filters for (final Filter filter : filters) { // pass request & response through various // filters filter.execute(request, response); } } } ==See also== Front controller Decorator pattern Template method pattern Interceptor pattern Pipeline (software) ==References==

References

No reference rows published for this article.

Cite this article

MLA

"Intercepting filter pattern." encyclopegia.org, 2026, https://encyclopegia.org/wiki/intercepting-filter-pattern. Accessed 24 November 2026.

Chicago

"Intercepting filter pattern." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/intercepting-filter-pattern.

APA

encyclopegia.org. (2026). Intercepting filter pattern. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/intercepting-filter-pattern

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1335337139 · 0.5 · snapshot enwiki-001335337139

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.