public interface UriBuilder
Effectively a generalization of UriComponentsBuilder
but with
shortcuts to expand directly into URI
rather than
UriComponents
and also leaving common concerns such as encoding
preferences, a base URI, and others as implementation concerns.
Typically obtained via UriBuilderFactory
which serves as a central
component configured once and used to create many URLs.
UriBuilderFactory
,
UriComponentsBuilder
Modifier and Type | Method and Description |
---|---|
java.net.URI |
build(java.util.Map<java.lang.String,?> uriVariables)
Build a
URI instance and replaces URI template variables
with the values from a map. |
java.net.URI |
build(java.lang.Object... uriVariables)
Build a
URI instance and replaces URI template variables
with the values from an array. |
UriBuilder |
fragment(java.lang.String fragment)
Set the URI fragment.
|
UriBuilder |
host(java.lang.String host)
Set the URI host which may contain URI template variables, and may also
be
null to clear the host of this builder. |
UriBuilder |
path(java.lang.String path)
Append the given path to the existing path of this builder.
|
UriBuilder |
pathSegment(java.lang.String... pathSegments)
Append path segments to the existing path.
|
UriBuilder |
port(int port)
Set the URI port.
|
UriBuilder |
port(java.lang.String port)
Set the URI port .
|
UriBuilder |
query(java.lang.String query)
Append the given query to the existing query of this builder.
|
UriBuilder |
queryParam(java.lang.String name,
java.lang.Object... values)
Append the given query parameter to the existing query parameters.
|
UriBuilder |
queryParams(MultiValueMap<java.lang.String,java.lang.String> params)
Add the given query parameters.
|
UriBuilder |
replacePath(java.lang.String path)
Set the path of this builder overriding the existing path values.
|
UriBuilder |
replaceQuery(java.lang.String query)
Set the query of this builder overriding all existing query parameters.
|
UriBuilder |
replaceQueryParam(java.lang.String name,
java.lang.Object... values)
Set the query parameter values overriding all existing query values for
the same parameter.
|
UriBuilder |
replaceQueryParams(MultiValueMap<java.lang.String,java.lang.String> params)
Set the query parameter values overriding all existing query values.
|
UriBuilder |
scheme(java.lang.String scheme)
Set the URI scheme which may contain URI template variables,
and may also be
null to clear the scheme of this builder. |
UriBuilder |
userInfo(java.lang.String userInfo)
Set the URI user info which may contain URI template variables, and
may also be
null to clear the user info of this builder. |
UriBuilder scheme(@Nullable java.lang.String scheme)
null
to clear the scheme of this builder.scheme
- the URI schemeUriBuilder userInfo(@Nullable java.lang.String userInfo)
null
to clear the user info of this builder.userInfo
- the URI user infoUriBuilder host(@Nullable java.lang.String host)
null
to clear the host of this builder.host
- the URI hostUriBuilder port(int port)
-1
will clear the port of this builder.port
- the URI portUriBuilder port(@Nullable java.lang.String port)
port(int)
.
Passing null
will clear the port of this builder.port
- the URI portUriBuilder path(java.lang.String path)
path
- the URI pathUriBuilder replacePath(@Nullable java.lang.String path)
path
- the URI path, or null
for an empty pathUriBuilder pathSegment(java.lang.String... pathSegments) throws java.lang.IllegalArgumentException
path("/")
subsequently to ensure a trailing slash.pathSegments
- the URI path segmentsjava.lang.IllegalArgumentException
UriBuilder query(java.lang.String query)
Note: The presence of reserved characters can prevent
correct parsing of the URI string. For example if a query parameter
contains '='
or '&'
characters, the query string cannot
be parsed unambiguously. Such values should be substituted for URI
variables to enable correct parsing:
builder.query("filter={value}").uriString("hot&cold");
query
- the query stringUriBuilder replaceQuery(@Nullable java.lang.String query)
query
- the query string, or null
to remove all query paramsUriBuilder queryParam(java.lang.String name, java.lang.Object... values)
?foo
instead of ?foo=bar
.name
- the query parameter namevalues
- the query parameter valuesUriBuilder queryParams(MultiValueMap<java.lang.String,java.lang.String> params)
params
- the paramsUriBuilder replaceQueryParam(java.lang.String name, java.lang.Object... values)
name
- the query parameter namevalues
- the query parameter valuesUriBuilder replaceQueryParams(MultiValueMap<java.lang.String,java.lang.String> params)
params
- the query parameter nameUriBuilder fragment(@Nullable java.lang.String fragment)
null
to clear the fragment of this builder.fragment
- the URI fragmentjava.net.URI build(java.lang.Object... uriVariables)
URI
instance and replaces URI template variables
with the values from an array.uriVariables
- the map of URI variablesjava.net.URI build(java.util.Map<java.lang.String,?> uriVariables)
URI
instance and replaces URI template variables
with the values from a map.uriVariables
- the map of URI variables