Package com.linecorp.armeria.server
Class VirtualHostServiceBindingBuilder
java.lang.Object
com.linecorp.armeria.server.VirtualHostServiceBindingBuilder
public final class VirtualHostServiceBindingBuilder extends Object
A builder class for binding an
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)));
- See Also:
ServiceBindingBuilder
-
Method Summary
Modifier and Type Method Description VirtualHostServiceBindingBuilder
accessLogFormat(String accessLogFormat)
VirtualHostServiceBindingBuilder
accessLogWriter(AccessLogWriter accessLogWriter, boolean shutdownOnStop)
VirtualHostServiceBindingBuilder
addRoute(Route route)
Specifies an additionalRoute
that should be matched.VirtualHostBuilder
build(HttpService service)
Sets theHttpService
and returns theVirtualHostBuilder
that thisVirtualHostServiceBindingBuilder
was created from.VirtualHostServiceBindingBuilder
connect(String pathPattern)
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.CONNECT
requests.VirtualHostServiceBindingBuilder
consumes(MediaType... consumeTypes)
SetsMediaType
s that anHttpService
will consume.VirtualHostServiceBindingBuilder
consumes(Iterable<MediaType> consumeTypes)
SetsMediaType
s that anHttpService
will consume.VirtualHostServiceBindingBuilder
decorator(Function<? super HttpService,? extends HttpService> decorator)
VirtualHostServiceBindingBuilder
defaultLogName(String defaultLogName)
Sets the default value of theRequestOnlyLog.name()
property which is used when no name was set viaRequestLogBuilder.name(String, String)
.VirtualHostServiceBindingBuilder
defaultServiceName(String defaultServiceName)
Sets the default value of theRequestOnlyLog.serviceName()
property which is used when no service name was set viaRequestLogBuilder.name(String, String)
.VirtualHostServiceBindingBuilder
delete(String pathPattern)
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.DELETE
requests.VirtualHostServiceBindingBuilder
get(String pathPattern)
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.GET
requests.VirtualHostServiceBindingBuilder
head(String pathPattern)
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.HEAD
requests.VirtualHostServiceBindingBuilder
matchesHeaders(CharSequence headerName, Predicate<? super String> valuePredicate)
Sets theRoute
to accept a request when the specifiedvaluePredicate
evaluatestrue
with the value of the specifiedheaderName
header.VirtualHostServiceBindingBuilder
matchesHeaders(Iterable<String> headerPredicates)
Sets theRoute
to accept a request if it matches all the specified predicates forHttpHeaders
.VirtualHostServiceBindingBuilder
matchesHeaders(String... headerPredicates)
Sets theRoute
to accept a request if it matches all the specified predicates forHttpHeaders
.VirtualHostServiceBindingBuilder
matchesParams(Iterable<String> paramPredicates)
Sets theRoute
to accept a request if it matches all the specified predicates for HTTP parameters.VirtualHostServiceBindingBuilder
matchesParams(String... paramPredicates)
Sets theRoute
to accept a request if it matches all the specified predicates for HTTP parameters.VirtualHostServiceBindingBuilder
matchesParams(String paramName, Predicate<? super String> valuePredicate)
Sets theRoute
to accept a request when the specifiedvaluePredicate
evaluatestrue
with the value of the specifiedparamName
parameter.VirtualHostServiceBindingBuilder
maxRequestLength(long maxRequestLength)
VirtualHostServiceBindingBuilder
methods(HttpMethod... methods)
Sets theHttpMethod
s that anHttpService
will support.VirtualHostServiceBindingBuilder
methods(Iterable<HttpMethod> methods)
Sets theHttpMethod
s that anHttpService
will support.VirtualHostServiceBindingBuilder
options(String pathPattern)
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.OPTIONS
requests.VirtualHostServiceBindingBuilder
patch(String pathPattern)
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.PATCH
requests.VirtualHostServiceBindingBuilder
path(String pathPattern)
Sets the path pattern that anHttpService
will be bound to.VirtualHostServiceBindingBuilder
pathPrefix(String prefix)
Sets the specified prefix which is a directory that anHttpService
will be bound under.VirtualHostServiceBindingBuilder
post(String pathPattern)
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.POST
requests.VirtualHostServiceBindingBuilder
produces(MediaType... produceTypes)
SetsMediaType
s that anHttpService
will produce to be used in content negotiation.VirtualHostServiceBindingBuilder
produces(Iterable<MediaType> produceTypes)
SetsMediaType
s that anHttpService
will produce to be used in content negotiation.VirtualHostServiceBindingBuilder
put(String pathPattern)
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.PUT
requests.VirtualHostServiceBindingBuilder
requestTimeout(Duration requestTimeout)
VirtualHostServiceBindingBuilder
requestTimeoutMillis(long requestTimeoutMillis)
VirtualHostServiceBindingBuilder
trace(String pathPattern)
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.TRACE
requests.VirtualHostServiceBindingBuilder
verboseResponses(boolean verboseResponses)
-
Method Details
-
path
Sets the path pattern that anHttpService
will be bound to. Please refer to the Path patterns in order to learn how to specify a path pattern. -
pathPrefix
Sets the specified prefix which is a directory that anHttpService
will be bound under.pathPrefix("/my/path")
is identical topath("prefix:/my/path")
. -
methods
Sets theHttpMethod
s that anHttpService
will support. If not set,HttpMethod.knownMethods()
s are set.- See Also:
path(String)
,pathPrefix(String)
-
methods
Sets theHttpMethod
s that anHttpService
will support. If not set,HttpMethod.knownMethods()
s are set.- See Also:
path(String)
,pathPrefix(String)
-
get
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.GET
requests. Please refer to the Path patterns in order to learn how to specify a path pattern. -
post
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.POST
requests. Please refer to the Path patterns in order to learn how to specify a path pattern. -
put
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.PUT
requests. Please refer to the Path patterns in order to learn how to specify a path pattern. -
patch
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.PATCH
requests. Please refer to the Path patterns in order to learn how to specify a path pattern. -
delete
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.DELETE
requests. Please refer to the Path patterns in order to learn how to specify a path pattern. -
options
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.OPTIONS
requests. Please refer to the Path patterns in order to learn how to specify a path pattern. -
head
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.HEAD
requests. Please refer to the Path patterns in order to learn how to specify a path pattern. -
trace
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.TRACE
requests. Please refer to the Path patterns in order to learn how to specify a path pattern. -
connect
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.CONNECT
requests. Please refer to the Path patterns in order to learn how to specify a path pattern. -
consumes
SetsMediaType
s that anHttpService
will consume. If not set, theHttpService
will accept all media types. -
consumes
SetsMediaType
s that anHttpService
will consume. If not set, theHttpService
will accept all media types. -
produces
SetsMediaType
s that anHttpService
will produce to be used in content negotiation. See Accept header for more information. -
produces
SetsMediaType
s that anHttpService
will produce to be used in content negotiation. See Accept header for more information. -
matchesParams
Sets theRoute
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 asome-param=some-value
parametersome-param!=some-value
which means that the request must not have asome-param=some-value
parametersome-param
which means that the request must contain asome-param
parameter!some-param
which means that the request must not contain asome-param
parameter
Note 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.
- See Also:
MatchesParam
-
matchesParams
Sets theRoute
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 asome-param=some-value
parametersome-param!=some-value
which means that the request must not have asome-param=some-value
parametersome-param
which means that the request must contain asome-param
parameter!some-param
which means that the request must not contain asome-param
parameter
Note 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.
- See Also:
MatchesParam
-
matchesParams
public VirtualHostServiceBindingBuilder matchesParams(String paramName, Predicate<? super String> valuePredicate)Sets theRoute
to accept a request when the specifiedvaluePredicate
evaluatestrue
with the value of the specifiedparamName
parameter. -
matchesHeaders
Sets theRoute
to accept a request if it matches all the specified predicates forHttpHeaders
. The predicate can be one of the following forms:some-header=some-value
which means that the request must have asome-header: some-value
headersome-header!=some-value
which means that the request must not have asome-header: some-value
headersome-header
which means that the request must contain asome-header
header!some-header
which means that the request must not contain asome-header
header
- See Also:
MatchesHeader
-
matchesHeaders
Sets theRoute
to accept a request if it matches all the specified predicates forHttpHeaders
. The predicate can be one of the following forms:some-header=some-value
which means that the request must have asome-header: some-value
headersome-header!=some-value
which means that the request must not have asome-header: some-value
an headersome-header
which means that the request must contain asome-header
header!some-header
which means that the request must not contain asome-header
header
- See Also:
MatchesHeader
-
matchesHeaders
public VirtualHostServiceBindingBuilder matchesHeaders(CharSequence headerName, Predicate<? super String> valuePredicate)Sets theRoute
to accept a request when the specifiedvaluePredicate
evaluatestrue
with the value of the specifiedheaderName
header. -
addRoute
Specifies an additionalRoute
that should be matched. -
defaultServiceName
Sets the default value of theRequestOnlyLog.serviceName()
property which is used when no service name was set viaRequestLogBuilder.name(String, String)
.- Parameters:
defaultServiceName
- the default service name.
-
defaultLogName
Sets the default value of theRequestOnlyLog.name()
property which is used when no name was set viaRequestLogBuilder.name(String, String)
.- Parameters:
defaultLogName
- the default log name.
-
requestTimeout
-
requestTimeoutMillis
-
maxRequestLength
-
verboseResponses
-
accessLogFormat
-
accessLogWriter
public VirtualHostServiceBindingBuilder accessLogWriter(AccessLogWriter accessLogWriter, boolean shutdownOnStop) -
decorator
public VirtualHostServiceBindingBuilder decorator(Function<? super HttpService,? extends HttpService> decorator) -
build
Sets theHttpService
and returns theVirtualHostBuilder
that thisVirtualHostServiceBindingBuilder
was created from.- Throws:
IllegalStateException
- if the path that theHttpService
will be bound to is not specified
-