Package io.micronaut.web.router.filter
Class FilteredRouter
- java.lang.Object
-
- io.micronaut.web.router.filter.FilteredRouter
-
- All Implemented Interfaces:
Router
public class FilteredRouter extends java.lang.Object implements Router
Allows decorating an existingRouterwith filtering capabilities.Filters themselves should be supplied via the
RouteMatchFilterinterface.A filtered router can be enabled by implementing a
BeanCreatedEventListenerfor the existingRouterand decorating appropriately. See for exampleVersionAwareRouterListener- Since:
- 1.1.0
- See Also:
RouteMatchFilter
-
-
Constructor Summary
Constructors Constructor Description FilteredRouter(Router router, RouteMatchFilter routeFilter)Creates a decorated router for an existing router andRouteMatchFilter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplyDefaultPorts(java.util.List<java.lang.Integer> ports)Sets the ports the application will listen to by default.<T,R>
java.util.Optional<UriRouteMatch<T,R>>DELETE(java.lang.CharSequence uri)Find the firstRouteMatchroute for anHttpMethod.DELETEmethod and the given URI.<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 anyRouteMatchregardless 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 filteredPublisherfor an action.<R> java.util.Optional<RouteMatch<R>>findStatusRoute(io.micronaut.http.HttpStatus status, io.micronaut.http.HttpRequest<?> request)Found aRouteMatchfor the givenHttpStatuscode.<R> java.util.Optional<RouteMatch<R>>findStatusRoute(java.lang.Class<?> originatingClass, io.micronaut.http.HttpStatus status, io.micronaut.http.HttpRequest<?> request)Found aRouteMatchfor the givenHttpStatuscode.<T,R>
java.util.Optional<UriRouteMatch<T,R>>GET(java.lang.CharSequence uri)Find the firstRouteMatchroute for anHttpMethod.GETmethod and the given URI.java.util.Set<java.lang.Integer>getExposedPorts()<T,R>
java.util.Optional<UriRouteMatch<T,R>>HEAD(java.lang.CharSequence uri)Find the firstRouteMatchroute for anHttpMethod.HEADmethod and the given URI.<T,R>
java.util.Optional<UriRouteMatch<T,R>>OPTIONS(java.lang.CharSequence uri)Find the firstRouteMatchroute for anHttpMethod.OPTIONSmethod and the given URI.<T,R>
java.util.Optional<UriRouteMatch<T,R>>PATCH(java.lang.CharSequence uri)Find the firstRouteMatchroute for anHttpMethod.PATCHmethod and the given URI.<T,R>
java.util.Optional<UriRouteMatch<T,R>>POST(java.lang.CharSequence uri)Find the firstRouteMatchroute for anHttpMethod.POSTmethod and the given URI.<T,R>
java.util.Optional<UriRouteMatch<T,R>>PUT(java.lang.CharSequence uri)Find the firstRouteMatchroute for anHttpMethod.PUTmethod and the given URI.<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 aRouteMatchfor the givenHttpStatuscode.<R> java.util.Optional<RouteMatch<R>>route(java.lang.Class originatingClass, io.micronaut.http.HttpStatus status)Found aRouteMatchfor the givenHttpStatuscode.<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.
-
-
-
Constructor Detail
-
FilteredRouter
public FilteredRouter(Router router, RouteMatchFilter routeFilter)
Creates a decorated router for an existing router andRouteMatchFilter.- Parameters:
router- ARouterto delegate torouteFilter- ARouteMatchFilterto filter non matching routes
-
-
Method Detail
-
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:RouterFind anyRouteMatchregardless of HTTP method.- Specified by:
findAnyin interfaceRouter- Type Parameters:
T- The target typeR- The return type- Parameters:
uri- The URIcontext- The optionalHttpRequestcontext information to applyRouteMatchFilter.- Returns:
- A stream of route matches
-
getExposedPorts
public java.util.Set<java.lang.Integer> getExposedPorts()
- Specified by:
getExposedPortsin interfaceRouter- Returns:
- The exposed ports.
-
applyDefaultPorts
public void applyDefaultPorts(java.util.List<java.lang.Integer> ports)
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> 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:RouterFinds all of the 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.
-
findAllClosest
@NonNull public <T,R> java.util.List<UriRouteMatch<T,R>> findAllClosest(@NonNull io.micronaut.http.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.
-
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:RouterFind method, that should be used for non-standard http methods. For standards it should act the same asRouter.find(HttpMethod, CharSequence, HttpRequest)
-
uriRoutes
@NonNull public java.util.stream.Stream<UriRoute> uriRoutes()
Description copied from interface:RouterReturns all UriRoutes.
-
route
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:RouterFinds the first possible route for the given HTTP method and URI.
-
route
public <R> java.util.Optional<RouteMatch<R>> route(@NonNull io.micronaut.http.HttpStatus status)
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> java.util.Optional<RouteMatch<R>> route(@NonNull java.lang.Class originatingClass, @NonNull io.micronaut.http.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> java.util.Optional<RouteMatch<R>> route(@NonNull java.lang.Throwable error)
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
-
route
public <R> java.util.Optional<RouteMatch<R>> route(@NonNull java.lang.Class originatingClass, @NonNull java.lang.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> 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: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> java.util.Optional<RouteMatch<R>> findErrorRoute(@NonNull java.lang.Throwable error, io.micronaut.http.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> 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: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> java.util.Optional<RouteMatch<R>> findStatusRoute(@NonNull io.micronaut.http.HttpStatus status, io.micronaut.http.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
-
findFilters
@NonNull public java.util.List<io.micronaut.http.filter.HttpFilter> findFilters(@NonNull io.micronaut.http.HttpRequest<?> request)Description copied from interface:RouterBuild a filteredPublisherfor an action.- Specified by:
findFiltersin interfaceRouter- Parameters:
request- The request- Returns:
- A new filtered publisher
-
GET
public <T,R> java.util.Optional<UriRouteMatch<T,R>> GET(@NonNull java.lang.CharSequence uri)
Description copied from interface:RouterFind the firstRouteMatchroute for anHttpMethod.GETmethod and the given URI.- Specified by:
GETin interfaceRouter- Type Parameters:
T- The target typeR- The return type- Parameters:
uri- The URI- Returns:
- An
OptionalofRouteMatch
-
POST
public <T,R> java.util.Optional<UriRouteMatch<T,R>> POST(@NonNull java.lang.CharSequence uri)
Description copied from interface:RouterFind the firstRouteMatchroute for anHttpMethod.POSTmethod and the given URI.- Specified by:
POSTin interfaceRouter- Type Parameters:
T- The target typeR- The return type- Parameters:
uri- The URI- Returns:
- An
OptionalofRouteMatch
-
PUT
public <T,R> java.util.Optional<UriRouteMatch<T,R>> PUT(@NonNull java.lang.CharSequence uri)
Description copied from interface:RouterFind the firstRouteMatchroute for anHttpMethod.PUTmethod and the given URI.- Specified by:
PUTin interfaceRouter- Type Parameters:
T- The target typeR- The URI route match- Parameters:
uri- The URI- Returns:
- An
OptionalofRouteMatch
-
PATCH
public <T,R> java.util.Optional<UriRouteMatch<T,R>> PATCH(@NonNull java.lang.CharSequence uri)
Description copied from interface:RouterFind the firstRouteMatchroute for anHttpMethod.PATCHmethod and the given URI.- Specified by:
PATCHin interfaceRouter- Type Parameters:
T- The target typeR- The return type- Parameters:
uri- The URI- Returns:
- An
OptionalofRouteMatch
-
DELETE
public <T,R> java.util.Optional<UriRouteMatch<T,R>> DELETE(@NonNull java.lang.CharSequence uri)
Description copied from interface:RouterFind the firstRouteMatchroute for anHttpMethod.DELETEmethod and the given URI.- Specified by:
DELETEin interfaceRouter- Type Parameters:
T- The target typeR- The return type- Parameters:
uri- The URI- Returns:
- An
OptionalofRouteMatch
-
OPTIONS
public <T,R> java.util.Optional<UriRouteMatch<T,R>> OPTIONS(@NonNull java.lang.CharSequence uri)
Description copied from interface:RouterFind the firstRouteMatchroute for anHttpMethod.OPTIONSmethod and the given URI.- Specified by:
OPTIONSin interfaceRouter- Type Parameters:
T- The target typeR- The return type- Parameters:
uri- The URI- Returns:
- An
OptionalofRouteMatch
-
HEAD
public <T,R> java.util.Optional<UriRouteMatch<T,R>> HEAD(@NonNull java.lang.CharSequence uri)
Description copied from interface:RouterFind the firstRouteMatchroute for anHttpMethod.HEADmethod and the given URI.- Specified by:
HEADin interfaceRouter- Type Parameters:
T- The target typeR- The return type- Parameters:
uri- The URI- Returns:
- An
OptionalofRouteMatch
-
find
@NonNull public <T,R> java.util.stream.Stream<UriRouteMatch<T,R>> find(@NonNull io.micronaut.http.HttpRequest<?> request)
Description copied from interface:RouterFinds all of the possible routes for the given HTTP request.
-
-