Package io.micronaut.web.router.filter
Class FilteredRouter
java.lang.Object
io.micronaut.web.router.filter.FilteredRouter
- All Implemented Interfaces:
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
- Author:
- Bogdan Oros, graemerocher
- See Also:
-
Constructor Summary
ConstructorDescriptionFilteredRouter
(Router router, RouteMatchFilter routeFilter) Creates a decorated router for an existing router andRouteMatchFilter
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
applyDefaultPorts
(List<Integer> ports) Sets the ports the application will listen to by default.<T,
R> Optional<UriRouteMatch<T, R>> DELETE
(@NonNull CharSequence uri) Find the firstRouteMatch
route for anHttpMethod.DELETE
method and the given URI.<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 anyRouteMatch
regardless of HTTP method.<T,
R> @NonNull Stream<UriRouteMatch<T, R>> findAny
(@NonNull CharSequence uri, @Nullable HttpRequest<?> context) Find anyRouteMatch
regardless of HTTP method.<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
(HttpRequest<?> request, RouteMatch<?> routeMatch) Find filters for the request and a route match.findPreMatchingFilters
(HttpRequest<?> request) Find pre-matching filters for the request.<R> Optional<RouteMatch<R>>
findStatusRoute
(int statusCode, HttpRequest<?> request) Found aRouteMatch
for the given status code.<R> Optional<RouteMatch<R>>
findStatusRoute
(@NonNull HttpStatus status, HttpRequest<?> request) Found aRouteMatch
for the givenHttpStatus
code.<R> Optional<RouteMatch<R>>
findStatusRoute
(@NonNull Class<?> originatingClass, int statusCode, HttpRequest<?> request) Found aRouteMatch
for the given status code.<R> Optional<RouteMatch<R>>
findStatusRoute
(@NonNull Class<?> originatingClass, @NonNull HttpStatus status, HttpRequest<?> request) Found aRouteMatch
for the givenHttpStatus
code.<T,
R> Optional<UriRouteMatch<T, R>> GET
(@NonNull CharSequence uri) Find the firstRouteMatch
route for anHttpMethod.GET
method and the given URI.<T,
R> Optional<UriRouteMatch<T, R>> HEAD
(@NonNull CharSequence uri) Find the firstRouteMatch
route for anHttpMethod.HEAD
method and the given URI.<T,
R> Optional<UriRouteMatch<T, R>> OPTIONS
(@NonNull CharSequence uri) Find the firstRouteMatch
route for anHttpMethod.OPTIONS
method and the given URI.<T,
R> Optional<UriRouteMatch<T, R>> PATCH
(@NonNull CharSequence uri) Find the firstRouteMatch
route for anHttpMethod.PATCH
method and the given URI.<T,
R> Optional<UriRouteMatch<T, R>> POST
(@NonNull CharSequence uri) Find the firstRouteMatch
route for anHttpMethod.POST
method and the given URI.<T,
R> Optional<UriRouteMatch<T, R>> PUT
(@NonNull CharSequence uri) Find the firstRouteMatch
route for anHttpMethod.PUT
method and the given URI.<T,
R> 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 aRouteMatch
for the givenHttpStatus
code.<R> Optional<RouteMatch<R>>
route
(@NonNull Class<?> originatingClass, @NonNull HttpStatus status) Found aRouteMatch
for the givenHttpStatus
code.<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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.web.router.Router
find, findClosest
-
Constructor Details
-
FilteredRouter
Creates a decorated router for an existing router andRouteMatchFilter
.- Parameters:
router
- ARouter
to delegate torouteFilter
- ARouteMatchFilter
to filter non-matching routes
-
-
Method Details
-
findAny
@NonNull public <T,R> @NonNull Stream<UriRouteMatch<T,R>> findAny(@NonNull @NonNull CharSequence uri, @Nullable @Nullable HttpRequest<?> context) Description copied from interface:Router
Find anyRouteMatch
regardless of HTTP method.- Specified by:
findAny
in interfaceRouter
- Type Parameters:
T
- The target typeR
- The return type- Parameters:
uri
- The URIcontext
- The optionalHttpRequest
context 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:Router
Find anyRouteMatch
regardless of HTTP method. -
getExposedPorts
- Specified by:
getExposedPorts
in interfaceRouter
- Returns:
- The exposed ports.
-
applyDefaultPorts
Description copied from interface:Router
Sets the ports the application will listen to by default.- Specified by:
applyDefaultPorts
in interfaceRouter
- Parameters:
ports
- The default ports
-
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:Router
Finds all possible routes for the given HTTP method and URI.- Specified by:
find
in interfaceRouter
- Type Parameters:
T
- The target typeR
- The type- Parameters:
httpMethod
- The HTTP methoduri
- The URI route matchcontext
- The optionalHttpRequest
context information to applyRouteMatchFilter
.- Returns:
- A
Stream
of possibleRoute
instances.
-
findAllClosest
@NonNull public <T,R> @NonNull List<UriRouteMatch<T,R>> findAllClosest(@NonNull @NonNull HttpRequest<?> request) Description copied from interface:Router
Finds the closest match for the given request.- Specified by:
findAllClosest
in interfaceRouter
- Type Parameters:
T
- The target typeR
- The type- Parameters:
request
- The request- Returns:
- A
List
of possibleRoute
instances.
-
find
@NonNull public <T,R> @NonNull Stream<UriRouteMatch<T,R>> find(@NonNull @NonNull 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 asRouter.find(HttpMethod, CharSequence, HttpRequest)
- Specified by:
find
in 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
Stream
of possibleRoute
instances.
-
uriRoutes
Description copied from interface:Router
Returns all UriRoutes. -
route
public <T,R> Optional<UriRouteMatch<T,R>> route(@NonNull @NonNull HttpMethod httpMethod, @NonNull @NonNull CharSequence uri) Description copied from interface:Router
Finds the first possible route for the given HTTP method and URI. -
route
Description copied from interface:Router
Found aRouteMatch
for the givenHttpStatus
code.- Specified by:
route
in 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:Router
Found aRouteMatch
for the givenHttpStatus
code.- Specified by:
route
in interfaceRouter
- Type Parameters:
R
- The matched route- Parameters:
originatingClass
- The class the error originates fromstatus
- The HTTP status- Returns:
- The
RouteMatch
-
route
Description copied from interface:Router
Match a route to an error.- Specified by:
route
in interfaceRouter
- 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 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:Router
Match a route to an error.- Specified by:
findErrorRoute
in 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:Router
Match a route to an error.- Specified by:
findErrorRoute
in 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:Router
Found aRouteMatch
for the givenHttpStatus
code.- Specified by:
findStatusRoute
in 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 Class<?> originatingClass, int statusCode, HttpRequest<?> request) Description copied from interface:Router
Found aRouteMatch
for the given status code.- Specified by:
findStatusRoute
in interfaceRouter
- Type Parameters:
R
- The matched route- Parameters:
originatingClass
- The class the error originates fromstatusCode
- 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:Router
Found aRouteMatch
for the givenHttpStatus
code.- Specified by:
findStatusRoute
in interfaceRouter
- Type Parameters:
R
- The matched route- Parameters:
status
- The HTTP statusrequest
- The request- Returns:
- The
RouteMatch
-
findStatusRoute
Description copied from interface:Router
Found aRouteMatch
for the given status code.- Specified by:
findStatusRoute
in interfaceRouter
- Type Parameters:
R
- The matched route- Parameters:
statusCode
- The HTTP status coderequest
- The request- Returns:
- The
RouteMatch
-
findFilters
@NonNull public @NonNull List<GenericHttpFilter> findFilters(@NonNull @NonNull HttpRequest<?> request) Description copied from interface:Router
Find filters for the request.- Specified by:
findFilters
in interfaceRouter
- Parameters:
request
- The request- Returns:
- filters
-
findFilters
Description copied from interface:Router
Find filters for the request and a route match.- Specified by:
findFilters
in interfaceRouter
- Parameters:
request
- The requestrouteMatch
- The route match- Returns:
- filters
-
findPreMatchingFilters
Description copied from interface:Router
Find pre-matching filters for the request.- Specified by:
findPreMatchingFilters
in interfaceRouter
- Parameters:
request
- The request- Returns:
- filters
-
GET
Description copied from interface:Router
Find the firstRouteMatch
route for anHttpMethod.GET
method and the given URI.- Specified by:
GET
in interfaceRouter
- Type Parameters:
T
- The target typeR
- The return type- Parameters:
uri
- The URI- Returns:
- An
Optional
ofRouteMatch
-
POST
Description copied from interface:Router
Find the firstRouteMatch
route for anHttpMethod.POST
method and the given URI.- Specified by:
POST
in interfaceRouter
- Type Parameters:
T
- The target typeR
- The return type- Parameters:
uri
- The URI- Returns:
- An
Optional
ofRouteMatch
-
PUT
Description copied from interface:Router
Find the firstRouteMatch
route for anHttpMethod.PUT
method and the given URI.- Specified by:
PUT
in interfaceRouter
- Type Parameters:
T
- The target typeR
- The URI route match- Parameters:
uri
- The URI- Returns:
- An
Optional
ofRouteMatch
-
PATCH
Description copied from interface:Router
Find the firstRouteMatch
route for anHttpMethod.PATCH
method and the given URI.- Specified by:
PATCH
in interfaceRouter
- Type Parameters:
T
- The target typeR
- The return type- Parameters:
uri
- The URI- Returns:
- An
Optional
ofRouteMatch
-
DELETE
Description copied from interface:Router
Find the firstRouteMatch
route for anHttpMethod.DELETE
method and the given URI.- Specified by:
DELETE
in interfaceRouter
- Type Parameters:
T
- The target typeR
- The return type- Parameters:
uri
- The URI- Returns:
- An
Optional
ofRouteMatch
-
OPTIONS
Description copied from interface:Router
Find the firstRouteMatch
route for anHttpMethod.OPTIONS
method and the given URI.- Specified by:
OPTIONS
in interfaceRouter
- Type Parameters:
T
- The target typeR
- The return type- Parameters:
uri
- The URI- Returns:
- An
Optional
ofRouteMatch
-
HEAD
Description copied from interface:Router
Find the firstRouteMatch
route for anHttpMethod.HEAD
method and the given URI.- Specified by:
HEAD
in interfaceRouter
- Type Parameters:
T
- The target typeR
- The return type- Parameters:
uri
- The URI- Returns:
- An
Optional
ofRouteMatch
-
find
@NonNull public <T,R> @NonNull Stream<UriRouteMatch<T,R>> find(@NonNull @NonNull HttpRequest<?> request) Description copied from interface:Router
Finds all possible routes for the given HTTP request.
-