@Singleton public class DefaultRouter extends java.lang.Object implements Router, HttpServerFilterResolver<RouteMatch<?>>
The default Router
implementation. This implementation does not perform any additional caching of
route discovery.
HttpFilterResolver.FilterEntry<F>
Constructor and Description |
---|
DefaultRouter(java.util.Collection<RouteBuilder> builders)
Construct a new router for the given route builders.
|
DefaultRouter(RouteBuilder... builders)
Construct a new router for the given route builders.
|
Modifier and Type | Method and 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(HttpMethod httpMethod,
java.lang.CharSequence uri,
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(HttpRequest<?> request)
Finds all of the possible routes for the given HTTP request.
|
<T,R> java.util.stream.Stream<UriRouteMatch<T,R>> |
find(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(HttpRequest<?> request)
Finds the closest match for the given request.
|
<T,R> java.util.stream.Stream<UriRouteMatch<T,R>> |
findAny(java.lang.CharSequence uri,
HttpRequest<?> context)
Find any
RouteMatch regardless of HTTP method. |
<R> java.util.Optional<RouteMatch<R>> |
findErrorRoute(java.lang.Class<?> originatingClass,
java.lang.Throwable error,
HttpRequest<?> request)
Match a route to an error.
|
<R> java.util.Optional<RouteMatch<R>> |
findErrorRoute(java.lang.Throwable error,
HttpRequest<?> request)
Match a route to an error.
|
java.util.List<HttpFilter> |
findFilters(HttpRequest<?> request)
Build a filtered
Publisher for an action. |
<R> java.util.Optional<RouteMatch<R>> |
findStatusRoute(java.lang.Class<?> originatingClass,
HttpStatus status,
HttpRequest<?> request)
Found a
RouteMatch for the given HttpStatus code. |
<R> java.util.Optional<RouteMatch<R>> |
findStatusRoute(HttpStatus status,
HttpRequest<?> request)
Found a
RouteMatch for the given HttpStatus code. |
java.util.Set<java.lang.Integer> |
getExposedPorts() |
java.util.List<HttpFilterResolver.FilterEntry<HttpFilter>> |
resolveFilterEntries(RouteMatch<?> context)
Resolves the initial list of filters.
|
java.util.List<HttpFilter> |
resolveFilters(HttpRequest<?> request,
java.util.List<HttpFilterResolver.FilterEntry<HttpFilter>> filterEntries)
Returns which filters should apply for the given request.
|
<R> java.util.Optional<RouteMatch<R>> |
route(java.lang.Class originatingClass,
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.
|
<T,R> java.util.Optional<UriRouteMatch<T,R>> |
route(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(HttpStatus status)
Found a
RouteMatch for the given HttpStatus code. |
<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.
|
@Inject public DefaultRouter(java.util.Collection<RouteBuilder> builders)
builders
- The builderspublic DefaultRouter(RouteBuilder... builders)
builders
- The builderspublic java.util.Set<java.lang.Integer> getExposedPorts()
getExposedPorts
in interface Router
public void applyDefaultPorts(java.util.List<java.lang.Integer> ports)
Router
applyDefaultPorts
in interface Router
ports
- The default ports@NonNull public <T,R> java.util.stream.Stream<UriRouteMatch<T,R>> find(@NonNull HttpRequest<?> request, @NonNull java.lang.CharSequence uri)
Router
Router.find(HttpMethod, CharSequence, HttpRequest)
find
in interface Router
T
- The target type.R
- The type of whatrequest
- The request, that can have overridden HttpRequest.getMethodName()
uri
- The URI route match.Stream
of possible Route
instances.@NonNull public <T,R> java.util.stream.Stream<UriRouteMatch<T,R>> find(@NonNull HttpRequest<?> request)
Router
@NonNull public <T,R> java.util.stream.Stream<UriRouteMatch<T,R>> find(@NonNull HttpMethod httpMethod, @NonNull java.lang.CharSequence uri, @Nullable HttpRequest<?> context)
Router
find
in interface Router
T
- The target typeR
- The typehttpMethod
- The HTTP methoduri
- The URI route matchcontext
- The optional HttpRequest
context information to apply RouteMatchFilter
.Stream
of possible Route
instances.@NonNull public java.util.stream.Stream<UriRoute> uriRoutes()
Router
@NonNull public <T,R> java.util.List<UriRouteMatch<T,R>> findAllClosest(@NonNull HttpRequest<?> request)
Router
findAllClosest
in interface Router
T
- The target typeR
- The typerequest
- The requestList
of possible Route
instances.@NonNull public <T,R> java.util.Optional<UriRouteMatch<T,R>> route(@NonNull HttpMethod httpMethod, @NonNull java.lang.CharSequence uri)
Router
public <R> java.util.Optional<RouteMatch<R>> route(@NonNull HttpStatus status)
Router
RouteMatch
for the given HttpStatus
code.route
in interface Router
R
- The matched routestatus
- The HTTP statusRouteMatch
public <R> java.util.Optional<RouteMatch<R>> route(@NonNull java.lang.Class originatingClass, @NonNull HttpStatus status)
Router
RouteMatch
for the given HttpStatus
code.route
in interface Router
R
- The matched routeoriginatingClass
- The class the error originates fromstatus
- The HTTP statusRouteMatch
public <R> java.util.Optional<RouteMatch<R>> route(@NonNull java.lang.Class originatingClass, @NonNull java.lang.Throwable error)
Router
route
in interface Router
R
- The matched routeoriginatingClass
- The class the error originates fromerror
- The errorRouteMatch
public <R> java.util.Optional<RouteMatch<R>> findErrorRoute(@NonNull java.lang.Class<?> originatingClass, @NonNull java.lang.Throwable error, HttpRequest<?> request)
Router
findErrorRoute
in interface Router
R
- The matched routeoriginatingClass
- The class the error originates fromerror
- The errorrequest
- The requestRouteMatch
public <R> java.util.Optional<RouteMatch<R>> findErrorRoute(@NonNull java.lang.Throwable error, HttpRequest<?> request)
Router
findErrorRoute
in interface Router
R
- The matched routeerror
- The errorrequest
- The requestRouteMatch
public <R> java.util.Optional<RouteMatch<R>> findStatusRoute(@NonNull java.lang.Class<?> originatingClass, @NonNull HttpStatus status, HttpRequest<?> request)
Router
RouteMatch
for the given HttpStatus
code.findStatusRoute
in interface Router
R
- The matched routeoriginatingClass
- The class the error originates fromstatus
- The HTTP statusrequest
- The requestRouteMatch
public <R> java.util.Optional<RouteMatch<R>> findStatusRoute(@NonNull HttpStatus status, HttpRequest<?> request)
Router
RouteMatch
for the given HttpStatus
code.findStatusRoute
in interface Router
R
- The matched routestatus
- The HTTP statusrequest
- The requestRouteMatch
public <R> java.util.Optional<RouteMatch<R>> route(@NonNull java.lang.Throwable error)
Router
route
in interface Router
R
- The matched routeerror
- The errorRouteMatch
@NonNull public java.util.List<HttpFilter> findFilters(@NonNull HttpRequest<?> request)
Router
Publisher
for an action.findFilters
in interface Router
request
- The request@NonNull public <T,R> java.util.stream.Stream<UriRouteMatch<T,R>> findAny(@NonNull java.lang.CharSequence uri, @Nullable HttpRequest<?> context)
Router
RouteMatch
regardless of HTTP method.findAny
in interface Router
T
- The target typeR
- The return typeuri
- The URIcontext
- The optional HttpRequest
context information to apply RouteMatchFilter
.public java.util.List<HttpFilterResolver.FilterEntry<HttpFilter>> resolveFilterEntries(RouteMatch<?> context)
HttpFilterResolver
resolveFilterEntries
in interface HttpFilterResolver<HttpFilter,RouteMatch<?>>
context
- The contextpublic java.util.List<HttpFilter> resolveFilters(HttpRequest<?> request, java.util.List<HttpFilterResolver.FilterEntry<HttpFilter>> filterEntries)
HttpFilterResolver
resolveFilters
in interface HttpFilterResolver<HttpFilter,RouteMatch<?>>
request
- The requestfilterEntries
- the filter entries