public class DefaultUriTemplateHandler extends AbstractUriTemplateHandler
UriTemplateHandler
based on the use of
UriComponentsBuilder
for expanding and encoding variables.
There are also several properties to customize how URI template handling
is performed, including a baseUrl
to be used as a prefix
for all URI templates and a couple of encoding related options —
parsePath
and strictEncoding
respectively.
Constructor and Description |
---|
DefaultUriTemplateHandler() |
Modifier and Type | Method and Description |
---|---|
protected UriComponents |
expandAndEncode(UriComponentsBuilder builder,
java.util.Map<java.lang.String,?> uriVariables) |
protected UriComponents |
expandAndEncode(UriComponentsBuilder builder,
java.lang.Object[] uriVariables) |
protected java.net.URI |
expandInternal(java.lang.String uriTemplate,
java.util.Map<java.lang.String,?> uriVariables)
Actually expand and encode the URI template.
|
protected java.net.URI |
expandInternal(java.lang.String uriTemplate,
java.lang.Object... uriVariables)
Actually expand and encode the URI template.
|
protected UriComponentsBuilder |
initUriComponentsBuilder(java.lang.String uriTemplate)
Create a
UriComponentsBuilder from the URI template string. |
boolean |
isStrictEncoding()
Whether to strictly encode any character outside the unreserved set.
|
void |
setParsePath(boolean parsePath)
Whether to parse the path of a URI template string into path segments.
|
void |
setStrictEncoding(boolean strictEncoding)
Whether to encode characters outside the unreserved set as defined in
RFC 3986 Section 2.
|
boolean |
shouldParsePath()
Whether the handler is configured to parse the path into path segments.
|
expand, expand, getBaseUrl, getDefaultUriVariables, setBaseUrl, setDefaultUriVariables
public void setParsePath(boolean parsePath)
If set to true
the URI template path is immediately decomposed
into path segments any URI variables expanded into it are then subject to
path segment encoding rules. In effect URI variables in the path have any
"/" characters percent encoded.
By default this is set to false
in which case the path is kept
as a full path and expanded URI variables will preserve "/" characters.
parsePath
- whether to parse the path into path segmentspublic boolean shouldParsePath()
public void setStrictEncoding(boolean strictEncoding)
By default this is set to false
in which case only characters
illegal for the given URI component are encoded. For example when expanding
a URI variable into a path segment the "/" character is illegal and
encoded. The ";" character however is legal and not encoded even though
it has a reserved purpose.
Note: this property supersedes the need to also set
the parsePath
property.
strictEncoding
- whether to perform strict encodingpublic boolean isStrictEncoding()
protected java.net.URI expandInternal(java.lang.String uriTemplate, java.util.Map<java.lang.String,?> uriVariables)
AbstractUriTemplateHandler
expandInternal
in class AbstractUriTemplateHandler
protected java.net.URI expandInternal(java.lang.String uriTemplate, java.lang.Object... uriVariables)
AbstractUriTemplateHandler
expandInternal
in class AbstractUriTemplateHandler
protected UriComponentsBuilder initUriComponentsBuilder(java.lang.String uriTemplate)
UriComponentsBuilder
from the URI template string.
This implementation also breaks up the path into path segments depending
on whether parsePath
is enabled.protected UriComponents expandAndEncode(UriComponentsBuilder builder, java.util.Map<java.lang.String,?> uriVariables)
protected UriComponents expandAndEncode(UriComponentsBuilder builder, java.lang.Object[] uriVariables)