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.
| Modifier and Type | Class and Description |
|---|---|
| public static class | Filter.
A chain of filters associated with a |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public static Filter | Returns: a filter that adapts the request state before the exchange is handledthe string to be returned from description, UnaryOperator<Request> description()the request operator requestOperator)Returns a pre-processing Filter that inspects and possibly adapts the request state. |
| public static Filter | Returns: a filter whose operation is invoked after the exchange is handledthe string to be returned from description, Consumer<HttpExchange> description()the operation of the returned filter operation)Returns a post-processing |
| public static Filter | Returns: a filter whose operation is invoked before the exchange is handledthe string to be returned from description, Consumer<HttpExchange> description()the operation of the returned filter operation)Returns a pre-processing |
| public abstract String | |
| public abstract void | doFilter(HttpExchange
the exchange, Filter.HttpExchange to be filteredthe chainChain which allows the next filter to be invokedAsks this filter to pre/post-process the given exchange. |
| Filter | back to summary |
|---|---|
| protected Filter() Constructor for subclasses to call. | |
| adaptRequest | back to summary |
|---|---|
| public static Filter adaptRequest(String description, UnaryOperator<Request> requestOperator) Returns a
pre-processing Filter
that inspects and possibly adapts the request state.
The API Note When the returned filter is invoked, it first invokes the
Example of adding the
| |
| afterHandler | back to summary |
|---|---|
| public static Filter afterHandler(String description, Consumer<HttpExchange> operation) Returns a post-processing The API Note An afterHandler filter is typically used to examine the exchange state
rather than modifying it. The filter Example of adding a filter that logs the response code of all exchanges:
Example of adding a sequence of afterHandler filters to a context:
The operation of
| |
| beforeHandler | back to summary |
|---|---|
| public static Filter beforeHandler(String description, Consumer<HttpExchange> operation) Returns a pre-processing The API Note A beforeHandler filter is typically used to examine or modify the
exchange state before it is handled. The filter Example of adding the
| |
| description | back to summary |
|---|---|
| public abstract String description() Returns a short description of this
| |
| doFilter | back to summary |
|---|---|
| public abstract void doFilter(HttpExchange exchange, Filter. Asks this filter to pre/post-process the given exchange. The filter can:
| |
HttpServer.
Each filter in the chain is given one of these so it can invoke the
next filter in the chain.
| Modifier and Type | Field and Description |
|---|---|
| private HttpHandler | |
| private ListIterator | iter
The last element in the chain must invoke the user's handler. |
| Access | Constructor and Description |
|---|---|
| public | Chain(List<Filter>
the filters that make up the filters, HttpHandler Chainthe handler)HttpHandler that will be invoked after
the final Filter has finishedCreates a |
| Modifier and Type | Method and Description |
|---|---|
| public void | doFilter(HttpExchange
the exchange)HttpExchangeCalls the next filter in the chain, or else the users exchange handler, if this is the final filter in the chain. |
| handler | back to summary |
|---|---|
| private HttpHandler handler | |
| iter | back to summary |
|---|---|
| private ListIterator<Filter> iter The last element in the chain must invoke the user's handler. | |
| Chain | back to summary |
|---|---|
| public Chain(List<Filter> filters, HttpHandler handler) Creates a
| |
| doFilter | back to summary |
|---|---|
| public void doFilter(HttpExchange exchange) throws IOException Calls the next filter in the chain, or else the users exchange
handler, if this is the final filter in the chain. The
| |