Class DefaultRouter

  • All Implemented Interfaces:
    io.micronaut.http.filter.HttpFilterResolver<io.micronaut.http.filter.HttpFilter,​RouteMatch<?>>, io.micronaut.http.filter.HttpServerFilterResolver<RouteMatch<?>>, Router

    @Singleton
    public class DefaultRouter
    extends java.lang.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
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface io.micronaut.http.filter.HttpFilterResolver

        io.micronaut.http.filter.HttpFilterResolver.FilterEntry<F extends java.lang.Object>
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultRouter​(RouteBuilder... builders)
      Construct a new router for the given route builders.
      DefaultRouter​(java.util.Collection<RouteBuilder> builders)
      Construct a new router for the given route builders.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void applyDefaultPorts​(java.util.List<java.lang.Integer> ports)
      Sets the ports the application will listen to by default.
      <T,​R>
      java.util.stream.Stream<UriRouteMatch<T,​R>>
      find​(io.micronaut.http.HttpMethod httpMethod, java.lang.CharSequence uri, io.micronaut.http.HttpRequest<?> context)
      Finds all of the possible routes for the given HTTP method and URI.
      <T,​R>
      java.util.stream.Stream<UriRouteMatch<T,​R>>
      find​(io.micronaut.http.HttpRequest<?> request)
      Finds all of the possible routes for the given HTTP request.
      <T,​R>
      java.util.stream.Stream<UriRouteMatch<T,​R>>
      find​(io.micronaut.http.HttpRequest<?> request, java.lang.CharSequence uri)
      Find method, that should be used for non-standard http methods.
      <T,​R>
      java.util.List<UriRouteMatch<T,​R>>
      findAllClosest​(io.micronaut.http.HttpRequest<?> request)
      Finds the closest match for the given request.
      <T,​R>
      java.util.stream.Stream<UriRouteMatch<T,​R>>
      findAny​(java.lang.CharSequence uri, io.micronaut.http.HttpRequest<?> context)
      Find any RouteMatch regardless of HTTP method.
      <R> java.util.Optional<RouteMatch<R>> findErrorRoute​(java.lang.Class<?> originatingClass, java.lang.Throwable error, io.micronaut.http.HttpRequest<?> request)
      Match a route to an error.
      <R> java.util.Optional<RouteMatch<R>> findErrorRoute​(java.lang.Throwable error, io.micronaut.http.HttpRequest<?> request)
      Match a route to an error.
      java.util.List<io.micronaut.http.filter.HttpFilter> findFilters​(io.micronaut.http.HttpRequest<?> request)
      Build a filtered Publisher for an action.
      <R> java.util.Optional<RouteMatch<R>> findStatusRoute​(io.micronaut.http.HttpStatus status, io.micronaut.http.HttpRequest<?> request)
      Found a RouteMatch for the given HttpStatus code.
      <R> java.util.Optional<RouteMatch<R>> findStatusRoute​(java.lang.Class<?> originatingClass, io.micronaut.http.HttpStatus status, io.micronaut.http.HttpRequest<?> request)
      Found a RouteMatch for the given HttpStatus code.
      java.util.Set<java.lang.Integer> getExposedPorts()  
      java.util.List<io.micronaut.http.filter.HttpFilterResolver.FilterEntry<io.micronaut.http.filter.HttpFilter>> resolveFilterEntries​(RouteMatch<?> routeMatch)  
      java.util.List<io.micronaut.http.filter.HttpFilter> resolveFilters​(io.micronaut.http.HttpRequest<?> request, java.util.List<io.micronaut.http.filter.HttpFilterResolver.FilterEntry<io.micronaut.http.filter.HttpFilter>> filterEntries)  
      <T,​R>
      java.util.Optional<UriRouteMatch<T,​R>>
      route​(io.micronaut.http.HttpMethod httpMethod, java.lang.CharSequence uri)
      Finds the first possible route for the given HTTP method and URI.
      <R> java.util.Optional<RouteMatch<R>> route​(io.micronaut.http.HttpStatus status)
      Found a RouteMatch for the given HttpStatus code.
      <R> java.util.Optional<RouteMatch<R>> route​(java.lang.Class originatingClass, io.micronaut.http.HttpStatus status)
      Found a RouteMatch for the given HttpStatus code.
      <R> java.util.Optional<RouteMatch<R>> route​(java.lang.Class originatingClass, java.lang.Throwable error)
      Match a route to an error.
      <R> java.util.Optional<RouteMatch<R>> route​(java.lang.Throwable error)
      Match a route to an error.
      java.util.stream.Stream<UriRoute> uriRoutes()
      Returns all UriRoutes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultRouter

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

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

      • getExposedPorts

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

        public void applyDefaultPorts​(java.util.List<java.lang.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> java.util.stream.Stream<UriRouteMatch<T,​R>> find​(@NonNull
                                                                                  io.micronaut.http.HttpRequest<?> request,
                                                                                  @NonNull
                                                                                  java.lang.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> java.util.stream.Stream<UriRouteMatch<T,​R>> find​(@NonNull
                                                                                  io.micronaut.http.HttpRequest<?> request)
        Description copied from interface: Router
        Finds all of the 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> java.util.stream.Stream<UriRouteMatch<T,​R>> find​(@NonNull
                                                                                  io.micronaut.http.HttpMethod httpMethod,
                                                                                  @NonNull
                                                                                  java.lang.CharSequence uri,
                                                                                  @Nullable
                                                                                  io.micronaut.http.HttpRequest<?> context)
        Description copied from interface: Router
        Finds all of the 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 java.util.stream.Stream<UriRoute> uriRoutes()
        Description copied from interface: Router
        Returns all UriRoutes.
        Specified by:
        uriRoutes in interface Router
        Returns:
        A Stream of all registered UriRoute instances.
      • findAllClosest

        @NonNull
        public <T,​R> java.util.List<UriRouteMatch<T,​R>> findAllClosest​(@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> java.util.Optional<UriRouteMatch<T,​R>> route​(@NonNull
                                                                              io.micronaut.http.HttpMethod httpMethod,
                                                                              @NonNull
                                                                              java.lang.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> java.util.Optional<RouteMatch<R>> route​(@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> java.util.Optional<RouteMatch<R>> route​(@NonNull
                                                           java.lang.Class originatingClass,
                                                           @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> java.util.Optional<RouteMatch<R>> route​(@NonNull
                                                           java.lang.Class originatingClass,
                                                           @NonNull
                                                           java.lang.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> java.util.Optional<RouteMatch<R>> findErrorRoute​(@NonNull
                                                                    java.lang.Class<?> originatingClass,
                                                                    @NonNull
                                                                    java.lang.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> java.util.Optional<RouteMatch<R>> findErrorRoute​(@NonNull
                                                                    java.lang.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> java.util.Optional<RouteMatch<R>> findStatusRoute​(@NonNull
                                                                     java.lang.Class<?> originatingClass,
                                                                     @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> java.util.Optional<RouteMatch<R>> findStatusRoute​(@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
      • route

        public <R> java.util.Optional<RouteMatch<R>> route​(@NonNull
                                                           java.lang.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 java.util.List<io.micronaut.http.filter.HttpFilter> findFilters​(@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> java.util.stream.Stream<UriRouteMatch<T,​R>> findAny​(@NonNull
                                                                                     java.lang.CharSequence uri,
                                                                                     @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
      • resolveFilterEntries

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

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