Class FilteredRouter

java.lang.Object
io.micronaut.web.router.filter.FilteredRouter
All Implemented Interfaces:
Router

public class FilteredRouter extends Object implements Router
Allows decorating an existing Router with filtering capabilities.

Filters themselves should be supplied via the RouteMatchFilter interface.

A filtered router can be enabled by implementing a BeanCreatedEventListener for the existing Router and decorating appropriately. See for example VersionAwareRouterListener

Since:
1.1.0
See Also:
  • Constructor Details

  • Method Details

    • findAny

      @NonNull public <T, R> @NonNull Stream<UriRouteMatch<T,R>> findAny(@NonNull @NonNull CharSequence uri, @Nullable @Nullable io.micronaut.http.HttpRequest<?> context)
      Description copied from interface: Router
      Find any RouteMatch regardless of HTTP method.
      Specified by:
      findAny in interface Router
      Type Parameters:
      T - The target type
      R - The return type
      Parameters:
      uri - The URI
      context - The optional HttpRequest context information to apply RouteMatchFilter.
      Returns:
      A stream of route matches
    • findAny

      public <T, R> List<UriRouteMatch<T,R>> findAny(io.micronaut.http.HttpRequest<?> request)
      Description copied from interface: Router
      Find any RouteMatch regardless of HTTP method.
      Specified by:
      findAny in interface Router
      Type Parameters:
      T - The target type
      R - The return type
      Parameters:
      request - The request
      Returns:
      A stream of route matches
    • getExposedPorts

      public Set<Integer> getExposedPorts()
      Specified by:
      getExposedPorts in interface Router
      Returns:
      The exposed ports.
    • applyDefaultPorts

      public void applyDefaultPorts(List<Integer> ports)
      Description copied from interface: Router
      Sets the ports the application will listen to by default.
      Specified by:
      applyDefaultPorts in interface Router
      Parameters:
      ports - The default ports
    • find

      @NonNull public <T, R> @NonNull Stream<UriRouteMatch<T,R>> find(@NonNull @NonNull io.micronaut.http.HttpMethod httpMethod, @NonNull @NonNull CharSequence uri, @Nullable @Nullable io.micronaut.http.HttpRequest<?> context)
      Description copied from interface: Router
      Finds all possible routes for the given HTTP method and URI.
      Specified by:
      find in interface Router
      Type Parameters:
      T - The target type
      R - The type
      Parameters:
      httpMethod - The HTTP method
      uri - The URI route match
      context - The optional HttpRequest context information to apply RouteMatchFilter.
      Returns:
      A Stream of possible Route instances.
    • findAllClosest

      @NonNull public <T, R> @NonNull List<UriRouteMatch<T,R>> findAllClosest(@NonNull @NonNull io.micronaut.http.HttpRequest<?> request)
      Description copied from interface: Router
      Finds the closest match for the given request.
      Specified by:
      findAllClosest in interface Router
      Type Parameters:
      T - The target type
      R - The type
      Parameters:
      request - The request
      Returns:
      A List of possible Route instances.
    • find

      @NonNull public <T, R> @NonNull Stream<UriRouteMatch<T,R>> find(@NonNull @NonNull io.micronaut.http.HttpRequest<?> request, @NonNull @NonNull CharSequence uri)
      Description copied from interface: Router
      Find method, that should be used for non-standard http methods. For standards, it should act the same as Router.find(HttpMethod, CharSequence, HttpRequest)
      Specified by:
      find in interface Router
      Type Parameters:
      T - The target type.
      R - The type of what
      Parameters:
      request - The request, that can have overridden HttpRequest.getMethodName()
      uri - The URI route match.
      Returns:
      A Stream of possible Route instances.
    • uriRoutes

      @NonNull public @NonNull Stream<UriRouteInfo<?,?>> uriRoutes()
      Description copied from interface: Router
      Returns all UriRoutes.
      Specified by:
      uriRoutes in interface Router
      Returns:
      A Stream of all registered UriRoute instances.
    • route

      public <T, R> Optional<UriRouteMatch<T,R>> route(@NonNull @NonNull io.micronaut.http.HttpMethod httpMethod, @NonNull @NonNull CharSequence uri)
      Description copied from interface: Router
      Finds the first possible route for the given HTTP method and URI.
      Specified by:
      route in interface Router
      Type Parameters:
      T - The target type
      R - The URI route match
      Parameters:
      httpMethod - The HTTP method
      uri - The URI
      Returns:
      The route match
    • route

      public <R> Optional<RouteMatch<R>> route(@NonNull @NonNull io.micronaut.http.HttpStatus status)
      Description copied from interface: Router
      Found a RouteMatch for the given HttpStatus code.
      Specified by:
      route in interface Router
      Type Parameters:
      R - The matched route
      Parameters:
      status - The HTTP status
      Returns:
      The RouteMatch
    • route

      public <R> Optional<RouteMatch<R>> route(@NonNull @NonNull Class<?> originatingClass, @NonNull @NonNull io.micronaut.http.HttpStatus status)
      Description copied from interface: Router
      Found a RouteMatch for the given HttpStatus code.
      Specified by:
      route in interface Router
      Type Parameters:
      R - The matched route
      Parameters:
      originatingClass - The class the error originates from
      status - The HTTP status
      Returns:
      The RouteMatch
    • route

      public <R> Optional<RouteMatch<R>> route(@NonNull @NonNull Throwable error)
      Description copied from interface: Router
      Match a route to an error.
      Specified by:
      route in interface Router
      Type Parameters:
      R - The matched route
      Parameters:
      error - The error
      Returns:
      The RouteMatch
    • route

      public <R> Optional<RouteMatch<R>> route(@NonNull @NonNull Class<?> originatingClass, @NonNull @NonNull Throwable error)
      Description copied from interface: Router
      Match a route to an error.
      Specified by:
      route in interface Router
      Type Parameters:
      R - The matched route
      Parameters:
      originatingClass - The class the error originates from
      error - The error
      Returns:
      The RouteMatch
    • findErrorRoute

      public <R> Optional<RouteMatch<R>> findErrorRoute(@NonNull @NonNull Class<?> originatingClass, @NonNull @NonNull Throwable error, io.micronaut.http.HttpRequest<?> request)
      Description copied from interface: Router
      Match a route to an error.
      Specified by:
      findErrorRoute in interface Router
      Type Parameters:
      R - The matched route
      Parameters:
      originatingClass - The class the error originates from
      error - The error
      request - The request
      Returns:
      The RouteMatch
    • findErrorRoute

      public <R> Optional<RouteMatch<R>> findErrorRoute(@NonNull @NonNull Throwable error, io.micronaut.http.HttpRequest<?> request)
      Description copied from interface: Router
      Match a route to an error.
      Specified by:
      findErrorRoute in interface Router
      Type Parameters:
      R - The matched route
      Parameters:
      error - The error
      request - The request
      Returns:
      The RouteMatch
    • findStatusRoute

      public <R> Optional<RouteMatch<R>> findStatusRoute(@NonNull @NonNull Class<?> originatingClass, @NonNull @NonNull io.micronaut.http.HttpStatus status, io.micronaut.http.HttpRequest<?> request)
      Description copied from interface: Router
      Found a RouteMatch for the given HttpStatus code.
      Specified by:
      findStatusRoute in interface Router
      Type Parameters:
      R - The matched route
      Parameters:
      originatingClass - The class the error originates from
      status - The HTTP status
      request - The request
      Returns:
      The RouteMatch
    • findStatusRoute

      public <R> Optional<RouteMatch<R>> findStatusRoute(Class<?> originatingClass, int statusCode, io.micronaut.http.HttpRequest<?> request)
      Description copied from interface: Router
      Found a RouteMatch for the given status code.
      Specified by:
      findStatusRoute in interface Router
      Type Parameters:
      R - The matched route
      Parameters:
      originatingClass - The class the error originates from
      statusCode - The HTTP status
      request - The request
      Returns:
      The RouteMatch
    • findStatusRoute

      public <R> Optional<RouteMatch<R>> findStatusRoute(@NonNull @NonNull io.micronaut.http.HttpStatus status, io.micronaut.http.HttpRequest<?> request)
      Description copied from interface: Router
      Found a RouteMatch for the given HttpStatus code.
      Specified by:
      findStatusRoute in interface Router
      Type Parameters:
      R - The matched route
      Parameters:
      status - The HTTP status
      request - The request
      Returns:
      The RouteMatch
    • findStatusRoute

      public <R> Optional<RouteMatch<R>> findStatusRoute(int statusCode, io.micronaut.http.HttpRequest<?> request)
      Description copied from interface: Router
      Found a RouteMatch for the given status code.
      Specified by:
      findStatusRoute in interface Router
      Type Parameters:
      R - The matched route
      Parameters:
      statusCode - The HTTP status code
      request - The request
      Returns:
      The RouteMatch
    • findFilters

      @NonNull public @NonNull List<io.micronaut.http.filter.GenericHttpFilter> findFilters(@NonNull @NonNull io.micronaut.http.HttpRequest<?> request)
      Description copied from interface: Router
      Build a filtered Publisher for an action.
      Specified by:
      findFilters in interface Router
      Parameters:
      request - The request
      Returns:
      A new filtered publisher
    • GET

      public <T, R> Optional<UriRouteMatch<T,R>> GET(@NonNull @NonNull CharSequence uri)
      Description copied from interface: Router
      Find the first RouteMatch route for an HttpMethod.GET method and the given URI.
      Specified by:
      GET in interface Router
      Type Parameters:
      T - The target type
      R - The return type
      Parameters:
      uri - The URI
      Returns:
      An Optional of RouteMatch
    • POST

      public <T, R> Optional<UriRouteMatch<T,R>> POST(@NonNull @NonNull CharSequence uri)
      Description copied from interface: Router
      Find the first RouteMatch route for an HttpMethod.POST method and the given URI.
      Specified by:
      POST in interface Router
      Type Parameters:
      T - The target type
      R - The return type
      Parameters:
      uri - The URI
      Returns:
      An Optional of RouteMatch
    • PUT

      public <T, R> Optional<UriRouteMatch<T,R>> PUT(@NonNull @NonNull CharSequence uri)
      Description copied from interface: Router
      Find the first RouteMatch route for an HttpMethod.PUT method and the given URI.
      Specified by:
      PUT in interface Router
      Type Parameters:
      T - The target type
      R - The URI route match
      Parameters:
      uri - The URI
      Returns:
      An Optional of RouteMatch
    • PATCH

      public <T, R> Optional<UriRouteMatch<T,R>> PATCH(@NonNull @NonNull CharSequence uri)
      Description copied from interface: Router
      Find the first RouteMatch route for an HttpMethod.PATCH method and the given URI.
      Specified by:
      PATCH in interface Router
      Type Parameters:
      T - The target type
      R - The return type
      Parameters:
      uri - The URI
      Returns:
      An Optional of RouteMatch
    • DELETE

      public <T, R> Optional<UriRouteMatch<T,R>> DELETE(@NonNull @NonNull CharSequence uri)
      Description copied from interface: Router
      Find the first RouteMatch route for an HttpMethod.DELETE method and the given URI.
      Specified by:
      DELETE in interface Router
      Type Parameters:
      T - The target type
      R - The return type
      Parameters:
      uri - The URI
      Returns:
      An Optional of RouteMatch
    • OPTIONS

      public <T, R> Optional<UriRouteMatch<T,R>> OPTIONS(@NonNull @NonNull CharSequence uri)
      Description copied from interface: Router
      Find the first RouteMatch route for an HttpMethod.OPTIONS method and the given URI.
      Specified by:
      OPTIONS in interface Router
      Type Parameters:
      T - The target type
      R - The return type
      Parameters:
      uri - The URI
      Returns:
      An Optional of RouteMatch
    • HEAD

      public <T, R> Optional<UriRouteMatch<T,R>> HEAD(@NonNull @NonNull CharSequence uri)
      Description copied from interface: Router
      Find the first RouteMatch route for an HttpMethod.HEAD method and the given URI.
      Specified by:
      HEAD in interface Router
      Type Parameters:
      T - The target type
      R - The return type
      Parameters:
      uri - The URI
      Returns:
      An Optional of RouteMatch
    • find

      @NonNull public <T, R> @NonNull Stream<UriRouteMatch<T,R>> find(@NonNull @NonNull io.micronaut.http.HttpRequest<?> request)
      Description copied from interface: Router
      Finds all possible routes for the given HTTP request.
      Specified by:
      find in interface Router
      Type Parameters:
      T - The target type
      R - The URI route match
      Parameters:
      request - The HTTP request
      Returns:
      A Stream of possible Route instances.