Package com.linecorp.armeria.server
Class RouteBuilder
java.lang.Object
com.linecorp.armeria.server.RouteBuilder
public final class RouteBuilder extends Object
Builds a new
Route
.-
Method Summary
Modifier and Type Method Description Route
build()
Returns a newly-createdRoute
based on the properties of this builder.RouteBuilder
catchAll()
Sets theRoute
to match any path.RouteBuilder
consumes(MediaType... consumeTypes)
RouteBuilder
consumes(Iterable<MediaType> consumeTypes)
boolean
equals(Object o)
RouteBuilder
exact(String exactPath)
Sets theRoute
to match the specified exact path.RouteBuilder
glob(String glob)
Sets theRoute
to match the specifiedglob
.int
hashCode()
RouteBuilder
matchesHeaders(CharSequence headerName, Predicate<? super String> valuePredicate)
Sets theRoute
to accept a request when the specifiedvaluePredicate
evaluatestrue
with the value of the specifiedheaderName
header.RouteBuilder
matchesHeaders(Iterable<String> headerPredicates)
Sets theRoute
to accept a request if it matches all the specified predicates forHttpHeaders
.RouteBuilder
matchesHeaders(String... headerPredicates)
Sets theRoute
to accept a request if it matches all the specified predicates forHttpHeaders
.RouteBuilder
matchesParams(Iterable<String> paramPredicates)
Sets theRoute
to accept a request if it matches all the specified predicates for HTTP parameters.RouteBuilder
matchesParams(String... paramPredicates)
Sets theRoute
to accept a request if it matches all the specified predicates for HTTP parameters.RouteBuilder
matchesParams(String paramName, Predicate<? super String> valuePredicate)
Sets theRoute
to accept a request when the specifiedvaluePredicate
evaluatestrue
with the value of the specifiedparamName
parameter.RouteBuilder
methods(HttpMethod... methods)
Sets theRoute
to support the specifiedHttpMethod
s.RouteBuilder
methods(Iterable<HttpMethod> methods)
Sets theRoute
to support the specifiedHttpMethod
s.RouteBuilder
path(String pathPattern)
Sets theRoute
to match the specifiedpathPattern
. e.g.RouteBuilder
path(String prefix, String pathPattern)
RouteBuilder
pathPrefix(String prefix)
RouteBuilder
pathPrefix(String prefix, boolean stripPrefix)
RouteBuilder
produces(MediaType... produceTypes)
RouteBuilder
produces(Iterable<MediaType> produceTypes)
RouteBuilder
regex(String regex)
Sets theRoute
to match the specifiedregex
.RouteBuilder
regex(Pattern regex)
Sets theRoute
to match the specifiedregex
.String
toString()
-
Method Details
-
path
Sets theRoute
to match the specifiedpathPattern
. e.g./login
(no path parameters)/users/{userId}
(curly-brace style)/list/:productType/by/:ordering
(colon style)exact:/foo/bar
(exact match)prefix:/files
(prefix match)glob:/~*/downloads/**
(glob pattern)regex:^/files/(?<filePath>.*)$
(regular expression)
- Throws:
IllegalArgumentException
- if the specified path pattern is invalid
-
path
Sets theRoute
to match the specifiedprefix
andpathPattern
. The mappedHttpService
is found when a path is under the specifiedprefix
and the rest of the path matches the specifiedpathPattern
.- See Also:
path(String)
-
exact
Sets theRoute
to match the specified exact path. -
pathPrefix
Sets theRoute
to match when a path is under the specifiedprefix
. It also removes the specifiedprefix
from the matched path so that mappedPath does not have the specifiedprefix
. For example, whenprefix
is"/foo/"
:"/foo/"
translates to"/"
"/foo/bar"
translates to"/bar"
"/foo/bar/baz"
translates to"/bar/baz"
-
pathPrefix
Sets theRoute
to match when a path is under the specifiedprefix
. WhenstripPrefix
istrue
, it also removes the specifiedprefix
from the matched path so that mappedPath does not have the specifiedprefix
. For example, whenprefix
is"/foo/"
:"/foo/"
translates to"/"
"/foo/bar"
translates to"/bar"
"/foo/bar/baz"
translates to"/bar/baz"
-
catchAll
Sets theRoute
to match any path. -
glob
Sets theRoute
to match the specifiedglob
."*"
in the expression matches a path component non-recursively whereas"**"
matches path components recursively. -
regex
Sets theRoute
to match the specifiedregex
. It also extracts the values of the named groups to pathParams: e.g."^/users/(?<userId>[0-9]+)$"
will extract the second numeric part of the path into the"userId"
path parameter. -
regex
Sets theRoute
to match the specifiedregex
. It also extracts the values of the named groups to pathParams: e.g."^/users/(?<userId>[0-9]+)$"
will extract the second numeric part of the path into the"userId"
path parameter. -
methods
Sets theRoute
to support the specifiedHttpMethod
s. If not set, the mappedHttpService
accepts anyHttpMethod
s. -
methods
Sets theRoute
to support the specifiedHttpMethod
s. If not set, the mappedHttpService
accepts anyHttpMethod
s. -
consumes
Sets theRoute
to consume the specifiedMediaType
s. If not set, the mappedHttpService
acceptsHttpRequest
s that have anyHttpHeaderNames.CONTENT_TYPE
. In order to get this work,methods(Iterable)
must be set. -
consumes
Sets theRoute
to consume the specifiedMediaType
s. If not set, the mappedHttpService
acceptsHttpRequest
s that have anyHttpHeaderNames.CONTENT_TYPE
. In order to get this work,methods(Iterable)
must be set. -
produces
Sets theRoute
to produce the specifiedMediaType
s. If not set, the mappedHttpService
acceptsHttpRequest
s that have anyHttpHeaderNames.ACCEPT
. In order to get this work,methods(Iterable)
must be set. -
produces
Sets theRoute
to produce the specifiedMediaType
s. If not set, the mappedHttpService
acceptsHttpRequest
s that have anyHttpHeaderNames.ACCEPT
. In order to get this work,methods(Iterable)
must be set. -
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
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 RouteBuilder matchesHeaders(CharSequence headerName, Predicate<? super String> valuePredicate)Sets theRoute
to accept a request when the specifiedvaluePredicate
evaluatestrue
with the value of the specifiedheaderName
header. -
build
Returns a newly-createdRoute
based on the properties of this builder. -
hashCode
public int hashCode() -
equals
-
toString
-