mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-08-09 20:22:06 +00:00
docs: Content SEO updates (#2990)
* update yaml frontmatter format * update abstract document * update abstract factory * use the new pattern template * acyclic visitor seo * adapter seo * ambassador seo * acl seo * aaa seo * async method invocation seo * balking seo * bridge seo * builder seo * business delegate and bytecode seo * caching seo * callback seo * chain seo * update headings * circuit breaker seo * client session + collecting parameter seo * collection pipeline seo * combinator SEO * command seo * cqrs seo * commander seo * component seo * composite seo * composite entity seo * composite view seo * context object seo * converter seo * crtp seo * currying seo * dao seo * data bus seo * data locality seo * data mapper seo * dto seo * decorator seo * delegation seo * di seo * dirty flag seo * domain model seo * double buffer seo * double checked locking seo * double dispatch seo * dynamic proxy seo * event aggregator seo * event-based asynchronous seo * eda seo * event queue seo * event sourcing seo * execute around seo * extension objects seo * facade seo * factory seo * factory kit seo * factory method seo * fanout/fanin seo * feature toggle seo * filterer seo * fluent interface seo * flux seo * flyweight seo * front controller seo * function composition seo * game loop seo * gateway seo * guarded suspension seo * half-sync/half-async seo * health check seo * hexagonal seo * identity map seo * intercepting filter seo * interpreter seo * iterator seo * layers seo * lazy loading seo * leader election seo * leader/followers seo * lockable object seo * rename and add seo for marker interface * master-worker seo * mediator seo * memento seo * metadata mapping seo * microservice aggregator seo * api gw seo * microservices log aggregration seo * mvc seo * mvi seo * mvp seo * mvvm seo * monad seo * monitor seo * monostate seo * multiton seo * mute idiom seo * naked objects & notification seo * null object seo * object mother seo * object pool seo * observer seo * optimistic locking seo * page controller seo * page object seo * parameter object seo * partial response seo * pipeline seo * poison pill seo * presentation model seo * private class data seo * producer-consumer seo * promise seo * property seo * prototype seo * proxy seo * queue-based load leveling seo * reactor seo * registry seo * repository seo * RAII seo * retry seo * role object seo * saga seo * separated interface seo * serialized entity seo * serialized lob seo * servant seo * server session seo * service layer seo * service locator seo * service to worker seo * sharding seo * single table inheritance seo * singleton seo * spatial partition seo * special case seo * specification seo * state seo * step builder seo * strangler seo * strategy seo * subclass sandbox seo * table module seo * template method seo * throttling seo * tolerant reader seo * trampoline seo * transaction script seo * twin seo * type object seo * unit of work seo * update method seo * value object seo * version number seo * virtual proxy seo * visitor seo * seo enhancements * seo improvements * SEO enhancements * SEO improvements * SEO additions * SEO improvements * more SEO improvements * rename hexagonal + SEO improvements * SEO improvements * more SEO stuff * SEO improvements * SEO optimizations * SEO enhancements * enchance SEO * improve SEO * SEO improvements * update headers
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
---
|
||||
title: Intercepting Filter
|
||||
title: "Intercepting Filter Pattern in Java: Enhancing Request Processing in Web Applications"
|
||||
shortTitle: Intercepting Filter
|
||||
description: "Learn about the Intercepting Filter Pattern in Java. Discover how to design, implement, and use this pattern to enhance web request handling with practical examples and detailed explanations."
|
||||
category: Architectural
|
||||
language: en
|
||||
tag:
|
||||
- API design
|
||||
- Decoupling
|
||||
- Layered architecture
|
||||
- Performance
|
||||
- Security
|
||||
- Web development
|
||||
- API design
|
||||
- Decoupling
|
||||
- Layered architecture
|
||||
- Performance
|
||||
- Security
|
||||
- Web development
|
||||
---
|
||||
|
||||
## Intent
|
||||
## Intent of Intercepting Filter Design Pattern
|
||||
|
||||
The Intercepting Filter pattern is intended to provide a pluggable framework for preprocessing and postprocessing web requests and responses. It allows different filters to process client requests and server responses in a configurable, decoupled manner.
|
||||
The Intercepting Filter Pattern in Java is a powerful design pattern that allows for efficient web request handling. This pattern enables the application of multiple filters in a filter chain to process and modify requests and responses.
|
||||
|
||||
## Explanation
|
||||
## Detailed Explanation of Intercepting Filter Pattern with Real-World Examples
|
||||
|
||||
Real-world example
|
||||
|
||||
@@ -29,11 +31,11 @@ Wikipedia says
|
||||
|
||||
> Intercepting Filter is a Java pattern which creates pluggable filters to process common services in a standard manner without requiring changes to core request processing code.
|
||||
|
||||
## Programmatic Example
|
||||
## Programmatic Example of Intercepting Filter Pattern in Java
|
||||
|
||||
Intercepting Filter is a pattern that creates pluggable filters to process common services in a standard manner without requiring changes to core request processing code. These filters can perform tasks such as authentication, logging, data compression, and encryption.
|
||||
In this article, we delve into the Intercepting Filter Pattern and provide a Java example to illustrate its use. This pattern is essential for Java web development, offering a modular approach to handling common services such as logging, authentication, and data compression.
|
||||
|
||||
In the provided code, we can see an example of the Intercepting Filter pattern in the `App`, `FilterManager`, `Client`, and various `Filter` classes.
|
||||
The Java implementation of the Intercepting Filter Pattern includes classes like `FilterManager` and `Client`, which facilitate the management and application of filters. Each filter in the chain performs specific tasks, ensuring a clean and efficient design.
|
||||
|
||||
The `App` class is the entry point of the application. It creates an instance of `FilterManager`, adds various filters to it, and sets it to a `Client`.
|
||||
|
||||
@@ -114,26 +116,26 @@ public class NameFilter extends AbstractFilter {
|
||||
|
||||
In this example, the `App` class sets up a `FilterManager` with various filters and assigns it to a `Client`. When the `Client` sends a request, the `FilterManager` applies all the filters to the request. This is a basic example of the Intercepting Filter pattern, where common processing tasks are encapsulated in filters and applied to requests in a standard manner.
|
||||
|
||||
## Applicability
|
||||
## When to Use the Intercepting Filter Pattern in Java
|
||||
|
||||
Use the Intercepting Filter pattern when
|
||||
|
||||
* Use the Intercepting Filter pattern when you need to apply pre-processing and post-processing steps to requests and responses, typically in web applications.
|
||||
* In Java web applications to manage cross-cutting concerns.
|
||||
* When you need to apply pre-processing and post-processing steps to requests and responses, typically in web applications.
|
||||
* Suitable for handling cross-cutting concerns such as logging, authentication, data compression, and encryption transparently.
|
||||
|
||||
## Tutorials
|
||||
## Intercepting Filter Pattern Java Tutorials
|
||||
|
||||
* [Introduction to Intercepting Filter Pattern in Java (Baeldung)](https://www.baeldung.com/intercepting-filter-pattern-in-java)
|
||||
* [Design Pattern - Intercepting Filter Pattern (TutorialsPoint)](http://www.tutorialspoint.com/design_pattern/intercepting_filter_pattern.htm)
|
||||
|
||||
## Known Uses
|
||||
## Real-World Applications of Intercepting Filter Pattern in Java
|
||||
|
||||
* Web servers like Apache Tomcat and Java EE web containers often use this pattern to implement filters that manipulate byte streams from requests and responses.
|
||||
* Frameworks like Spring MVC utilize this pattern to manage interceptors that add behavior to web requests.
|
||||
* Frameworks like Spring MVC and web servers such as Apache Tomcat utilize the Intercepting Filter Pattern to enhance Java web development. This pattern's ability to centralize control and streamline web request handling makes it a go-to choice for developers.
|
||||
* [javax.servlet.FilterChain](https://tomcat.apache.org/tomcat-8.0-doc/servletapi/javax/servlet/FilterChain.html) and [javax.servlet.Filter](https://tomcat.apache.org/tomcat-8.0-doc/servletapi/javax/servlet/Filter.html)
|
||||
* [Struts 2 - Interceptors](https://struts.apache.org/core-developers/interceptors.html)
|
||||
|
||||
## Consequences
|
||||
## Benefits and Trade-offs of Intercepting Filter Pattern
|
||||
|
||||
Benefits:
|
||||
|
||||
@@ -146,12 +148,12 @@ Trade-offs:
|
||||
* Introducing many filters can lead to performance overhead due to the processing of each request and response through multiple filters.
|
||||
* Debugging and tracing the request flow through multiple filters can be complex.
|
||||
|
||||
## Related Patterns
|
||||
## Related Java Design Patterns
|
||||
|
||||
* [Decorator](https://java-design-patterns.com/patterns/decorator/): Filters in the Intercepting Filter pattern can be considered as decorators that add additional responsibilities to request handling. They modify the request/response without altering their fundamental behavior.
|
||||
* [Chain of Responsibility](https://java-design-patterns.com/patterns/chain-of-responsibility/): Filters are linked in a chain, where each filter processes the request or response and optionally passes it to the next filter in the chain, similar to how responsibilities are passed along in the Chain of Responsibility pattern.
|
||||
|
||||
## Credits
|
||||
## References and Credits
|
||||
|
||||
* [Core J2EE Patterns: Best Practices and Design Strategies](https://amzn.to/4cAbDap)
|
||||
* [Design Patterns: Elements of Reusable Object-Oriented Software](https://amzn.to/3w0pvKI)
|
||||
|
||||
Reference in New Issue
Block a user