HttpContext instances.
Each Filter in the chain, invokes the next filter within its own
doFilter(HttpExchange, Chain) implementation. The final Filter
in the chain invokes the applications exchange handler.
- Since:
- 1.6
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FilterafterHandler(String description, Consumer<HttpExchange> operation) Returns a post-processingFilterwith the given description and operation.static FilterbeforeHandler(String description, Consumer<HttpExchange> operation) Returns a pre-processingFilterwith the given description and operation.abstract StringReturns a short description of thisFilter.abstract voiddoFilter(HttpExchange exchange, Filter.Chain chain) Asks this filter to pre/post-process the given exchange.
-
Constructor Details
-
Filter
protected Filter()Constructor for subclasses to call.
-
-
Method Details
-
doFilter
Asks 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
HttpExchange.setStreams(InputStream, OutputStream). - Set attribute objects in the exchange, which other filters or the exchange handler can access.
- Decide to either:
- Invoke the next filter in the chain, by calling
Filter.Chain.doFilter(HttpExchange). - Terminate the chain of invocation, by not calling
Filter.Chain.doFilter(HttpExchange).
- Invoke the next filter in the chain, by calling
- If option 1. above is 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 is taken, then this Filter must use the HttpExchange to send back an appropriate response.
- Parameters:
exchange- theHttpExchangeto be filteredchain- theChainwhich allows the next filter to be invoked- Throws:
IOException- may be thrown by any filter module, and if caught, must be rethrown againNullPointerException- if either exchange or chain arenull
-
description
Returns a short description of thisFilter.- Returns:
- a
Stringdescribing theFilter
-
beforeHandler
Returns a pre-processingFilterwith the given description and operation.The
operationis the effective implementation of the filter. It is executed for eachHttpExchangebefore invoking either the next filter in the chain or the exchange handler (if this is the final filter in the chain). Exceptions thrown by theoperationare not handled by the filter.- Parameters:
description- the string to be returned fromdescription()operation- the operation of the returned filter- Returns:
- a filter whose operation is invoked before the exchange is handled
- Throws:
NullPointerException- if any argument is null- Since:
- 17
-
afterHandler
Returns a post-processingFilterwith the given description and operation.The
operationis the effective implementation of the filter. It is executed for eachHttpExchangeafter invoking either the next filter in the chain or the exchange handler (if this filter is the final filter in the chain). Exceptions thrown by theoperationare not handled by the filter.- Parameters:
description- the string to be returned fromdescription()operation- the operation of the returned filter- Returns:
- a filter whose operation is invoked after the exchange is handled
- Throws:
NullPointerException- if any argument is null- Since:
- 17
-