Top Description Inners Fields Constructors Methods
org.springframework.web.util

public abstract Class UriComponents

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
org.springframework.web.util.HierarchicalUriComponents, org.springframework.web.util.OpaqueUriComponents
Annotations
@SuppressWarnings:serial
Imports
java.io.Serializable, java.net.URI, java.nio.charset.Charset, .StandardCharsets, java.util.Arrays, .Iterator, .List, .Map, java.util.function.UnaryOperator, java.util.regex.Matcher, .Pattern, org.springframework.lang.Nullable, org.springframework.util.Assert, .MultiValueMap

Represents an immutable collection of URI components, mapping component type to String values. Contains convenience getters for all components. Effectively similar to java.net.URI, but with more powerful encoding options and support for URI template variables.
Authors
Arjen Poutsma, Juergen Hoeller, Rossen Stoyanchev
Since
3.1
See Also
UriComponentsBuilder

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
UriComponents.MapTemplateVariables

URI template variables backed by a map.

public static interface
UriComponents.UriTemplateVariables

Defines the contract for URI Template variables.

private static class
UriComponents.VarArgsTemplateVariables

URI template variables backed by a variable argument array.

Field Summary

Modifier and TypeField and Description
private final String
private static final Pattern
NAMES_PATTERN

Captures URI template variable names.

private final String

Constructor Summary

AccessConstructor and Description
protected
UriComponents(String scheme, String fragment)

Method Summary

Modifier and TypeMethod and Description
protected abstract void
copyToUriComponentsBuilder(UriComponentsBuilder builder)

Set all components of the given UriComponentsBuilder.

public final UriComponents
encode()

Invoke this after expanding URI variables to encode the resulting URI component values.

public abstract UriComponents
encode(Charset
the charset to use for encoding
charset
)

A variant of encode() with a charset other than "UTF-8".

public final UriComponents

Returns:

the expanded URI components
expand
(Map<String, ?>
the map of URI variables
uriVariables
)

Replace all URI template variables with the values from a given map.

public final UriComponents

Returns:

the expanded URI components
expand
(Object...
the URI variable values
uriVariableValues
)

Replace all URI template variables with the values from a given array.

public final UriComponents

Returns:

the expanded URI components
expand
(UriComponents.UriTemplateVariables
the URI template values
uriVariables
)

Replace all URI template variables with the values from the given UriTemplateVariables.

pack-priv abstract UriComponents

Returns:

the expanded URI components
expandInternal
(UriComponents.UriTemplateVariables
the URI template values
uriVariables
)

Replace all URI template variables with the values from the given UriTemplateVariables.

pack-priv static String
pack-priv static String
public final String
getFragment()

Return the fragment.

public abstract String
getHost()

Return the host.

public abstract String
getPath()

Return the path.

public abstract List<String>
getPathSegments()

Return the list of path segments.

public abstract int
getPort()

Return the port.

public abstract String
getQuery()

Return the query.

public abstract MultiValueMap<String, String>
getQueryParams()

Return the map of query parameters.

public final String
getScheme()

Return the scheme.

public abstract String
getSchemeSpecificPart()

Return the scheme specific part.

public abstract String
getUserInfo()

Return the user info.

private static String
private static String
public abstract UriComponents
normalize()

Normalize the path removing sequences like "path/..".

private static String
sanitizeSource(String source)

Remove nested "{}" such as in URI vars with regular expressions.

public final String
toString()

Overrides java.lang.Object.toString.

A simple pass-through to toUriString().
public abstract URI
toUri()

Create a URI from this instance as follows:

If the current instance is encoded, form the full URI String via toUriString(), and then pass it to the single argument URI constructor which preserves percent encoding.

public abstract String
toUriString()

Concatenate all URI components to return the fully formed URI String.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

fragmentback to summary
private final String fragment
Annotations
@Nullable
NAMES_PATTERNback to summary
private static final Pattern NAMES_PATTERN

Captures URI template variable names.

schemeback to summary
private final String scheme
Annotations
@Nullable

Constructor Detail

