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
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDefines the contract for URI Template variables. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidSet all components of the given UriComponentsBuilder.final UriComponentsencode()Invoke this after expanding URI variables to encode the resulting URI component values.abstract UriComponentsA variant ofencode()with a charset other than "UTF-8".final UriComponentsReplace all URI template variables with the values from a given array.final UriComponentsReplace all URI template variables with the values from a given map.final UriComponentsexpand(UriComponents.UriTemplateVariables uriVariables) Replace all URI template variables with the values from the givenUriComponents.UriTemplateVariables.final StringReturn the fragment.abstract StringgetHost()Return the host.abstract StringgetPath()Return the path.Return the list of path segments.abstract intgetPort()Return the port.abstract StringgetQuery()Return the query.abstract MultiValueMap<String,String> Return the map of query parameters.final StringReturn the scheme.abstract StringReturn the scheme specific part.abstract StringReturn the user info.abstract UriComponentsNormalize the path removing sequences like "path/..".final StringtoString()A simple pass-through totoUriString().abstract URItoUri()Create aURIfrom this instance as follows:abstract StringConcatenate 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.-1if 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 aURIfrom this instance as follows:If the current instance is
encoded, form the full URI String viatoUriString(), and then pass it to the single argumentURIconstructor which preserves percent encoding.If not yet encoded, pass individual URI component values to the multi-argument
URIconstructor 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
-