Package com.linecorp.armeria.server
Class VirtualHostDecoratingServiceBindingBuilder
java.lang.Object
com.linecorp.armeria.server.VirtualHostDecoratingServiceBindingBuilder
public final class VirtualHostDecoratingServiceBindingBuilder extends Object
A builder class for binding a
decorator
to a Route
fluently.
This class can be instantiated through VirtualHostBuilder.routeDecorator()
.
Call build(Function)
or build(DecoratingHttpServiceFunction)
to build the decorator
and return to the VirtualHostBuilder
.
ServerBuilder sb = Server.builder();
sb.virtualHost("example.com")
.routeDecorator() // Configure a decorator with route.
.pathPrefix("/api/users")
.build((delegate, ctx, req) -> {
if (!"bearer my_token".equals(req.headers().get(HttpHeaderNames.AUTHORIZATION))) {
return HttpResponse.of(HttpStatus.UNAUTHORIZED);
}
return delegate.serve(ctx, req);
}); // Return to the VirtualHostBuilder.
- See Also:
VirtualHostServiceBindingBuilder
-
Method Summary
Modifier and Type Method Description VirtualHostDecoratingServiceBindingBuilder
addRoute(Route route)
Specifies an additionalRoute
that should be matched.VirtualHostBuilder
build(DecoratingHttpServiceFunction decoratingHttpServiceFunction)
Sets theDecoratingHttpServiceFunction
and returnsVirtualHostBuilder
that thisVirtualHostDecoratingServiceBindingBuilder
was created from.VirtualHostBuilder
build(Function<? super HttpService,? extends HttpService> decorator)
Sets thedecorator
and returnsVirtualHostBuilder
that thisVirtualHostDecoratingServiceBindingBuilder
was created from.VirtualHostDecoratingServiceBindingBuilder
connect(String pathPattern)
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.CONNECT
requests.VirtualHostDecoratingServiceBindingBuilder
consumes(MediaType... consumeTypes)
SetsMediaType
s that anHttpService
will consume.VirtualHostDecoratingServiceBindingBuilder
consumes(Iterable<MediaType> consumeTypes)
SetsMediaType
s that anHttpService
will consume.VirtualHostDecoratingServiceBindingBuilder
delete(String pathPattern)
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.DELETE
requests.VirtualHostDecoratingServiceBindingBuilder
get(String pathPattern)
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.GET
requests.VirtualHostDecoratingServiceBindingBuilder
head(String pathPattern)
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.HEAD
requests.VirtualHostDecoratingServiceBindingBuilder
matchesHeaders(CharSequence headerName, Predicate<? super String> valuePredicate)
Sets theRoute
to accept a request when the specifiedvaluePredicate
evaluatestrue
with the value of the specifiedheaderName
header.VirtualHostDecoratingServiceBindingBuilder
matchesHeaders(Iterable<String> headerPredicates)
Sets theRoute
to accept a request if it matches all the specified predicates forHttpHeaders
.VirtualHostDecoratingServiceBindingBuilder
matchesHeaders(String... headerPredicates)
Sets theRoute
to accept a request if it matches all the specified predicates forHttpHeaders
.VirtualHostDecoratingServiceBindingBuilder
matchesParams(Iterable<String> paramPredicates)
Sets theRoute
to accept a request if it matches all the specified predicates for HTTP parameters.VirtualHostDecoratingServiceBindingBuilder
matchesParams(String... paramPredicates)
Sets theRoute
to accept a request if it matches all the specified predicates for HTTP parameters.VirtualHostDecoratingServiceBindingBuilder
matchesParams(String paramName, Predicate<? super String> valuePredicate)
Sets theRoute
to accept a request when the specifiedvaluePredicate
evaluatestrue
with the value of the specifiedparamName
parameter.VirtualHostDecoratingServiceBindingBuilder
methods(HttpMethod... methods)
Sets theHttpMethod
s that anHttpService
will support.VirtualHostDecoratingServiceBindingBuilder
methods(Iterable<HttpMethod> methods)
Sets theHttpMethod
s that anHttpService
will support.VirtualHostDecoratingServiceBindingBuilder
options(String pathPattern)
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.OPTIONS
requests.VirtualHostDecoratingServiceBindingBuilder
patch(String pathPattern)
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.PATCH
requests.VirtualHostDecoratingServiceBindingBuilder
path(String pathPattern)
Sets the path pattern that anHttpService
will be bound to.VirtualHostDecoratingServiceBindingBuilder
pathPrefix(String prefix)
Sets the specified prefix which is a directory that anHttpService
will be bound under.VirtualHostDecoratingServiceBindingBuilder
post(String pathPattern)
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.POST
requests.VirtualHostDecoratingServiceBindingBuilder
produces(MediaType... produceTypes)
SetsMediaType
s that anHttpService
will produce to be used in content negotiation.VirtualHostDecoratingServiceBindingBuilder
produces(Iterable<MediaType> produceTypes)
SetsMediaType
s that anHttpService
will produce to be used in content negotiation.VirtualHostDecoratingServiceBindingBuilder
put(String pathPattern)
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.PUT
requests.VirtualHostDecoratingServiceBindingBuilder
trace(String pathPattern)
Sets the path pattern that anHttpService
will be bound to, only supportingHttpMethod.TRACE
requests.
-
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 VirtualHostDecoratingServiceBindingBuilder 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
public VirtualHostDecoratingServiceBindingBuilder matchesHeaders(Iterable<String> headerPredicates)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 VirtualHostDecoratingServiceBindingBuilder 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. -
build
Sets thedecorator
and returnsVirtualHostBuilder
that thisVirtualHostDecoratingServiceBindingBuilder
was created from.- Parameters:
decorator
- theFunction
that decoratesHttpService
-
build
Sets theDecoratingHttpServiceFunction
and returnsVirtualHostBuilder
that thisVirtualHostDecoratingServiceBindingBuilder
was created from.- Parameters:
decoratingHttpServiceFunction
- theDecoratingHttpServiceFunction
that decoratesHttpService
-