public final class VirtualHostServiceBindingBuilder extends Object
HttpService fluently. This class can be instantiated through
VirtualHostBuilder.route(). You can also configure an HttpService using
VirtualHostBuilder.withRoute(Consumer).
Call build(HttpService) to build the HttpService and return to the
VirtualHostBuilder.
ServerBuilder sb = Server.builder();
sb.virtualHost("example.com")
.route() // Configure the first service in "example.com".
.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 VirtualHostBuilder.
sb.virtualHost("example2.com") // Configure the second service "example2.com".
.withRoute(builder -> builder.path("/baz")
.methods(HttpMethod.GET, HttpMethod.POST)
.build((ctx, req) -> HttpResponse.of(OK)));
ServiceBindingBuilder| Modifier and Type | Method and Description |
|---|---|
VirtualHostServiceBindingBuilder |
accessLogFormat(String accessLogFormat)
Sets the format of this
HttpService's access log. |
VirtualHostServiceBindingBuilder |
accessLogWriter(AccessLogWriter accessLogWriter,
boolean shutdownOnStop)
Sets the access log writer of this
HttpService. |
VirtualHostBuilder |
build(HttpService service)
Sets the
HttpService and returns the VirtualHostBuilder that this
VirtualHostServiceBindingBuilder was created from. |
VirtualHostServiceBindingBuilder |
connect(String pathPattern)
Sets the path pattern that an
HttpService will be bound to, only supporting
HttpMethod.CONNECT requests. |
VirtualHostServiceBindingBuilder |
consumes(Iterable<MediaType> consumeTypes)
Sets
MediaTypes that an HttpService will consume. |
VirtualHostServiceBindingBuilder |
consumes(MediaType... consumeTypes)
Sets
MediaTypes that an HttpService will consume. |
VirtualHostServiceBindingBuilder |
decorator(Function<? super HttpService,? extends HttpService> decorator)
Decorates an
HttpService with the specified decorator. |
VirtualHostServiceBindingBuilder |
delete(String pathPattern)
Sets the path pattern that an
HttpService will be bound to, only supporting
HttpMethod.DELETE requests. |
VirtualHostServiceBindingBuilder |
get(String pathPattern)
Sets the path pattern that an
HttpService will be bound to, only supporting
HttpMethod.GET requests. |
VirtualHostServiceBindingBuilder |
head(String pathPattern)
Sets the path pattern that an
HttpService will be bound to, only supporting
HttpMethod.HEAD requests. |
com.linecorp.armeria.server.AbstractBindingBuilder |
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. |
com.linecorp.armeria.server.AbstractBindingBuilder |
matchesHeaders(Iterable<String> headerPredicates)
Sets the
Route to accept a request if it matches all the specified predicates for
HttpHeaders. |
com.linecorp.armeria.server.AbstractBindingBuilder |
matchesHeaders(String... headerPredicates)
Sets the
Route to accept a request if it matches all the specified predicates for
HttpHeaders. |
com.linecorp.armeria.server.AbstractBindingBuilder |
matchesParams(Iterable<String> paramPredicates)
Sets the
Route to accept a request if it matches all the specified predicates for
HTTP parameters. |
com.linecorp.armeria.server.AbstractBindingBuilder |
matchesParams(String... paramPredicates)
Sets the
Route to accept a request if it matches all the specified predicates for
HTTP parameters. |
com.linecorp.armeria.server.AbstractBindingBuilder |
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. |
VirtualHostServiceBindingBuilder |
maxRequestLength(long maxRequestLength)
Sets the maximum allowed length of an HTTP request.
|
VirtualHostServiceBindingBuilder |
methods(HttpMethod... methods)
Sets the
HttpMethods that an HttpService will support. |
VirtualHostServiceBindingBuilder |
methods(Iterable<HttpMethod> methods)
Sets the
HttpMethods that an HttpService will support. |
VirtualHostServiceBindingBuilder |
options(String pathPattern)
Sets the path pattern that an
HttpService will be bound to, only supporting
HttpMethod.OPTIONS requests. |
VirtualHostServiceBindingBuilder |
patch(String pathPattern)
Sets the path pattern that an
HttpService will be bound to, only supporting
HttpMethod.PATCH requests. |
VirtualHostServiceBindingBuilder |
path(String pathPattern)
Sets the path pattern that an
HttpService will be bound to. |
VirtualHostServiceBindingBuilder |
pathPrefix(String prefix)
Sets the specified prefix which is a directory that an
HttpService will be bound under. |
VirtualHostServiceBindingBuilder |
pathUnder(String prefix)
Deprecated.
|
VirtualHostServiceBindingBuilder |
post(String pathPattern)
Sets the path pattern that an
HttpService will be bound to, only supporting
HttpMethod.POST requests. |
VirtualHostServiceBindingBuilder |
produces(Iterable<MediaType> produceTypes)
Sets
MediaTypes that an HttpService will produce to be used in
content negotiation. |
VirtualHostServiceBindingBuilder |
produces(MediaType... produceTypes)
Sets
MediaTypes that an HttpService will produce to be used in
content negotiation. |
VirtualHostServiceBindingBuilder |
put(String pathPattern)
Sets the path pattern that an
HttpService will be bound to, only supporting
HttpMethod.PUT requests. |
VirtualHostServiceBindingBuilder |
requestTimeout(Duration requestTimeout)
Sets the timeout of an HTTP request.
|
VirtualHostServiceBindingBuilder |
requestTimeoutMillis(long requestTimeoutMillis)
Sets the timeout of an HTTP request in milliseconds.
|
VirtualHostServiceBindingBuilder |
trace(String pathPattern)
Sets the path pattern that an
HttpService will be bound to, only supporting
HttpMethod.TRACE requests. |
VirtualHostServiceBindingBuilder |
verboseResponses(boolean verboseResponses)
Sets whether the verbose response mode is enabled.
|
public VirtualHostServiceBindingBuilder 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 VirtualHostServiceBindingBuilder pathUnder(String prefix)
HttpService will be bound under.
pathUnder("/my/path") is identical to path("prefix:/my/path").public VirtualHostServiceBindingBuilder pathPrefix(String prefix)
HttpService will be bound under.
pathPrefix("/my/path") is identical to path("prefix:/my/path").public VirtualHostServiceBindingBuilder methods(HttpMethod... methods)
HttpMethods that an HttpService will support. If not set,
HttpMethod.knownMethods()s are set.path(String),
pathPrefix(String)public VirtualHostServiceBindingBuilder methods(Iterable<HttpMethod> methods)
HttpMethods that an HttpService will support. If not set,
HttpMethod.knownMethods()s are set.path(String),
pathPrefix(String)public VirtualHostServiceBindingBuilder 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 VirtualHostServiceBindingBuilder 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 VirtualHostServiceBindingBuilder 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 VirtualHostServiceBindingBuilder 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 VirtualHostServiceBindingBuilder 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 VirtualHostServiceBindingBuilder 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 VirtualHostServiceBindingBuilder 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 VirtualHostServiceBindingBuilder 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 VirtualHostServiceBindingBuilder 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 VirtualHostServiceBindingBuilder consumes(MediaType... consumeTypes)
MediaTypes that an HttpService will consume. If not set, the HttpService
will accept all media types.public VirtualHostServiceBindingBuilder consumes(Iterable<MediaType> consumeTypes)
MediaTypes that an HttpService will consume. If not set, the HttpService
will accept all media types.public VirtualHostServiceBindingBuilder produces(MediaType... produceTypes)
MediaTypes that an HttpService will produce to be used in
content negotiation. See Accept header
for more information.public VirtualHostServiceBindingBuilder produces(Iterable<MediaType> produceTypes)
MediaTypes that an HttpService will produce to be used in
content negotiation. See Accept header
for more information.public VirtualHostServiceBindingBuilder requestTimeout(Duration requestTimeout)
VirtualHost.requestTimeoutMillis() is used.requestTimeout - the timeout. 0 disables the timeout.public VirtualHostServiceBindingBuilder requestTimeoutMillis(long requestTimeoutMillis)
VirtualHost.requestTimeoutMillis() is used.requestTimeoutMillis - the timeout in milliseconds. 0 disables the timeout.public VirtualHostServiceBindingBuilder maxRequestLength(long maxRequestLength)
VirtualHost.maxRequestLength() is used.maxRequestLength - the maximum allowed length. 0 disables the length limit.public VirtualHostServiceBindingBuilder verboseResponses(boolean verboseResponses)
VirtualHostBuilder.verboseResponses(boolean) is used.public VirtualHostServiceBindingBuilder accessLogFormat(String accessLogFormat)
HttpService's access log. The specified accessLogFormat would be
parsed by AccessLogWriter.custom(String).public VirtualHostServiceBindingBuilder 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 VirtualHostServiceBindingBuilder decorator(Function<? super HttpService,? extends HttpService> decorator)
HttpService with the specified decorator.decorator - the Function that decorates the HttpServicepublic VirtualHostBuilder build(HttpService service)
HttpService and returns the VirtualHostBuilder that this
VirtualHostServiceBindingBuilder was created from.IllegalStateException - if the path that the HttpService will be bound to is not specifiedpublic com.linecorp.armeria.server.AbstractBindingBuilder 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 com.linecorp.armeria.server.AbstractBindingBuilder 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 com.linecorp.armeria.server.AbstractBindingBuilder 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 com.linecorp.armeria.server.AbstractBindingBuilder 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 com.linecorp.armeria.server.AbstractBindingBuilder 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 com.linecorp.armeria.server.AbstractBindingBuilder 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.Copyright © 2020 LeanCloud. All rights reserved.