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
-
Constructor Summary
ConstructorsConstructorDescriptionFilterRunner(List<GenericHttpFilter> filters) Create a new filter runner, to be used only once. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> io.micronaut.http.filter.FilterRunner.FilterMethod<T>prepareFilterMethod(io.micronaut.core.convert.ConversionService conversionService, T bean, io.micronaut.inject.ExecutableMethod<T, ?> method, boolean isResponseFilter, FilterOrder order) static <T> io.micronaut.http.filter.FilterRunner.FilterMethod<T>prepareFilterMethod(io.micronaut.core.convert.ConversionService conversionService, T bean, io.micronaut.inject.ExecutableMethod<T, ?> method, io.micronaut.core.type.Argument<?>[] arguments, io.micronaut.core.type.Argument<?> returnType, boolean isResponseFilter, FilterOrder order) protected io.micronaut.core.execution.ExecutionFlow<? extends HttpResponse<?>>processFailure(HttpRequest<?> request, Throwable failure) Transform a failure, e.g.protected io.micronaut.core.execution.ExecutionFlow<? extends HttpResponse<?>>processResponse(HttpRequest<?> request, HttpResponse<?> response) Transform a response, e.g.final io.micronaut.core.execution.ExecutionFlow<MutableHttpResponse<?>>run(HttpRequest<?> request) Execute the filters for the given request.static voidsort(List<GenericHttpFilter> filters) Sort filters according to their declared order (e.g.static voidsortReverse(List<GenericHttpFilter> filters) Sort filters according to their declared order (e.g.static voidvalidateFilterMethod(io.micronaut.core.type.Argument<?>[] arguments, io.micronaut.core.type.Argument<?> returnType, boolean isResponseFilter)
-
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 io.micronaut.core.execution.ExecutionFlow<? extends HttpResponse<?>> processResponse(HttpRequest<?> request, HttpResponse<?> response) Transform a response, e.g. by replacing an error response with an exception. Called before every filter.- Parameters:
request- The current requestresponse- The current response- Returns:
- A flow that will be passed on to the next filter
-
processFailure
protected io.micronaut.core.execution.ExecutionFlow<? extends HttpResponse<?>> processFailure(HttpRequest<?> request, Throwable failure) Transform a failure, e.g. by replacing an exception with an error response. Called before every filter.- Parameters:
request- The current requestfailure- The failure- Returns:
- A flow that will be passed on to the next filter
-
run
public final io.micronaut.core.execution.ExecutionFlow<MutableHttpResponse<?>> run(HttpRequest<?> request) 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
-
prepareFilterMethod
@Internal public static <T> io.micronaut.http.filter.FilterRunner.FilterMethod<T> prepareFilterMethod(io.micronaut.core.convert.ConversionService conversionService, T bean, io.micronaut.inject.ExecutableMethod<T, ?> method, boolean isResponseFilter, FilterOrder order) throws IllegalArgumentException- Throws:
IllegalArgumentException
-
validateFilterMethod
@Internal public static void validateFilterMethod(io.micronaut.core.type.Argument<?>[] arguments, io.micronaut.core.type.Argument<?> returnType, boolean isResponseFilter) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
prepareFilterMethod
@Internal public static <T> io.micronaut.http.filter.FilterRunner.FilterMethod<T> prepareFilterMethod(io.micronaut.core.convert.ConversionService conversionService, T bean, io.micronaut.inject.ExecutableMethod<T, ?> method, io.micronaut.core.type.Argument<?>[] arguments, io.micronaut.core.type.Argument<?> returnType, boolean isResponseFilter, FilterOrder order) throws IllegalArgumentException- Throws:
IllegalArgumentException
-