public class DefaultUriBuilderFactory extends java.lang.Object implements UriBuilderFactory
UriBuilderFactory
that relies on UriComponentsBuilder
for
the actual building of the URI.
Provides options to create UriBuilder
instances with a common
base URI, alternative encoding mode strategies, among others.
UriComponentsBuilder
Modifier and Type | Class and Description |
---|---|
static class |
DefaultUriBuilderFactory.EncodingMode
Enum to represent multiple URI encoding strategies.
|
Constructor and Description |
---|
DefaultUriBuilderFactory()
Default constructor without a base URI.
|
DefaultUriBuilderFactory(java.lang.String baseUriTemplate)
Constructor with a base URI.
|
DefaultUriBuilderFactory(UriComponentsBuilder baseUri)
Variant of
DefaultUriBuilderFactory(String) with a
UriComponentsBuilder . |
Modifier and Type | Method and Description |
---|---|
UriBuilder |
builder()
Create a URI builder with default settings.
|
java.net.URI |
expand(java.lang.String uriTemplate,
java.util.Map<java.lang.String,?> uriVars)
Expand the given URI template with a map of URI variables.
|
java.net.URI |
expand(java.lang.String uriTemplate,
java.lang.Object... uriVars)
Expand the given URI template with an array of URI variables.
|
java.util.Map<java.lang.String,?> |
getDefaultUriVariables()
Return the configured default URI variable values.
|
DefaultUriBuilderFactory.EncodingMode |
getEncodingMode()
Return the configured encoding mode.
|
void |
setDefaultUriVariables(java.util.Map<java.lang.String,?> defaultUriVariables)
Provide default URI variable values to use when expanding URI templates
with a Map of variables.
|
void |
setEncodingMode(DefaultUriBuilderFactory.EncodingMode encodingMode)
Set the encoding mode to use.
|
void |
setParsePath(boolean parsePath)
Whether to parse the input path into path segments if the encoding mode
is set to
EncodingMode.URI_COMPONENT ,
which ensures that URI variables in the path are encoded according to
path segment rules and for example a '/' is encoded. |
boolean |
shouldParsePath()
Whether to parse the path into path segments if the encoding mode is set
to
EncodingMode.URI_COMPONENT . |
UriBuilder |
uriString(java.lang.String uriTemplate)
Initialize a builder with the given URI template.
|
public DefaultUriBuilderFactory()
The target address must be specified on each UriBuilder.
public DefaultUriBuilderFactory(java.lang.String baseUriTemplate)
The given URI template is parsed via
UriComponentsBuilder.fromUriString(java.lang.String)
and then applied as a base URI
to every UriBuilder via UriComponentsBuilder.uriComponents(org.springframework.web.util.UriComponents)
unless
the UriBuilder itself was created with a URI template that already has a
target address.
baseUriTemplate
- the URI template to use a base URLpublic DefaultUriBuilderFactory(UriComponentsBuilder baseUri)
DefaultUriBuilderFactory(String)
with a
UriComponentsBuilder
.public void setEncodingMode(DefaultUriBuilderFactory.EncodingMode encodingMode)
By default this is set to EncodingMode.TEMPLATE_AND_VALUES
.
Note: In 5.1 the default was changed from
EncodingMode.URI_COMPONENT
.
Consequently the WebClient
, which relies on the built-in default
has also been switched to the new default. The RestTemplate
however sets this explicitly to EncodingMode.URI_COMPONENT
explicitly for historic and backwards
compatibility reasons.
encodingMode
- the encoding mode to usepublic DefaultUriBuilderFactory.EncodingMode getEncodingMode()
public void setDefaultUriVariables(@Nullable java.util.Map<java.lang.String,?> defaultUriVariables)
defaultUriVariables
- default URI variable valuespublic java.util.Map<java.lang.String,?> getDefaultUriVariables()
public void setParsePath(boolean parsePath)
EncodingMode.URI_COMPONENT
,
which ensures that URI variables in the path are encoded according to
path segment rules and for example a '/' is encoded.
By default this is set to true
.
parsePath
- whether to parse the path into path segmentspublic boolean shouldParsePath()
EncodingMode.URI_COMPONENT
.public java.net.URI expand(java.lang.String uriTemplate, java.util.Map<java.lang.String,?> uriVars)
UriTemplateHandler
expand
in interface UriTemplateHandler
uriTemplate
- the URI templateuriVars
- variable valuespublic java.net.URI expand(java.lang.String uriTemplate, java.lang.Object... uriVars)
UriTemplateHandler
expand
in interface UriTemplateHandler
uriTemplate
- the URI templateuriVars
- variable valuespublic UriBuilder uriString(java.lang.String uriTemplate)
UriBuilderFactory
uriString
in interface UriBuilderFactory
uriTemplate
- the URI template to usepublic UriBuilder builder()
UriBuilderFactory
builder
in interface UriBuilderFactory