Package io.micronaut.web.router
Class DefaultRouter
java.lang.Object
io.micronaut.web.router.DefaultRouter
- All Implemented Interfaces:
HttpFilterResolver<RouteMatch<?>>,HttpServerFilterResolver<RouteMatch<?>>,Router
@Singleton
public class DefaultRouter
extends Object
implements Router, HttpServerFilterResolver<RouteMatch<?>>
The default Router implementation. This implementation does not perform any additional caching of
route discovery.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.micronaut.http.filter.HttpFilterResolver
HttpFilterResolver.FilterEntry -
Constructor Summary
ConstructorsConstructorDescriptionDefaultRouter(RouteBuilder... builders) Construct a new router for the given route builders.DefaultRouter(Collection<RouteBuilder> builders) Construct a new router for the given route builders. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyDefaultPorts(List<Integer> ports) Sets the ports the application will listen to by default.<T,R> @NonNull Stream<UriRouteMatch<T, R>> find(@NonNull HttpMethod httpMethod, @NonNull CharSequence uri, @Nullable HttpRequest<?> context) Finds all possible routes for the given HTTP method and URI.<T,R> @NonNull Stream<UriRouteMatch<T, R>> find(@NonNull HttpRequest<?> request) Finds all possible routes for the given HTTP request.<T,R> @NonNull Stream<UriRouteMatch<T, R>> find(@NonNull HttpRequest<?> request, @NonNull CharSequence uri) Find method, that should be used for non-standard http methods.<T,R> @NonNull List<UriRouteMatch<T, R>> findAllClosest(@NonNull HttpRequest<?> request) Finds the closest match for the given request.<T,R> @NonNull List<UriRouteMatch<T, R>> findAny(@NonNull HttpRequest<?> request) Find anyRouteMatchregardless of HTTP method.<T,R> @NonNull Stream<UriRouteMatch<T, R>> findAny(@NonNull CharSequence uri, @Nullable HttpRequest<?> request) Find anyRouteMatchregardless of HTTP method.<T,R> UriRouteMatch<T, R> findClosest(@NonNull HttpRequest<?> request) Finds the closest match for the given request or null if none is found.<R> Optional<RouteMatch<R>>findErrorRoute(@NonNull Class<?> originatingClass, @NonNull Throwable error, HttpRequest<?> request) Match a route to an error.<R> Optional<RouteMatch<R>>findErrorRoute(@NonNull Throwable error, HttpRequest<?> request) Match a route to an error.findFilters(@NonNull HttpRequest<?> request) Find filters for the request.findFilters(@NonNull HttpRequest<?> request, @Nullable RouteMatch<?> routeMatch) Find filters for the request and a route match.findPreMatchingFilters(@NonNull HttpRequest<?> request) Find pre-matching filters for the request.<R> Optional<RouteMatch<R>>findStatusRoute(int statusCode, HttpRequest<?> request) Found aRouteMatchfor the given status code.<R> Optional<RouteMatch<R>>findStatusRoute(@NonNull HttpStatus status, HttpRequest<?> request) Found aRouteMatchfor the givenHttpStatuscode.<R> Optional<RouteMatch<R>>findStatusRoute(@NonNull Class<?> originatingClass, int statusCode, HttpRequest<?> request) Found aRouteMatchfor the given status code.<R> Optional<RouteMatch<R>>findStatusRoute(@NonNull Class<?> originatingClass, @NonNull HttpStatus status, HttpRequest<?> request) Found aRouteMatchfor the givenHttpStatuscode.resolveFilterEntries(RouteMatch<?> routeMatch) Resolves the initial list of filters.resolveFilters(HttpRequest<?> request, List<HttpFilterResolver.FilterEntry> filterEntries) Returns which filters should apply for the given request.<T,R> @NonNull Optional<UriRouteMatch<T, R>> route(@NonNull HttpMethod httpMethod, @NonNull CharSequence uri) Finds the first possible route for the given HTTP method and URI.<R> Optional<RouteMatch<R>>route(@NonNull HttpStatus status) Found aRouteMatchfor the givenHttpStatuscode.<R> Optional<RouteMatch<R>>route(@NonNull Class<?> originatingClass, @NonNull HttpStatus status) Found aRouteMatchfor the givenHttpStatuscode.<R> Optional<RouteMatch<R>>Match a route to an error.<R> Optional<RouteMatch<R>>Match a route to an error.@NonNull Stream<UriRouteInfo<?,?>> Returns all UriRoutes.
-
Constructor Details
-
DefaultRouter
Construct a new router for the given route builders.- Parameters:
builders- The builders
-
DefaultRouter
Construct a new router for the given route builders.- Parameters:
builders- The builders
-
-
Method Details
-
getExposedPorts
- Specified by:
getExposedPortsin interfaceRouter- Returns:
- The exposed ports.
-
applyDefaultPorts
Description copied from interface:RouterSets the ports the application will listen to by default.- Specified by:
applyDefaultPortsin interfaceRouter- Parameters:
ports- The default ports
-
find
@NonNull public <T,R> @NonNull Stream<UriRouteMatch<T,R>> find(@NonNull @NonNull HttpRequest<?> request, @NonNull @NonNull CharSequence uri) Description copied from interface:RouterFind method, that should be used for non-standard http methods. For standards, it should act the same asRouter.find(HttpMethod, CharSequence, HttpRequest)- Specified by:
findin interfaceRouter- Type Parameters:
T- The target type.R- The type of what- Parameters:
request- The request, that can have overriddenHttpRequest.getMethodName()uri- The URI route match.- Returns:
- A
Streamof possibleRouteinstances.
-
find
@NonNull public <T,R> @NonNull Stream<UriRouteMatch<T,R>> find(@NonNull @NonNull HttpRequest<?> request) Description copied from interface:RouterFinds all possible routes for the given HTTP request. -
find
@NonNull public <T,R> @NonNull Stream<UriRouteMatch<T,R>> find(@NonNull @NonNull HttpMethod httpMethod, @NonNull @NonNull CharSequence uri, @Nullable @Nullable HttpRequest<?> context) Description copied from interface:RouterFinds all possible routes for the given HTTP method and URI.- Specified by:
findin interfaceRouter- Type Parameters:
T- The target typeR- The type- Parameters:
httpMethod- The HTTP methoduri- The URI route matchcontext- The optionalHttpRequestcontext information to applyRouteMatchFilter.- Returns:
- A
Streamof possibleRouteinstances.
-
uriRoutes
Description copied from interface:RouterReturns all UriRoutes. -
findClosest
public <T,R> UriRouteMatch<T,R> findClosest(@NonNull @NonNull HttpRequest<?> request) throws DuplicateRouteException Description copied from interface:RouterFinds the closest match for the given request or null if none is found.- Specified by:
findClosestin interfaceRouter- Type Parameters:
T- The target typeR- The type- Parameters:
request- The request- Returns:
- A match or null, throws
DuplicateRouteExceptionon multiple routes. - Throws:
DuplicateRouteException
-
findAllClosest
@NonNull public <T,R> @NonNull List<UriRouteMatch<T,R>> findAllClosest(@NonNull @NonNull HttpRequest<?> request) Description copied from interface:RouterFinds the closest match for the given request.- Specified by:
findAllClosestin interfaceRouter- Type Parameters:
T- The target typeR- The type- Parameters:
request- The request- Returns:
- A
Listof possibleRouteinstances.
-
route
@NonNull public <T,R> @NonNull Optional<UriRouteMatch<T,R>> route(@NonNull @NonNull HttpMethod httpMethod, @NonNull @NonNull CharSequence uri) Description copied from interface:RouterFinds the first possible route for the given HTTP method and URI. -
route
Description copied from interface:RouterFound aRouteMatchfor the givenHttpStatuscode.- Specified by:
routein interfaceRouter- 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 HttpStatus status) Description copied from interface:RouterFound aRouteMatchfor the givenHttpStatuscode.- Specified by:
routein interfaceRouter- Type Parameters:
R- The matched route- Parameters:
originatingClass- The class the error originates fromstatus- 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:RouterMatch a route to an error.- Specified by:
routein interfaceRouter- Type Parameters:
R- The matched route- Parameters:
originatingClass- The class the error originates fromerror- The error- Returns:
- The
RouteMatch
-
findErrorRoute
public <R> Optional<RouteMatch<R>> findErrorRoute(@NonNull @NonNull Class<?> originatingClass, @NonNull @NonNull Throwable error, HttpRequest<?> request) Description copied from interface:RouterMatch a route to an error.- Specified by:
findErrorRoutein interfaceRouter- Type Parameters:
R- The matched route- Parameters:
originatingClass- The class the error originates fromerror- The errorrequest- The request- Returns:
- The
RouteMatch
-
findErrorRoute
public <R> Optional<RouteMatch<R>> findErrorRoute(@NonNull @NonNull Throwable error, HttpRequest<?> request) Description copied from interface:RouterMatch a route to an error.- Specified by:
findErrorRoutein interfaceRouter- Type Parameters:
R- The matched route- Parameters:
error- The errorrequest- The request- Returns:
- The
RouteMatch
-
findStatusRoute
public <R> Optional<RouteMatch<R>> findStatusRoute(@NonNull @NonNull Class<?> originatingClass, @NonNull @NonNull HttpStatus status, HttpRequest<?> request) Description copied from interface:RouterFound aRouteMatchfor the givenHttpStatuscode.- Specified by:
findStatusRoutein interfaceRouter- Type Parameters:
R- The matched route- Parameters:
originatingClass- The class the error originates fromstatus- The HTTP statusrequest- The request- Returns:
- The
RouteMatch
-
findStatusRoute
public <R> Optional<RouteMatch<R>> findStatusRoute(@NonNull @NonNull HttpStatus status, HttpRequest<?> request) Description copied from interface:RouterFound aRouteMatchfor the givenHttpStatuscode.- Specified by:
findStatusRoutein interfaceRouter- Type Parameters:
R- The matched route- Parameters:
status- The HTTP statusrequest- The request- Returns:
- The
RouteMatch
-
findStatusRoute
public <R> Optional<RouteMatch<R>> findStatusRoute(@NonNull @NonNull Class<?> originatingClass, int statusCode, HttpRequest<?> request) Description copied from interface:RouterFound aRouteMatchfor the given status code.- Specified by:
findStatusRoutein interfaceRouter- Type Parameters:
R- The matched route- Parameters:
originatingClass- The class the error originates fromstatusCode- The HTTP statusrequest- The request- Returns:
- The
RouteMatch
-
findStatusRoute
Description copied from interface:RouterFound aRouteMatchfor the given status code.- Specified by:
findStatusRoutein interfaceRouter- Type Parameters:
R- The matched route- Parameters:
statusCode- The HTTP status coderequest- The request- Returns:
- The
RouteMatch
-
route
Description copied from interface:RouterMatch a route to an error.- Specified by:
routein interfaceRouter- Type Parameters:
R- The matched route- Parameters:
error- The error- Returns:
- The
RouteMatch
-
findFilters
@NonNull public @NonNull List<GenericHttpFilter> findFilters(@NonNull @NonNull HttpRequest<?> request) Description copied from interface:RouterFind filters for the request.- Specified by:
findFiltersin interfaceRouter- Parameters:
request- The request- Returns:
- filters
-
findFilters
@NonNull public @NonNull List<GenericHttpFilter> findFilters(@NonNull @NonNull HttpRequest<?> request, @Nullable @Nullable RouteMatch<?> routeMatch) Description copied from interface:RouterFind filters for the request and a route match.- Specified by:
findFiltersin interfaceRouter- Parameters:
request- The requestrouteMatch- The route match- Returns:
- filters
-
findPreMatchingFilters
@NonNull public @NonNull List<GenericHttpFilter> findPreMatchingFilters(@NonNull @NonNull HttpRequest<?> request) Description copied from interface:RouterFind pre-matching filters for the request.- Specified by:
findPreMatchingFiltersin interfaceRouter- Parameters:
request- The request- Returns:
- filters
-
findAny
@NonNull public <T,R> @NonNull Stream<UriRouteMatch<T,R>> findAny(@NonNull @NonNull CharSequence uri, @Nullable @Nullable HttpRequest<?> request) Description copied from interface:RouterFind anyRouteMatchregardless of HTTP method.- Specified by:
findAnyin interfaceRouter- Type Parameters:
T- The target typeR- The return type- Parameters:
uri- The URIrequest- The optionalHttpRequestcontext information to applyRouteMatchFilter.- Returns:
- A stream of route matches
-
findAny
@NonNull public <T,R> @NonNull List<UriRouteMatch<T,R>> findAny(@NonNull @NonNull HttpRequest<?> request) Description copied from interface:RouterFind anyRouteMatchregardless of HTTP method. -
resolveFilterEntries
Description copied from interface:HttpFilterResolverResolves the initial list of filters.- Specified by:
resolveFilterEntriesin interfaceHttpFilterResolver<RouteMatch<?>>- Parameters:
routeMatch- The context- Returns:
- The filters
-
resolveFilters
public List<GenericHttpFilter> resolveFilters(HttpRequest<?> request, List<HttpFilterResolver.FilterEntry> filterEntries) Description copied from interface:HttpFilterResolverReturns which filters should apply for the given request.- Specified by:
resolveFiltersin interfaceHttpFilterResolver<RouteMatch<?>>- Parameters:
request- The requestfilterEntries- the filter entries- Returns:
- The list of filters
-