Class DefaultRouter

java.lang.Object
io.micronaut.web.router.DefaultRouter
All Implemented Interfaces:
io.micronaut.http.filter.HttpFilterResolver<RouteMatch<?>>, io.micronaut.http.filter.HttpServerFilterResolver<RouteMatch<?>>, Router

@Singleton public class DefaultRouter extends Object implements Router, io.micronaut.http.filter.HttpServerFilterResolver<RouteMatch<?>>

The default Router implementation. This implementation does not perform any additional caching of route discovery.

Since:
1.0
  • Constructor Details

    • DefaultRouter

      public DefaultRouter(RouteBuilder... builders)
      Construct a new router for the given route builders.
      Parameters:
      builders - The builders
    • DefaultRouter

      @Inject public DefaultRouter(Collection<RouteBuilder> builders)
      Construct a new router for the given route builders.
      Parameters:
      builders - The builders
  • Method Details

    • 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.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.
    • 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.
    • 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.
    • 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.
    • findClosest

      public <T, R> UriRouteMatch<T,R> findClosest(io.micronaut.http.HttpRequest<?> request) throws DuplicateRouteException
      Description copied from interface: Router
      Finds the closest match for the given request or null if none is found.
      Specified by:
      findClosest in interface Router
      Type Parameters:
      T - The target type
      R - The type
      Parameters:
      request - The request
      Returns:
      A match or null, throws DuplicateRouteException on multiple routes.
      Throws:
      DuplicateRouteException
    • 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.
    • route

      @NonNull public <T, R> @NonNull 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 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(@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(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(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
    • 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
    • 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
    • findAny

      @NonNull public <T, R> @NonNull Stream<UriRouteMatch<T,R>> findAny(@NonNull @NonNull CharSequence uri, @Nullable @Nullable 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:
      uri - The URI
      request - 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
    • resolveFilterEntries

      public List<io.micronaut.http.filter.HttpFilterResolver.FilterEntry> resolveFilterEntries(RouteMatch<?> routeMatch)
      Specified by:
      resolveFilterEntries in interface io.micronaut.http.filter.HttpFilterResolver<RouteMatch<?>>
    • resolveFilters

      public List<io.micronaut.http.filter.GenericHttpFilter> resolveFilters(io.micronaut.http.HttpRequest<?> request, List<io.micronaut.http.filter.HttpFilterResolver.FilterEntry> filterEntries)
      Specified by:
      resolveFilters in interface io.micronaut.http.filter.HttpFilterResolver<RouteMatch<?>>