UriComponentsback to summary
protected UriComponents(String scheme, String fragment)

Method Detail

copyToUriComponentsBuilderback to summary
protected abstract void copyToUriComponentsBuilder(UriComponentsBuilder builder)

Set all components of the given UriComponentsBuilder.

Since
4.2
encodeback to summary
public final UriComponents 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
UriComponentsBuilder#encode()
encodeback to summary
public abstract UriComponents encode(Charset charset)

A variant of encode() with a charset other than "UTF-8".

Parameters
charset:Charset

the charset to use for encoding

See Also
UriComponentsBuilder#encode(Charset)
expandback to summary
public final UriComponents expand(Map<String, ?> uriVariables)

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:Map<String, ?>

the map of URI variables

Returns:UriComponents

the expanded URI components

expandback to summary
public final UriComponents expand(Object... uriVariableValues)

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:Object[]

the URI variable values

Returns:UriComponents

the expanded URI components

expandback to summary
public final UriComponents expand(UriComponents.UriTemplateVariables uriVariables)

Replace all URI template variables with the values from the given UriTemplateVariables.

Parameters
uriVariables:UriComponents.UriTemplateVariables

the URI template values

Returns:UriComponents

the expanded URI components

expandInternalback to summary
pack-priv abstract UriComponents expandInternal(UriComponents.UriTemplateVariables uriVariables)

Replace all URI template variables with the values from the given UriTemplateVariables.

Parameters
uriVariables:UriComponents.UriTemplateVariables

the URI template values

Returns:UriComponents

the expanded URI components

expandUriComponentback to summary
pack-priv static String expandUriComponent(String source, UriComponents.UriTemplateVariables uriVariables)
Annotations
@Nullable
expandUriComponentback to summary
pack-priv static String expandUriComponent(String source, UriComponents.UriTemplateVariables uriVariables, UnaryOperator<String> encoder)
Annotations
@Nullable
getFragmentback to summary
public final String getFragment()

Return the fragment. Can be null.

Annotations
@Nullable
getHostback to summary
public abstract String getHost()

Return the host. Can be null.

Annotations
@Nullable
getPathback to summary
public abstract String getPath()

Return the path. Can be null.

Annotations
@Nullable
getPathSegmentsback to summary
public abstract List<String> getPathSegments()

Return the list of path segments. Empty if no path has been set.

getPortback to summary
public abstract int getPort()

Return the port. -1 if no port has been set.

getQueryback to summary
public abstract String getQuery()

Return the query. Can be null.

Annotations
@Nullable
getQueryParamsback to summary
public abstract MultiValueMap<String, String> getQueryParams()

Return the map of query parameters. Empty if no query has been set.

getSchemeback to summary
public final String getScheme()

Return the scheme. Can be null.

Annotations
@Nullable
getSchemeSpecificPartback to summary
public abstract String getSchemeSpecificPart()

Return the scheme specific part. Can be null.

Annotations
@Nullable
getUserInfoback to summary
public abstract String getUserInfo()

Return the user info. Can be null.

Annotations
@Nullable
getVariableNameback to summary
private static String getVariableName(String match)
getVariableValueAsStringback to summary
private static String getVariableValueAsString(Object variableValue)
normalizeback to summary
public abstract UriComponents 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
org.springframework.util.StringUtils#cleanPath(String)
sanitizeSourceback to summary
private static String sanitizeSource(String source)

Remove nested "{}" such as in URI vars with regular expressions.

toStringback to summary
public final String toString()

Overrides java.lang.Object.toString.

A simple pass-through to toUriString().

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override
toUriback to summary
public abstract URI toUri()

Create a URI from this instance as follows:

If the current instance is encoded, form the full URI String via toUriString(), and then pass it to the single argument URI 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.

toUriStringback to summary
public abstract String 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() or encode().

org.springframework.web.util back to summary

private Class UriComponents.MapTemplateVariables

extends Object
implements UriTemplateVariables
Class Inheritance
  • java.lang.Object
  • org.springframework.web.util.UriComponents.MapTemplateVariables
