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

public Class UriComponentsBuilder

extends Object
implements UriBuilder, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, org.springframework.web.util.UriBuilder
Imports
java.net.InetSocketAddress, .URI, java.nio.charset.Charset, .StandardCharsets, java.util.ArrayDeque, .ArrayList, .Collection, .Deque, .HashMap, .List, .Map, .Optional, java.util.regex.Matcher, .Pattern, org.springframework.http.HttpRequest, org.springframework.lang.Nullable, org.springframework.util.Assert, .CollectionUtils, .LinkedMultiValueMap, .MultiValueMap, .ObjectUtils, .StringUtils, org.springframework.web.util.HierarchicalUriComponents.PathComponent, .UriComponents.UriTemplateVariables

Builder for UriComponents.

Typical usage involves:

  1. Create a UriComponentsBuilder with one of the static factory methods (such as fromPath(String) or fromUri(URI))
  2. Set the various URI components through the respective methods (scheme(String), userInfo(String), host(String), port(int), path(String), pathSegment(String...), queryParam(String, Object...), and fragment(String).
  3. Build the UriComponents instance with the build() method.
Authors
Arjen Poutsma, Rossen Stoyanchev, Phillip Webb, Oliver Gierke, Brian Clozel, Sebastien Deleuze, Sam Brannen
Since
3.1
See Also
newInstance(), fromPath(String), fromUri(URI)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static enum
private static class
private static interface
private static class

Field Summary

Modifier and TypeField and Description
private Charset
private static final Object[]
private boolean
private String
private String
private static final String
private static final String
private static final String
private static final String
private static final Pattern
private static final String
private static final String
private UriComponentsBuilder.CompositePathComponentBuilder
private String
private static final String
private static final Pattern
private static final String
private final MultiValueMap<String, String>
private String
private static final String
private String
private static final Pattern
private final Map<String, Object>
private String
private static final String

Constructor Summary

AccessConstructor and Description
protected
UriComponentsBuilder()

Default constructor.

protected
UriComponentsBuilder(UriComponentsBuilder
the other builder to copy from
other
)

Create a deep copy of the given UriComponentsBuilder.

Method Summary

Modifier and TypeMethod and Description
public UriComponents

Returns:

the URI components
build
()

Build a UriComponents instance from the various components contained in this builder.

public UriComponents

Returns:

the URI components
build
(boolean
whether the components in this builder are already encoded
encoded
)

Variant of build() to create a UriComponents instance when components are already fully encoded.

public URI
build(Object...
the map of URI variables
uriVariables
)

Implements org.springframework.web.util.UriBuilder.build.

Build a URI instance and replaces URI template variables with the values from an array.
public URI
build(Map<String, ?>
the map of URI variables
uriVariables
)

Implements org.springframework.web.util.UriBuilder.build.

Build a URI instance and replaces URI template variables with the values from a map.
public UriComponents

Returns:

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

Build a UriComponents instance and replaces URI template variables with the values from a map.

public UriComponents

Returns:

the URI components with expanded values
buildAndExpand
(Object...
the URI variable values
uriVariableValues
)

Build a UriComponents instance and replaces URI template variables with the values from an array.

private UriComponents
public Object
clone()

Overrides java.lang.Object.clone.

Public declaration of Object's clone() method.
public UriComponentsBuilder

Returns:

the cloned UriComponentsBuilder object
cloneBuilder
()

Clone this UriComponentsBuilder.

public final UriComponentsBuilder
encode()

Request to have the URI template pre-encoded at build time, and URI variables encoded separately when expanded.

public UriComponentsBuilder
encode(Charset
the charset to use for encoding
charset
)

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

public UriComponentsBuilder
fragment(String
the URI fragment
fragment
)

Implements org.springframework.web.util.UriBuilder.fragment.

Set the URI fragment.
public static UriComponentsBuilder

Returns:

the URI components of the URI
fromHttpRequest
(HttpRequest
the source request
request
)

Deprecated for removal since 6.1. in favor of ForwardedHeaderUtils#adaptFromForwardedHeaders; to be removed in 6.2
Create a new UriComponents object from the URI associated with the given HttpRequest while also overlaying with values from the headers "Forwarded" (RFC 7239), or "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if "Forwarded" is not found.
public static UriComponentsBuilder

Returns:

the URI components of the URI
fromHttpUrl
(String
the source URI
httpUrl
)

Create a URI components builder from the given HTTP URL String.

public static UriComponentsBuilder
fromOriginHeader(String origin)

Create an instance by parsing the "Origin" header of an HTTP request.

public static UriComponentsBuilder

Returns:

the new UriComponentsBuilder
fromPath
(String
the path to initialize with
path
)

Create a builder that is initialized with the given path.

public static UriComponentsBuilder

Returns:

the new UriComponentsBuilder
fromUri
(URI
the URI to initialize with
uri
)

Create a builder that is initialized from the given URI.

public static UriComponentsBuilder

Returns:

the new UriComponentsBuilder
fromUriString
(String
the URI string to initialize with
uri
)

Create a builder that is initialized with the given URI string.

private String
public UriComponentsBuilder
host(String
the URI host
host
)

Implements org.springframework.web.util.UriBuilder.host.

Set the URI host which may contain URI template variables, and may also be null to clear the host of this builder.
public static UriComponentsBuilder

Returns:

the new UriComponentsBuilder
newInstance
()

Create a new, empty builder.

public static InetSocketAddress

Returns:

an InetSocketAddress with the extracted host and port, or null if the headers are not present.
parseForwardedFor
(HttpRequest
a request with headers that may contain forwarded headers
request
,
InetSocketAddress
the current remoteAddress
remoteAddress
)

Deprecated for removal since 6.1. in favor of ForwardedHeaderUtils#parseForwardedFor; to be removed in 6.2
Parse the first "Forwarded: for=..." or "X-Forwarded-For" header value to an InetSocketAddress representing the address of the client.
public UriComponentsBuilder
path(String
the URI path
path
)

Implements org.springframework.web.util.UriBuilder.path.

Append to the path of this builder.
public UriComponentsBuilder
pathSegment(String...
the URI path segments
pathSegments
)

Implements org.springframework.web.util.UriBuilder.pathSegment.

Append to the path using path segments.
public UriComponentsBuilder
port(int
the URI port
port
)

Implements org.springframework.web.util.UriBuilder.port.

Set the URI port.
public UriComponentsBuilder
port(String
the URI port
port
)

Implements org.springframework.web.util.UriBuilder.port.

Set the URI port.
public UriComponentsBuilder
query(String
the query string
query
)

Implements org.springframework.web.util.UriBuilder.query.

Parse the given query string into query parameters where parameters are separated with '&' and their values, if any, with '='.
public UriComponentsBuilder
queryParam(String
the query parameter name
name
,
Object...
the query parameter values
values
)

Implements org.springframework.web.util.UriBuilder.queryParam.

Append the given query parameter.
public UriComponentsBuilder
queryParam(String
the query parameter name
name
,
Collection<?>
the query parameter values
values
)

Implements org.springframework.web.util.UriBuilder.queryParam.

Variant of queryParam(String, Object...) with a Collection.
public UriComponentsBuilder
queryParamIfPresent(String
the query parameter name
name
,
Optional<?>
an Optional, either empty or holding the query parameter value.
value
)

Implements org.springframework.web.util.UriBuilder.queryParamIfPresent.

Delegates to either queryParam(String, Object...) or queryParam(String, Collection) if the given Optional has a value, or else if it is empty, no query parameter is added at all.
public UriComponentsBuilder
queryParams(MultiValueMap<String, String>
the params
params
)

Implements org.springframework.web.util.UriBuilder.queryParams.

Add multiple query parameters and values.
public UriComponentsBuilder
replacePath(String
the URI path, or null for an empty path
path
)

Implements org.springframework.web.util.UriBuilder.replacePath.

Override the current path.
public UriComponentsBuilder
replaceQuery(String
the query string; a null value removes all query parameters.
query
)

Implements org.springframework.web.util.UriBuilder.replaceQuery.

Clear existing query parameters and then delegate to query(String).
public UriComponentsBuilder
replaceQueryParam(String
the query parameter name
name
,
Object...
the query parameter values
values
)

Implements org.springframework.web.util.UriBuilder.replaceQueryParam.

Set the query parameter values replacing existing values, or if no values are given, the query parameter is removed.
public UriComponentsBuilder
replaceQueryParam(String
the query parameter name
name
,
Collection<?>
the query parameter values
values
)

Implements org.springframework.web.util.UriBuilder.replaceQueryParam.

Variant of replaceQueryParam(String, Object...) with a Collection.
public UriComponentsBuilder
replaceQueryParams(MultiValueMap<String, String>
the query parameter name
params
)

Implements org.springframework.web.util.UriBuilder.replaceQueryParams.

Set the query parameter values after removing all existing ones.
private void
pack-priv void
private void
public UriComponentsBuilder
scheme(String
the URI scheme
scheme
)

Implements org.springframework.web.util.UriBuilder.scheme.

Set the URI scheme which may contain URI template variables, and may also be null to clear the scheme of this builder.
public UriComponentsBuilder

Returns:

this UriComponentsBuilder
schemeSpecificPart
(String
the URI scheme-specific-part, may contain URI template parameters
ssp
)

Set the URI scheme-specific-part.

public String
public UriComponentsBuilder

Returns:

this UriComponentsBuilder
uri
(URI
the URI
uri
)

Initialize components of this builder from components of the given URI.

public UriComponentsBuilder

Returns:

this UriComponentsBuilder
uriComponents
(UriComponents
the UriComponents to copy from
uriComponents
)

Set or append individual URI components of this builder from the values of the given UriComponents instance.

public UriComponentsBuilder

Returns:

this UriComponentsBuilder
uriVariables
(Map<String, Object>
the URI variables to use
uriVariables
)

Configure URI variables to be expanded at build time.

public UriComponentsBuilder
userInfo(String
the URI user info
userInfo
)

Implements org.springframework.web.util.UriBuilder.userInfo.

Set the URI user info which may contain URI template variables, and may also be null to clear the user info of this builder.
Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait