public final class HttpPredicateRouterBuilder extends java.lang.Object implements RouteStarter
StreamingHttpService
which routes requests to a number of other StreamingHttpService
s based
on user specified criteria.
eg.
final StreamingHttpService<HttpChunk, HttpChunk> router = new HttpPredicateRouterBuilder<HttpChunk, HttpChunk>()
.whenMethod(GET).andPathStartsWith("/a/").thenRouteTo(serviceA)
.whenMethod(GET).andPathStartsWith("/b/").thenRouteTo(serviceB)
.whenMethod(POST).thenRouteTo(serviceC)
.buildStreaming();
If no routes match, a default service is used, which returns a 404 response.
Constructor and Description |
---|
HttpPredicateRouterBuilder() |
Modifier and Type | Method and Description |
---|---|
StreamingHttpService |
buildStreaming()
Builds the
StreamingHttpService that performs the configured routing. |
RouteContinuation |
when(java.util.function.BiPredicate<ConnectionContext,StreamingHttpRequest> predicate)
Begin a route that matches
StreamingHttpRequest and ConnectionContext with a user-specified
predicate . |
RouteContinuation |
when(java.util.function.Predicate<StreamingHttpRequest> predicate)
Begin a route that matches
StreamingHttpRequest s with a user-specified predicate . |
CookieMatcher |
whenCookie(java.lang.String name)
|
StringMultiValueMatcher |
whenHeader(java.lang.CharSequence name)
Begin a route with a
StringMultiValueMatcher that matches against the value(s) of the
name headers. |
RouteContinuation |
whenIsNotSsl()
Begin a route that matches requests that are not over SSL/TLS.
|
RouteContinuation |
whenIsSsl()
Begin a route that matches requests that are over SSL/TLS.
|
RouteContinuation |
whenMethod(HttpRequestMethod method)
Begin a route that matches requests where the
HttpRequestMethod is method . |
RouteContinuation |
whenMethodIsOneOf(HttpRequestMethod... methods)
Begin a route that matches requests where the
HttpRequestMethod is one of the methods . |
RouteContinuation |
whenPathEquals(java.lang.String path)
Begin a route that matches requests where the path is equal to
path . |
RouteContinuation |
whenPathIsOneOf(java.lang.String... paths)
Begin a route that matches requests where the path is equal to any of the specified
path s. |
RouteContinuation |
whenPathMatches(java.util.regex.Pattern pathRegex)
Begin a route that matches requests where the path matches the regex
pathRegex . |
RouteContinuation |
whenPathMatches(java.lang.String pathRegex)
Begin a route that matches requests where the path matches the regex
pathRegex . |
RouteContinuation |
whenPathStartsWith(java.lang.String pathPrefix)
Begin a route that matches requests where the path starts with
pathPrefix . |
StringMultiValueMatcher |
whenQueryParam(java.lang.String name)
Begin a route with a
StringMultiValueMatcher that matches against the value(s) of the request
parameter name . |
public RouteContinuation whenMethod(HttpRequestMethod method)
RouteStarter
HttpRequestMethod
is method
.whenMethod
in interface RouteStarter
method
- the method to match.RouteContinuation
for the next steps of building a route.public RouteContinuation whenMethodIsOneOf(HttpRequestMethod... methods)
RouteStarter
HttpRequestMethod
is one of the methods
.whenMethodIsOneOf
in interface RouteStarter
methods
- the methods to match.RouteContinuation
for the next steps of building a route.public RouteContinuation whenPathEquals(java.lang.String path)
RouteStarter
path
.whenPathEquals
in interface RouteStarter
path
- the path to match.RouteContinuation
for the next steps of building a route.public RouteContinuation whenPathIsOneOf(java.lang.String... paths)
RouteStarter
path
s.whenPathIsOneOf
in interface RouteStarter
paths
- the paths to match.RouteContinuation
for the next steps of building a route.public RouteContinuation whenPathStartsWith(java.lang.String pathPrefix)
RouteStarter
pathPrefix
.whenPathStartsWith
in interface RouteStarter
pathPrefix
- the path prefix to match.RouteContinuation
for the next steps of building a route.public RouteContinuation whenPathMatches(java.lang.String pathRegex)
RouteStarter
pathRegex
.whenPathMatches
in interface RouteStarter
pathRegex
- the regex to match against the request path.RouteContinuation
for the next steps of building a route.public RouteContinuation whenPathMatches(java.util.regex.Pattern pathRegex)
RouteStarter
pathRegex
.whenPathMatches
in interface RouteStarter
pathRegex
- the regex to match against the request path.RouteContinuation
for the next steps of building a route.public StringMultiValueMatcher whenQueryParam(java.lang.String name)
RouteStarter
StringMultiValueMatcher
that matches against the value(s) of the request
parameter name
.whenQueryParam
in interface RouteStarter
name
- the request parameter name that must be present in the request in order to continue evaluation of
this route.StringMultiValueMatcher
for the next steps of building a route.public StringMultiValueMatcher whenHeader(java.lang.CharSequence name)
RouteStarter
StringMultiValueMatcher
that matches against the value(s) of the
name
headers.whenHeader
in interface RouteStarter
name
- The header name that must be present in the request in order to continue evaluation of this route.StringMultiValueMatcher
for the next steps of building a route.public CookieMatcher whenCookie(java.lang.String name)
RouteStarter
whenCookie
in interface RouteStarter
name
- the cookie name that must be present in the request in order to continue evaluation of this route.CookieMatcher
for the next steps of building a route.public RouteContinuation whenIsSsl()
RouteStarter
whenIsSsl
in interface RouteStarter
RouteContinuation
for the next steps of building a route.public RouteContinuation whenIsNotSsl()
RouteStarter
whenIsNotSsl
in interface RouteStarter
RouteContinuation
for the next steps of building a route.public RouteContinuation when(java.util.function.Predicate<StreamingHttpRequest> predicate)
RouteStarter
StreamingHttpRequest
s with a user-specified predicate
.when
in interface RouteStarter
predicate
- the predicate to evaluate against requests.RouteContinuation
for the next steps of building a route.public RouteContinuation when(java.util.function.BiPredicate<ConnectionContext,StreamingHttpRequest> predicate)
RouteStarter
StreamingHttpRequest
and ConnectionContext
with a user-specified
predicate
.when
in interface RouteStarter
predicate
- the predicate to evaluate against the request and connection context.RouteContinuation
for the next steps of building a route.public StreamingHttpService buildStreaming()
RouteStarter
StreamingHttpService
that performs the configured routing.buildStreaming
in interface RouteStarter
StreamingHttpService
.