public abstract class Filter extends ObjectA filter used to pre- and post-process incoming requests. Pre-processing occurs before the application's exchange handler is invoked, and post-processing occurs after the exchange handler returns. Filters are organised in chains, and are associated with HttpContext instances.
Each Filter in the chain, invokes the next filter within its own doFilter() implementation. The final Filter in the chain invokes the applications exchange handler.
Nested Class Summary
Nested Classes Modifier and Type Class Description
Filter.Chaina chain of filters associated with a HttpServer.
Constructors Modifier Constructor Description
All Methods Instance Methods Abstract Methods Modifier and Type Method Description
description()returns a short description of this Filter
doFilter(HttpExchange exchange, Filter.Chain chain)Asks this filter to pre/post-process the given exchange.
public abstract void doFilter(HttpExchange exchange, Filter.Chain chain) throws IOExceptionAsks this filter to pre/post-process the given exchange. The filter can:
- examine or modify the request headers
- filter the request body or the response body, by creating suitable
filter streams and calling
- set attribute Objects in the exchange, which other filters or the exchange handler can access.
- decide to either
- if option 1. above taken, then when doFilter() returns all subsequent filters in the Chain have been called, and the response headers can be examined or modified.
- if option 2. above taken, then this Filter must use the HttpExchange to send back an appropriate response
public abstract String description()returns a short description of this Filter
- a string describing the Filter