All Implemented Interfaces
org.springframework.web.util.UriComponents.UriTemplateVariables

URI template variables backed by a map.

Field Summary

Modifier and TypeField and Description
private final Map<String, ?>

Constructor Summary

AccessConstructor and Description
public
MapTemplateVariables(Map<String, ?> uriVariables)

Method Summary

Modifier and TypeMethod and Description
public Object
getValue(String
the variable name
name
)

Implements org.springframework.web.util.UriComponents.UriTemplateVariables.getValue.

Get the value for the given URI variable name.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

uriVariablesback to summary
private final Map<String, ?> uriVariables

Constructor Detail

MapTemplateVariablesback to summary
public MapTemplateVariables(Map<String, ?> uriVariables)

Method Detail

getValueback to summary
public Object getValue(String name)

Implements org.springframework.web.util.UriComponents.UriTemplateVariables.getValue.

Doc from org.springframework.web.util.UriComponents.UriTemplateVariables.getValue.

Get the value for the given URI variable name. If the value is null, an empty String is expanded. If the value is SKIP_VALUE, the URI variable is not expanded.

Parameters
name:String

the variable name

Returns:Object

the variable value, possibly null or SKIP_VALUE

Annotations
@Override
@Nullable
org.springframework.web.util back to summary

public Interface UriComponents.UriTemplateVariables

Known Direct Implementers
org.springframework.web.util.UriComponents.MapTemplateVariables, org.springframework.web.util.UriComponents.VarArgsTemplateVariables, org.springframework.web.util.HierarchicalUriComponents.QueryUriTemplateVariables

Defines the contract for URI Template variables.
See Also
HierarchicalUriComponents#expand

Field Summary

Modifier and TypeField and Description
public static final Object
SKIP_VALUE

Constant for a value that indicates a URI variable name should be ignored and left as is.

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

the variable value, possibly null or SKIP_VALUE
getValue
(String
the variable name
name
)

Get the value for the given URI variable name.

Field Detail

SKIP_VALUEback to summary
public static final Object SKIP_VALUE

Constant for a value that indicates a URI variable name should be ignored and left as is. This is useful for partial expanding of some but not all URI variables.

Method Detail

getValueback to summary
public Object getValue(String name)

Get the value for the given URI variable name. If the value is null, an empty String is expanded. If the value is SKIP_VALUE, the URI variable is not expanded.

Parameters
name:String

the variable name

Returns:Object

the variable value, possibly null or SKIP_VALUE

Annotations
@Nullable
org.springframework.web.util back to summary

private Class UriComponents.VarArgsTemplateVariables

extends Object
implements UriTemplateVariables
Class Inheritance
  • java.lang.Object
  • org.springframework.web.util.UriComponents.VarArgsTemplateVariables
All Implemented Interfaces
org.springframework.web.util.UriComponents.UriTemplateVariables

URI template variables backed by a variable argument array.

Field Summary

Modifier and TypeField and Description
private final Iterator<Object>

Constructor Summary

AccessConstructor and Description
public
VarArgsTemplateVariables(Object... uriVariableValues)

Method Summary

Modifier and TypeMethod and Description
public Object
getValue(String
the variable name
name
)

Implements org.springframework.web.util.UriComponents.UriTemplateVariables.getValue.

Get the value for the given URI variable name.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

valueIteratorback to summary
private final Iterator<Object> valueIterator

Constructor Detail

VarArgsTemplateVariablesback to summary
public VarArgsTemplateVariables(Object... uriVariableValues)

Method Detail

getValueback to summary
public Object getValue(String name)

Implements org.springframework.web.util.UriComponents.UriTemplateVariables.getValue.

Doc from org.springframework.web.util.UriComponents.UriTemplateVariables.getValue.

Get the value for the given URI variable name. If the value is null, an empty String is expanded. If the value is SKIP_VALUE, the URI variable is not expanded.

Parameters
name:String

the variable name

Returns:Object

the variable value, possibly null or SKIP_VALUE

Annotations
@Override
@Nullable