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)
.contentPreview(500)
.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 |
contentPreview(int length)
Sets the
ContentPreviewerFactory for creating a ContentPreviewer which produces the
preview with the maximum length limit for an HTTP request/response of the HttpService. |
ServiceBindingBuilder |
contentPreview(int length,
Charset defaultCharset)
Sets the
ContentPreviewerFactory for creating a ContentPreviewer which produces the
preview with the maximum length limit for an HTTP request/response of an HttpService. |
ServiceBindingBuilder |
contentPreviewerFactory(ContentPreviewerFactory factory)
Sets the
ContentPreviewerFactory for an HTTP request/response of an HttpService. |
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 |
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.
Use
pathPrefix(String). |
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 |
requestContentPreviewerFactory(ContentPreviewerFactory factory)
Sets the
ContentPreviewerFactory for an HTTP request of an HttpService. |
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 |
responseContentPreviewerFactory(ContentPreviewerFactory factory)
Sets the
ContentPreviewerFactory for an HTTP response of an HttpService. |
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)
pathPrefix(String).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 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 requestContentPreviewerFactory(ContentPreviewerFactory factory)
ContentPreviewerFactory for an HTTP request of an HttpService.
If not set, the ContentPreviewerFactory set via
VirtualHost.requestContentPreviewerFactory() is used.public ServiceBindingBuilder responseContentPreviewerFactory(ContentPreviewerFactory factory)
ContentPreviewerFactory for an HTTP response of an HttpService.
If not set, the ContentPreviewerFactory set via
VirtualHost.responseContentPreviewerFactory() is used.public ServiceBindingBuilder contentPreview(int length)
ContentPreviewerFactory for creating a ContentPreviewer which produces the
preview with the maximum length limit for an HTTP request/response of the HttpService.
The previewer is enabled only if the content type of an HTTP request/response meets
any of the following conditions:
text/* or application/x-www-form-urlencoded"xml" or "json""+xml" or "+json"length - the maximum length of the preview.public ServiceBindingBuilder contentPreview(int length, Charset defaultCharset)
ContentPreviewerFactory for creating a ContentPreviewer which produces the
preview with the maximum length limit for an HTTP request/response of an HttpService.
The previewer is enabled only if the content type of an HTTP request/response meets any of
the following conditions:
text/* or application/x-www-form-urlencoded"xml" or "json""+xml" or "+json"length - the maximum length of the previewdefaultCharset - the default charset used when a charset is not specified in the
"content-type" headerpublic ServiceBindingBuilder contentPreviewerFactory(ContentPreviewerFactory factory)
ContentPreviewerFactory for an HTTP request/response of an HttpService.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.