public final class HttpPredicateRouterBuilder extends Object implements RouteStarter
StreamingHttpService which routes requests to a number of other StreamingHttpServices 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(BiPredicate<ConnectionContext,StreamingHttpRequest> predicate)
Begin a route that matches
StreamingHttpRequest and ConnectionContext with a user-specified
predicate. |
RouteContinuation |
when(Predicate<StreamingHttpRequest> predicate)
Begin a route that matches
StreamingHttpRequests with a user-specified predicate. |
CookieMatcher |
whenCookie(String name)
|
StringMultiValueMatcher |
whenHeader(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(String path)
Begin a route that matches requests where the path is equal to
path. |
RouteContinuation |
whenPathIsOneOf(String... paths)
Begin a route that matches requests where the path is equal to any of the specified
paths. |
RouteContinuation |
whenPathMatches(Pattern pathRegex)
Begin a route that matches requests where the path matches the regex
pathRegex. |
RouteContinuation |
whenPathMatches(String pathRegex)
Begin a route that matches requests where the path matches the regex
pathRegex. |
RouteContinuation |
whenPathStartsWith(String pathPrefix)
Begin a route that matches requests where the path starts with
pathPrefix. |
StringMultiValueMatcher |
whenQueryParam(String name)
Begin a route with a
StringMultiValueMatcher that matches against the value(s) of the request
parameter name. |
public RouteContinuation whenMethod(HttpRequestMethod method)
RouteStarterHttpRequestMethod is method.whenMethod in interface RouteStartermethod - the method to match.RouteContinuation for the next steps of building a route.public RouteContinuation whenMethodIsOneOf(HttpRequestMethod... methods)
RouteStarterHttpRequestMethod is one of the methods.whenMethodIsOneOf in interface RouteStartermethods - the methods to match.RouteContinuation for the next steps of building a route.public RouteContinuation whenPathEquals(String path)
RouteStarterpath.whenPathEquals in interface RouteStarterpath - the path to match.RouteContinuation for the next steps of building a route.public RouteContinuation whenPathIsOneOf(String... paths)
RouteStarterpaths.whenPathIsOneOf in interface RouteStarterpaths - the paths to match.RouteContinuation for the next steps of building a route.public RouteContinuation whenPathStartsWith(String pathPrefix)
RouteStarterpathPrefix.whenPathStartsWith in interface RouteStarterpathPrefix - the path prefix to match.RouteContinuation for the next steps of building a route.public RouteContinuation whenPathMatches(String pathRegex)
RouteStarterpathRegex.whenPathMatches in interface RouteStarterpathRegex - the regex to match against the request path.RouteContinuation for the next steps of building a route.public RouteContinuation whenPathMatches(Pattern pathRegex)
RouteStarterpathRegex.whenPathMatches in interface RouteStarterpathRegex - the regex to match against the request path.RouteContinuation for the next steps of building a route.public StringMultiValueMatcher whenQueryParam(String name)
RouteStarterStringMultiValueMatcher that matches against the value(s) of the request
parameter name.whenQueryParam in interface RouteStartername - 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(CharSequence name)
RouteStarterStringMultiValueMatcher that matches against the value(s) of the
name headers.whenHeader in interface RouteStartername - 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(String name)
RouteStarterwhenCookie in interface RouteStartername - 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()
RouteStarterwhenIsSsl in interface RouteStarterRouteContinuation for the next steps of building a route.public RouteContinuation whenIsNotSsl()
RouteStarterwhenIsNotSsl in interface RouteStarterRouteContinuation for the next steps of building a route.public RouteContinuation when(Predicate<StreamingHttpRequest> predicate)
RouteStarterStreamingHttpRequests with a user-specified predicate.when in interface RouteStarterpredicate - the predicate to evaluate against requests.RouteContinuation for the next steps of building a route.public RouteContinuation when(BiPredicate<ConnectionContext,StreamingHttpRequest> predicate)
RouteStarterStreamingHttpRequest and ConnectionContext with a user-specified
predicate.when in interface RouteStarterpredicate - the predicate to evaluate against the request and connection context.RouteContinuation for the next steps of building a route.public StreamingHttpService buildStreaming()
RouteStarterStreamingHttpService that performs the configured routing.buildStreaming in interface RouteStarterStreamingHttpService.