Package io.micronaut.http.filter
Class FilterRunner
java.lang.Object
io.micronaut.http.filter.FilterRunner
The filter runner will start processing the filters in the forward order.
All the request filters are executed till one of them returns a response (bypasses the route execution for controllers or the client invocation),
or the terminal filter will produce the response from the route/client call.
After that, the filters are processed in the opposite order so response filters can be processed,
which can sometimes override the existing response.
There is a special case of response filters that needs to process the response; for those cases,
the filter needs to be suspended, and the next filter in the order needs to be executed.
When the response is committed, the filter will be resumed when it's processed again.
There is a special case for the client filters; those will process the exception,
which needs to be tracked during the response filtering phase.
- Since:
- 4.0.0
- Author:
- Jonas Konrad, Denis Stepanov
-
Constructor Summary
ConstructorDescriptionFilterRunner
(List<GenericHttpFilter> filters) Create a new filter runner, to be used only once. -
Method Summary
Modifier and TypeMethodDescriptionprotected ExecutionFlow<? extends HttpResponse<?>>
processFailure
(HttpRequest<?> request, Throwable failure, PropagatedContext propagatedContext) Transform a failure, e.g.protected ExecutionFlow<? extends HttpResponse<?>>
processResponse
(HttpRequest<?> request, HttpResponse<?> response, PropagatedContext propagatedContext) Transform a response, e.g.final ExecutionFlow<MutableHttpResponse<?>>
run
(HttpRequest<?> request) Execute the filters for the given request.static void
sort
(@NonNull List<GenericHttpFilter> filters) Sort filters according to their declared order (e.g.static void
sortReverse
(@NonNull List<GenericHttpFilter> filters) Sort filters according to their declared order (e.g.
-
Constructor Details
-
FilterRunner
Create a new filter runner, to be used only once.- Parameters:
filters
- The filters to run
-
-
Method Details
-
sort
Sort filters according to their declared order (e.g. annotation,Ordered.getOrder()
...). List must not contain terminal filters.- Parameters:
filters
- The list of filters to sort in place
-
sortReverse
Sort filters according to their declared order (e.g. annotation,Ordered.getOrder()
...). List must not contain terminal filters. Reverse order.- Parameters:
filters
- The list of filters to sort in place
-
processResponse
protected ExecutionFlow<? extends HttpResponse<?>> processResponse(HttpRequest<?> request, HttpResponse<?> response, PropagatedContext propagatedContext) Transform a response, e.g. by replacing an error response with an exception. Called before every filter.- Parameters:
request
- The current requestresponse
- The current responsepropagatedContext
- The propagated context- Returns:
- A flow that will be passed on to the next filter
-
processFailure
protected ExecutionFlow<? extends HttpResponse<?>> processFailure(HttpRequest<?> request, Throwable failure, PropagatedContext propagatedContext) Transform a failure, e.g. by replacing an exception with an error response. Called before every filter.- Parameters:
request
- The current requestfailure
- The failurepropagatedContext
- The propagated context- Returns:
- A flow that will be passed on to the next filter
-
run
Execute the filters for the given request. May only be called once- Parameters:
request
- The request- Returns:
- The flow that completes after all filters and the terminal operation, with the final response
-