Day 05 — JAX-RS Filters & Request/Response Pipelines¶
Daily Time Investment: 2.0 hours | Week: 1 | Phase: 3
Daily Schedule¶
| Segment | Duration | Activity |
|---|---|---|
| Core Theory | 45 min | ContainerRequestFilter, ContainerResponseFilter, @PreMatching, @NameBinding, @Priority, abortWith() |
| Book Reading | 30 min | EE8 AppDev Ch10 (Filters) + EE8 AppDev Ch13 (Servlet Filters — conceptual comparison) |
| Hands-On Lab | 45 min | Correlation ID filter + Bearer token auth with abortWith + response header enrichment |
Files in This Day¶
-
EE8 AppDev Ch10 — JAX-RS Filters
@PreMatching,ContainerRequestFilter,ContainerResponseFilter,abortWith(), correlation ID pattern.Ch10 full content is in Day 03. This note focuses on the Filters section specifically.
-
EE8 AppDev Ch13 — Servlet Development & Filters
Servlet lifecycle (
doGet/doPost),@WebServlet, ServletFilterinterface,@WebFilter,FilterChain, Async Servlet (AsyncContext), Servlet listeners, HTTP/2 server push. -
Lab Guide — JAX-RS Filters & Pipelines
@PreMatchingcorrelation ID injection,@Authenticatedname-bound Bearer token filter withabortWith(401),ContainerResponseFilterresponse enrichment.
Prerequisites to Continue¶
New concepts in Phase 3 not seen in Phase 1 or Phase 2
javax.ws.rs.Priorities— standard priority constants for filter chain ordering:AUTHENTICATION(1000),AUTHORIZATION(2000),HEADER_DECORATOR(3000),USER(5000)ResourceInfo— injectable into post-matching filters via@Context ResourceInfo; gives access to the matchedMethodandClass(not available in@PreMatchingfilters)abortWith(Response)— short-circuits the entire pipeline; the resource method is never invoked butContainerResponseFilterstill fires- Correlation IDs — distributed tracing primitive; every request gets a unique UUID propagated through request properties, response headers, and logs
- Servlet Filter vs JAX-RS Filter — Servlet
@WebFilterfires at the Servlet container level (before JAX-RS runtime);ContainerRequestFilterfires inside the JAX-RS runtime (after Servlet dispatch)