Class HttpPredicateRouterBuilder
- java.lang.Object
-
- io.servicetalk.http.router.predicate.HttpPredicateRouterBuilder
-
- All Implemented Interfaces:
RouteStarter
public final class HttpPredicateRouterBuilder extends java.lang.Object implements RouteStarter
Builds anStreamingHttpServicewhich routes requests to a number of otherStreamingHttpServices 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 Summary
Constructors Constructor Description HttpPredicateRouterBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StreamingHttpServicebuildStreaming()Builds theStreamingHttpServicethat performs the configured routing.RouteContinuationwhen(java.util.function.BiPredicate<ConnectionContext,StreamingHttpRequest> predicate)Begin a route that matchesStreamingHttpRequestandConnectionContextwith a user-specifiedpredicate.RouteContinuationwhen(java.util.function.Predicate<StreamingHttpRequest> predicate)Begin a route that matchesStreamingHttpRequests with a user-specifiedpredicate.CookieMatcherwhenCookie(java.lang.String name)StringMultiValueMatcherwhenHeader(java.lang.CharSequence name)Begin a route with aStringMultiValueMatcherthat matches against the value(s) of thenameheaders.RouteContinuationwhenIsNotSsl()Begin a route that matches requests that are not over SSL/TLS.RouteContinuationwhenIsSsl()Begin a route that matches requests that are over SSL/TLS.RouteContinuationwhenMethod(HttpRequestMethod method)Begin a route that matches requests where theHttpRequestMethodismethod.RouteContinuationwhenMethodIsOneOf(HttpRequestMethod... methods)Begin a route that matches requests where theHttpRequestMethodis one of themethods.RouteContinuationwhenPathEquals(java.lang.String path)Begin a route that matches requests where the path is equal topath.RouteContinuationwhenPathIsOneOf(java.lang.String... paths)Begin a route that matches requests where the path is equal to any of the specifiedpaths.RouteContinuationwhenPathMatches(java.lang.String pathRegex)Begin a route that matches requests where the path matches the regexpathRegex.RouteContinuationwhenPathMatches(java.util.regex.Pattern pathRegex)Begin a route that matches requests where the path matches the regexpathRegex.RouteContinuationwhenPathStartsWith(java.lang.String pathPrefix)Begin a route that matches requests where the path starts withpathPrefix.StringMultiValueMatcherwhenQueryParam(java.lang.String name)Begin a route with aStringMultiValueMatcherthat matches against the value(s) of the request parametername.
-
-
-
Method Detail
-
whenMethod
public RouteContinuation whenMethod(HttpRequestMethod method)
Description copied from interface:RouteStarterBegin a route that matches requests where theHttpRequestMethodismethod.- Specified by:
whenMethodin interfaceRouteStarter- Parameters:
method- the method to match.- Returns:
RouteContinuationfor the next steps of building a route.
-
whenMethodIsOneOf
public RouteContinuation whenMethodIsOneOf(HttpRequestMethod... methods)
Description copied from interface:RouteStarterBegin a route that matches requests where theHttpRequestMethodis one of themethods.- Specified by:
whenMethodIsOneOfin interfaceRouteStarter- Parameters:
methods- the methods to match.- Returns:
RouteContinuationfor the next steps of building a route.
-
whenPathEquals
public RouteContinuation whenPathEquals(java.lang.String path)
Description copied from interface:RouteStarterBegin a route that matches requests where the path is equal topath.- Specified by:
whenPathEqualsin interfaceRouteStarter- Parameters:
path- the path to match.- Returns:
RouteContinuationfor the next steps of building a route.
-
whenPathIsOneOf
public RouteContinuation whenPathIsOneOf(java.lang.String... paths)
Description copied from interface:RouteStarterBegin a route that matches requests where the path is equal to any of the specifiedpaths.- Specified by:
whenPathIsOneOfin interfaceRouteStarter- Parameters:
paths- the paths to match.- Returns:
RouteContinuationfor the next steps of building a route.
-
whenPathStartsWith
public RouteContinuation whenPathStartsWith(java.lang.String pathPrefix)
Description copied from interface:RouteStarterBegin a route that matches requests where the path starts withpathPrefix.- Specified by:
whenPathStartsWithin interfaceRouteStarter- Parameters:
pathPrefix- the path prefix to match.- Returns:
RouteContinuationfor the next steps of building a route.
-
whenPathMatches
public RouteContinuation whenPathMatches(java.lang.String pathRegex)
Description copied from interface:RouteStarterBegin a route that matches requests where the path matches the regexpathRegex.- Specified by:
whenPathMatchesin interfaceRouteStarter- Parameters:
pathRegex- the regex to match against the request path.- Returns:
RouteContinuationfor the next steps of building a route.
-
whenPathMatches
public RouteContinuation whenPathMatches(java.util.regex.Pattern pathRegex)
Description copied from interface:RouteStarterBegin a route that matches requests where the path matches the regexpathRegex.- Specified by:
whenPathMatchesin interfaceRouteStarter- Parameters:
pathRegex- the regex to match against the request path.- Returns:
RouteContinuationfor the next steps of building a route.
-
whenQueryParam
public StringMultiValueMatcher whenQueryParam(java.lang.String name)
Description copied from interface:RouteStarterBegin a route with aStringMultiValueMatcherthat matches against the value(s) of the request parametername.- Specified by:
whenQueryParamin interfaceRouteStarter- Parameters:
name- the request parameter name that must be present in the request in order to continue evaluation of this route.- Returns:
StringMultiValueMatcherfor the next steps of building a route.
-
whenHeader
public StringMultiValueMatcher whenHeader(java.lang.CharSequence name)
Description copied from interface:RouteStarterBegin a route with aStringMultiValueMatcherthat matches against the value(s) of thenameheaders.- Specified by:
whenHeaderin interfaceRouteStarter- Parameters:
name- The header name that must be present in the request in order to continue evaluation of this route.- Returns:
StringMultiValueMatcherfor the next steps of building a route.
-
whenCookie
public CookieMatcher whenCookie(java.lang.String name)
Description copied from interface:RouteStarter- Specified by:
whenCookiein interfaceRouteStarter- Parameters:
name- the cookie name that must be present in the request in order to continue evaluation of this route.- Returns:
CookieMatcherfor the next steps of building a route.
-
whenIsSsl
public RouteContinuation whenIsSsl()
Description copied from interface:RouteStarterBegin a route that matches requests that are over SSL/TLS.- Specified by:
whenIsSslin interfaceRouteStarter- Returns:
RouteContinuationfor the next steps of building a route.
-
whenIsNotSsl
public RouteContinuation whenIsNotSsl()
Description copied from interface:RouteStarterBegin a route that matches requests that are not over SSL/TLS.- Specified by:
whenIsNotSslin interfaceRouteStarter- Returns:
RouteContinuationfor the next steps of building a route.
-
when
public RouteContinuation when(java.util.function.Predicate<StreamingHttpRequest> predicate)
Description copied from interface:RouteStarterBegin a route that matchesStreamingHttpRequests with a user-specifiedpredicate.- Specified by:
whenin interfaceRouteStarter- Parameters:
predicate- the predicate to evaluate against requests.- Returns:
RouteContinuationfor the next steps of building a route.
-
when
public RouteContinuation when(java.util.function.BiPredicate<ConnectionContext,StreamingHttpRequest> predicate)
Description copied from interface:RouteStarterBegin a route that matchesStreamingHttpRequestandConnectionContextwith a user-specifiedpredicate.- Specified by:
whenin interfaceRouteStarter- Parameters:
predicate- the predicate to evaluate against the request and connection context.- Returns:
RouteContinuationfor the next steps of building a route.
-
buildStreaming
public StreamingHttpService buildStreaming()
Description copied from interface:RouteStarterBuilds theStreamingHttpServicethat performs the configured routing.- Specified by:
buildStreamingin interfaceRouteStarter- Returns:
- the router
StreamingHttpService.
-
-