Class UriComponents
- All Implemented Interfaces:
Serializable
URI
, but with more powerful encoding options and support for
URI template variables.- Since:
- 3.1
- Author:
- Arjen Poutsma, Juergen Hoeller, Rossen Stoyanchev
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Defines the contract for URI Template variables. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
Set all components of the given UriComponentsBuilder.final UriComponents
encode()
Invoke this after expanding URI variables to encode the resulting URI component values.abstract UriComponents
A variant ofencode()
with a charset other than "UTF-8".final UriComponents
Replace all URI template variables with the values from a given array.final UriComponents
Replace all URI template variables with the values from a given map.final UriComponents
expand
(UriComponents.UriTemplateVariables uriVariables) Replace all URI template variables with the values from the givenUriComponents.UriTemplateVariables
.final String
Return the fragment.abstract String
getHost()
Return the host.abstract String
getPath()
Return the path.Return the list of path segments.abstract int
getPort()
Return the port.abstract String
getQuery()
Return the query.abstract MultiValueMap<String,
String> Return the map of query parameters.final String
Return the scheme.abstract String
Return the scheme specific part.abstract String
Return the user info.abstract UriComponents
Normalize the path removing sequences like "path/..".final String
toString()
A simple pass-through totoUriString()
.abstract URI
toUri()
Create aURI
from this instance as follows:abstract String
Concatenate all URI components to return the fully formed URI String.
-
Constructor Details
-
UriComponents
-
-
Method Details
-
getScheme
Return the scheme. Can benull
. -
getFragment
Return the fragment. Can benull
. -
getSchemeSpecificPart
Return the scheme specific part. Can benull
. -
getUserInfo
Return the user info. Can benull
. -
getHost
Return the host. Can benull
. -
getPort
public abstract int getPort()Return the port.-1
if no port has been set. -
getPath
Return the path. Can benull
. -
getPathSegments
Return the list of path segments. Empty if no path has been set. -
getQuery
Return the query. Can benull
. -
getQueryParams
Return the map of query parameters. Empty if no query has been set. -
encode
Invoke this after expanding URI variables to encode the resulting URI component values.In comparison to
UriComponentsBuilder.encode()
, this method only replaces non-ASCII and illegal (within a given URI component type) characters, but not characters with reserved meaning. For most cases,UriComponentsBuilder.encode()
is more likely to give the expected result.- See Also:
-
encode
A variant ofencode()
with a charset other than "UTF-8".- Parameters:
charset
- the charset to use for encoding- See Also:
-
expand
Replace all URI template variables with the values from a given map.The given map keys represent variable names; the corresponding values represent variable values. The order of variables is not significant.
- Parameters:
uriVariables
- the map of URI variables- Returns:
- the expanded URI components
-
expand
Replace all URI template variables with the values from a given array.The given array represents variable values. The order of variables is significant.
- Parameters:
uriVariableValues
- the URI variable values- Returns:
- the expanded URI components
-
expand
Replace all URI template variables with the values from the givenUriComponents.UriTemplateVariables
.- Parameters:
uriVariables
- the URI template values- Returns:
- the expanded URI components
-
normalize
Normalize the path removing sequences like "path/..". Note that normalization is applied to the full path, and not to individual path segments.- See Also:
-
toUriString
Concatenate all URI components to return the fully formed URI String.This method amounts to simple String concatenation of the current URI component values and as such the result may contain illegal URI characters, for example if URI variables have not been expanded or if encoding has not been applied via
UriComponentsBuilder.encode()
orencode()
. -
toUri
Create aURI
from this instance as follows:If the current instance is
encoded
, form the full URI String viatoUriString()
, and then pass it to the single argumentURI
constructor which preserves percent encoding.If not yet encoded, pass individual URI component values to the multi-argument
URI
constructor which quotes illegal characters that cannot appear in their respective URI component. -
toString
A simple pass-through totoUriString()
. -
copyToUriComponentsBuilder
Set all components of the given UriComponentsBuilder.- Since:
- 4.2
-