Class FilterRunner

java.lang.Object
io.micronaut.http.filter.FilterRunner

@Internal public class FilterRunner extends Object
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 Details

    • FilterRunner

      public FilterRunner(List<GenericHttpFilter> filters)
      Create a new filter runner, to be used only once.
      Parameters:
      filters - The filters to run
  • Method Details

    • sort

      public static void sort(@NonNull @NonNull List<GenericHttpFilter> filters)
      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

      public static void sortReverse(@NonNull @NonNull List<GenericHttpFilter> filters)
      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 request
      response - The current response
      propagatedContext - 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 request
      failure - The failure
      propagatedContext - The propagated context
      Returns:
      A flow that will be passed on to the next filter
    • run

      public final 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(ConversionService conversionService, T bean, ExecutableMethod<T,?> method, boolean isResponseFilter, FilterOrder order, RequestBinderRegistry argumentBinderRegistry) throws IllegalArgumentException
      Throws:
      IllegalArgumentException