public final class ServiceBindingBuilder extends Object
HttpService fluently. This class can be instantiated through
ServerBuilder.route(). You can also configure an HttpService using
ServerBuilder.withRoute(Consumer).
Call build(HttpService) to build the HttpService and return to the ServerBuilder.
ServerBuilder sb = Server.builder();
sb.route() // Configure the first service.
.post("/foo/bar")
.consumes(JSON, PLAIN_TEXT_UTF_8)
.produces(JSON_UTF_8)
.requestTimeoutMillis(5000)
.maxRequestLength(8192)
.verboseResponses(true)
.build((ctx, req) -> HttpResponse.of(OK)); // Return to the ServerBuilder.
// Configure the second service with Consumer.
sb.withRoute(builder -> builder.path("/baz")
.methods(HttpMethod.GET, HttpMethod.POST)
.build((ctx, req) -> HttpResponse.of(OK)));
VirtualHostServiceBindingBuilder| Modifier and Type | Method and Description |
|---|---|
ServiceBindingBuilder |
accessLogFormat(String accessLogFormat)
Sets the format of this
HttpService's access log. |
ServiceBindingBuilder |
accessLogWriter(AccessLogWriter accessLogWriter,
boolean shutdownOnStop)
Sets the access log writer of this
HttpService. |
ServerBuilder |
build(HttpService service)
Sets the
HttpService and returns the ServerBuilder that this
ServiceBindingBuilder was created from. |
ServiceBindingBuilder |
connect(String pathPattern)
Sets the path pattern that an
HttpService will be bound to, only supporting
HttpMethod.CONNECT requests. |
ServiceBindingBuilder |
consumes(Iterable<MediaType> consumeTypes)
Sets
MediaTypes that an HttpService will consume. |
ServiceBindingBuilder |
consumes(MediaType... consumeTypes)
Sets
MediaTypes that an HttpService will consume. |
ServiceBindingBuilder |
decorator(Function<? super HttpService,? extends HttpService> decorator)
Decorates an
HttpService with the specified decorator. |
ServiceBindingBuilder |
delete(String pathPattern)
Sets the path pattern that an
HttpService will be bound to, only supporting
HttpMethod.DELETE requests. |
ServiceBindingBuilder |
get(String pathPattern)
Sets the path pattern that an
HttpService will be bound to, only supporting
HttpMethod.GET requests. |
ServiceBindingBuilder |
head(String pathPattern)
Sets the path pattern that an
HttpService will be bound to, only supporting
HttpMethod.HEAD requests. |
ServiceBindingBuilder |
matchesHeaders(CharSequence headerName,
Predicate<? super String> valuePredicate)
Sets the
Route to accept a request when the specified valuePredicate evaluates
true with the value of the specified headerName header. |
ServiceBindingBuilder |
matchesHeaders(Iterable<String> headerPredicates)
Sets the
Route to accept a request if it matches all the specified predicates for
HttpHeaders. |
ServiceBindingBuilder |
matchesHeaders(String... headerPredicates)
Sets the
Route to accept a request if it matches all the specified predicates for
HttpHeaders. |
ServiceBindingBuilder |
matchesParams(Iterable<String> paramPredicates)
Sets the
Route to accept a request if it matches all the specified predicates for
HTTP parameters. |
ServiceBindingBuilder |
matchesParams(String... paramPredicates)
Sets the
Route to accept a request if it matches all the specified predicates for
HTTP parameters. |
ServiceBindingBuilder |
matchesParams(String paramName,
Predicate<? super String> valuePredicate)
Sets the
Route to accept a request when the specified valuePredicate evaluates
true with the value of the specified paramName parameter. |
ServiceBindingBuilder |
maxRequestLength(long maxRequestLength)
Sets the maximum allowed length of an HTTP request.
|
ServiceBindingBuilder |
methods(HttpMethod... methods)
Sets the
HttpMethods that an HttpService will support. |
ServiceBindingBuilder |
methods(Iterable<HttpMethod> methods)
Sets the
HttpMethods that an HttpService will support. |
ServiceBindingBuilder |
options(String pathPattern)
Sets the path pattern that an
HttpService will be bound to, only supporting
HttpMethod.OPTIONS requests. |
ServiceBindingBuilder |
patch(String pathPattern)
Sets the path pattern that an
HttpService will be bound to, only supporting
HttpMethod.PATCH requests. |
ServiceBindingBuilder |
path(String pathPattern)
Sets the path pattern that an
HttpService will be bound to. |
ServiceBindingBuilder |
pathPrefix(String prefix)
Sets the specified prefix which is a directory that an
HttpService will be bound under. |
ServiceBindingBuilder |
pathUnder(String prefix)
Deprecated.
|
ServiceBindingBuilder |
post(String pathPattern)
Sets the path pattern that an
HttpService will be bound to, only supporting
HttpMethod.POST requests. |
ServiceBindingBuilder |
produces(Iterable<MediaType> produceTypes)
Sets
MediaTypes that an HttpService will produce to be used in
content negotiation. |
ServiceBindingBuilder |
produces(MediaType... produceTypes)
Sets
MediaTypes that an HttpService will produce to be used in
content negotiation. |
ServiceBindingBuilder |
put(String pathPattern)
Sets the path pattern that an
HttpService will be bound to, only supporting
HttpMethod.PUT requests. |
ServiceBindingBuilder |
requestTimeout(Duration requestTimeout)
Sets the timeout of an HTTP request.
|
ServiceBindingBuilder |
requestTimeoutMillis(long requestTimeoutMillis)
Sets the timeout of an HTTP request in milliseconds.
|
ServiceBindingBuilder |
trace(String pathPattern)
Sets the path pattern that an
HttpService will be bound to, only supporting
HttpMethod.TRACE requests. |
ServiceBindingBuilder |
verboseResponses(boolean verboseResponses)
Sets whether the verbose response mode is enabled.
|
public ServiceBindingBuilder path(String pathPattern)
HttpService will be bound to.
Please refer to the Path patterns
in order to learn how to specify a path pattern.@Deprecated public ServiceBindingBuilder pathUnder(String prefix)
HttpService will be bound under.
pathUnder("/my/path") is identical to path("prefix:/my/path").public ServiceBindingBuilder pathPrefix(String prefix)
HttpService will be bound under.
pathPrefix("/my/path") is identical to path("prefix:/my/path").public ServiceBindingBuilder methods(HttpMethod... methods)
HttpMethods that an HttpService will support. If not set,
HttpMethod.knownMethods()s are set.path(String),
pathPrefix(String)public ServiceBindingBuilder methods(Iterable<HttpMethod> methods)
HttpMethods that an HttpService will support. If not set,
HttpMethod.knownMethods()s are set.path(String),
pathPrefix(String)public ServiceBindingBuilder get(String pathPattern)
HttpService will be bound to, only supporting
HttpMethod.GET requests.
Please refer to the Path patterns
in order to learn how to specify a path pattern.public ServiceBindingBuilder post(String pathPattern)
HttpService will be bound to, only supporting
HttpMethod.POST requests.
Please refer to the Path patterns
in order to learn how to specify a path pattern.public ServiceBindingBuilder put(String pathPattern)
HttpService will be bound to, only supporting
HttpMethod.PUT requests.
Please refer to the Path patterns
in order to learn how to specify a path pattern.public ServiceBindingBuilder patch(String pathPattern)
HttpService will be bound to, only supporting
HttpMethod.PATCH requests.
Please refer to the Path patterns
in order to learn how to specify a path pattern.public ServiceBindingBuilder delete(String pathPattern)
HttpService will be bound to, only supporting
HttpMethod.DELETE requests.
Please refer to the Path patterns
in order to learn how to specify a path pattern.public ServiceBindingBuilder options(String pathPattern)
HttpService will be bound to, only supporting
HttpMethod.OPTIONS requests.
Please refer to the Path patterns
in order to learn how to specify a path pattern.public ServiceBindingBuilder head(String pathPattern)
HttpService will be bound to, only supporting
HttpMethod.HEAD requests.
Please refer to the Path patterns
in order to learn how to specify a path pattern.public ServiceBindingBuilder trace(String pathPattern)
HttpService will be bound to, only supporting
HttpMethod.TRACE requests.
Please refer to the Path patterns
in order to learn how to specify a path pattern.public ServiceBindingBuilder connect(String pathPattern)
HttpService will be bound to, only supporting
HttpMethod.CONNECT requests.
Please refer to the Path patterns
in order to learn how to specify a path pattern.public ServiceBindingBuilder consumes(MediaType... consumeTypes)
MediaTypes that an HttpService will consume. If not set, the HttpService
will accept all media types.public ServiceBindingBuilder consumes(Iterable<MediaType> consumeTypes)
MediaTypes that an HttpService will consume. If not set, the HttpService
will accept all media types.public ServiceBindingBuilder produces(MediaType... produceTypes)
MediaTypes that an HttpService will produce to be used in
content negotiation. See Accept header
for more information.public ServiceBindingBuilder produces(Iterable<MediaType> produceTypes)
MediaTypes that an HttpService will produce to be used in
content negotiation. See Accept header
for more information.public ServiceBindingBuilder matchesParams(String... paramPredicates)
Route to accept a request if it matches all the specified predicates for
HTTP parameters. The predicate can be one of the following forms:
some-param=some-value which means that the request must have a
some-param=some-value parametersome-param!=some-value which means that the request must not have a
some-param=some-value parametersome-param which means that the request must contain a some-param parameter!some-param which means that the request must not contain a some-param
parameterNote that these predicates can be evaluated only with the query string of the request URI. Also note that each predicate will be evaluated with the decoded value of HTTP parameters, so do not use percent-encoded value in the predicate.
MatchesParampublic ServiceBindingBuilder matchesParams(Iterable<String> paramPredicates)
Route to accept a request if it matches all the specified predicates for
HTTP parameters. The predicate can be one of the following forms:
some-param=some-value which means that the request must have a
some-param=some-value parametersome-param!=some-value which means that the request must not have a
some-param=some-value parametersome-param which means that the request must contain a some-param parameter!some-param which means that the request must not contain a some-param
parameterNote that these predicates can be evaluated only with the query string of the request URI. Also note that each predicate will be evaluated with the decoded value of HTTP parameters, so do not use percent-encoded value in the predicate.
MatchesParampublic ServiceBindingBuilder matchesParams(String paramName, Predicate<? super String> valuePredicate)
Route to accept a request when the specified valuePredicate evaluates
true with the value of the specified paramName parameter.public ServiceBindingBuilder matchesHeaders(String... headerPredicates)
Route to accept a request if it matches all the specified predicates for
HttpHeaders. The predicate can be one of the following forms:
some-header=some-value which means that the request must have a
some-header: some-value headersome-header!=some-value which means that the request must not have a
some-header: some-value headersome-header which means that the request must contain a some-header header!some-header which means that the request must not contain a some-header
headerMatchesHeaderpublic ServiceBindingBuilder matchesHeaders(Iterable<String> headerPredicates)
Route to accept a request if it matches all the specified predicates for
HttpHeaders. The predicate can be one of the following forms:
some-header=some-value which means that the request must have a
some-header: some-value headersome-header!=some-value which means that the request must not have a
some-header: some-value an headersome-header which means that the request must contain a some-header header!some-header which means that the request must not contain a some-header
headerMatchesHeaderpublic ServiceBindingBuilder matchesHeaders(CharSequence headerName, Predicate<? super String> valuePredicate)
Route to accept a request when the specified valuePredicate evaluates
true with the value of the specified headerName header.public ServiceBindingBuilder requestTimeout(Duration requestTimeout)
VirtualHost.requestTimeoutMillis() is used.requestTimeout - the timeout. 0 disables the timeout.public ServiceBindingBuilder requestTimeoutMillis(long requestTimeoutMillis)
VirtualHost.requestTimeoutMillis() is used.requestTimeoutMillis - the timeout in milliseconds. 0 disables the timeout.public ServiceBindingBuilder maxRequestLength(long maxRequestLength)
VirtualHost.maxRequestLength() is used.maxRequestLength - the maximum allowed length. 0 disables the length limit.public ServiceBindingBuilder verboseResponses(boolean verboseResponses)
VirtualHostBuilder.verboseResponses(boolean) is used.public ServiceBindingBuilder accessLogFormat(String accessLogFormat)
HttpService's access log. The specified accessLogFormat would be
parsed by AccessLogWriter.custom(String).public ServiceBindingBuilder accessLogWriter(AccessLogWriter accessLogWriter, boolean shutdownOnStop)
HttpService. If not set, the AccessLogWriter set via
VirtualHost.accessLogWriter() is used.shutdownOnStop - whether to shut down the AccessLogWriter when the Server stopspublic ServiceBindingBuilder decorator(Function<? super HttpService,? extends HttpService> decorator)
HttpService with the specified decorator.decorator - the Function that decorates the HttpServicepublic ServerBuilder build(HttpService service)
HttpService and returns the ServerBuilder that this
ServiceBindingBuilder was created from.IllegalStateException - if the path that the HttpService will be bound to is not specifiedCopyright © 2020 LeanCloud. All rights reserved.