public class ResteasyUriBuilder extends UriBuilder
Modifier and Type | Field and Description |
---|---|
static Pattern |
hierarchicalUri |
static Pattern |
opaqueUri |
Constructor and Description |
---|
ResteasyUriBuilder() |
Modifier and Type | Method and Description |
---|---|
URI |
build(Object... values)
Build a URI, using the supplied values in order to replace any URI
template parameters.
|
URI |
build(Object[] values,
boolean encodeSlashInPath)
Build a URI, using the supplied values in order to replace any URI
template parameters.
|
URI |
buildFromEncoded(Object... values)
Build a URI.
|
URI |
buildFromEncodedMap(Map<String,? extends Object> values)
Build a URI.
|
URI |
buildFromMap(Map<String,?> values,
boolean encodeSlashInPath)
Build a URI.
|
URI |
buildFromMap(Map<String,? extends Object> values)
Build a URI.
|
protected URI |
buildFromValues(boolean encodeSlash,
boolean encoded,
Object... values) |
protected URI |
buildUriFromMap(Map<String,? extends Object> paramMap,
boolean fromEncodedMap,
boolean encodeSlash) |
UriBuilder |
clientQueryParam(String name,
Object value)
Called by ClientRequest.getUri() to add a query parameter for
@QueryParam parameters. |
UriBuilder |
clone()
Create a copy of the UriBuilder preserving its state.
|
static boolean |
compare(String s1,
String s2) |
static Matcher |
createUriParamMatcher(String string) |
UriBuilder |
fragment(String fragment)
Set the URI fragment.
|
static UriBuilder |
fromTemplate(String uriTemplate)
You may put path parameters anywhere within the uriTemplate except port
|
String |
getFragment() |
String |
getHost() |
String |
getPath() |
List<String> |
getPathParamNamesInDeclarationOrder()
Return a unique order list of path params
|
int |
getPort() |
String |
getQuery() |
String |
getScheme() |
String |
getUserInfo() |
UriBuilder |
host(String host)
Set the URI host.
|
UriBuilder |
matrixParam(String name,
Object... values)
Append a matrix parameter to the existing set of matrix parameters of
the current final segment of the URI path.
|
protected UriBuilder |
parseHierarchicalUri(String uriTemplate,
Matcher match) |
UriBuilder |
path(Class resource)
Append the path from a Path-annotated class to the
existing path.
|
UriBuilder |
path(Class resource,
String method)
Append the path from a Path-annotated method to the
existing path.
|
UriBuilder |
path(Method method)
Append the path from a
Path -annotated method to the
existing path. |
UriBuilder |
path(String segment)
Append path to the existing path.
|
protected static String |
paths(boolean encode,
String basePath,
String... segments) |
UriBuilder |
port(int port)
Set the URI port.
|
UriBuilder |
queryParam(String name,
Object... values)
Append a query parameter to the existing set of query parameters.
|
static URI |
relativize(URI from,
URI to) |
UriBuilder |
replaceMatrix(String matrix)
Set the matrix parameters of the current final segment of the current URI path.
|
UriBuilder |
replaceMatrixParam(String name,
Object... values)
Replace the existing value(s) of a matrix parameter on
the current final segment of the URI path.
|
protected StringBuffer |
replaceParameter(Map<String,? extends Object> paramMap,
boolean fromEncodedMap,
boolean isTemplate,
String string,
StringBuffer buffer,
boolean encodeSlash) |
UriBuilder |
replacePath(String path)
Set the URI path.
|
protected StringBuffer |
replacePathParameter(String name,
String value,
boolean isEncoded,
String string,
StringBuffer buffer,
boolean encodeSlash) |
UriBuilder |
replaceQuery(String query)
Set the URI query string.
|
UriBuilder |
replaceQueryParam(String name,
Object... values)
Replace the existing value(s) of a query parameter.
|
protected StringBuffer |
replaceQueryStringParameter(Map<String,? extends Object> paramMap,
boolean fromEncodedMap,
boolean isTemplate,
String string,
StringBuffer buffer) |
UriBuilder |
resolveTemplate(String name,
Object value)
Resolve a URI template with a given
name in this UriBuilder instance
using a supplied value. |
UriBuilder |
resolveTemplate(String name,
Object value,
boolean encodeSlashInPath)
Resolve a URI template with a given
name in this UriBuilder instance
using a supplied value. |
UriBuilder |
resolveTemplateFromEncoded(String name,
Object value)
Resolve a URI template with a given
name in this UriBuilder instance
using a supplied encoded value. |
UriBuilder |
resolveTemplates(Map<String,Object> templateValues)
Resolve one or more URI templates in this
UriBuilder instance using supplied
name-value pairs. |
UriBuilder |
resolveTemplates(Map<String,Object> templateValues,
boolean encodeSlashInPath)
Resolve one or more URI templates in this
UriBuilder instance using supplied
name-value pairs. |
UriBuilder |
resolveTemplatesFromEncoded(Map<String,Object> templateValues)
Resolve one or more URI templates in this
UriBuilder instance using supplied
name-value pairs. |
UriBuilder |
scheme(String scheme)
Set the URI scheme.
|
UriBuilder |
schemeSpecificPart(String ssp)
Set the URI scheme-specific-part (see
URI ). |
UriBuilder |
segment(String... segments)
Append path segments to the existing path.
|
UriBuilder |
substitutePathParam(String name,
Object value,
boolean isEncoded)
Only replace path params in path of URI.
|
String |
toTemplate()
Get the URI template string represented by this URI builder.
|
UriBuilder |
uri(String uriTemplate)
Parses the
uriTemplate string and copies the parsed components of the supplied
URI to the UriBuilder replacing any existing values for those components. |
UriBuilder |
uri(URI uri)
Copies the non-null components of the supplied URI to the UriBuilder replacing
any existing values for those components.
|
UriBuilder |
uriTemplate(String uriTemplate)
You may put path parameters anywhere within the uriTemplate except port
|
UriBuilder |
userInfo(String ui)
Set the URI user-info.
|
fromLink, fromMethod, fromPath, fromResource, fromUri, fromUri, newInstance
public static final Pattern opaqueUri
public static final Pattern hierarchicalUri
public UriBuilder clone()
UriBuilder
UriBuilder.build(Object...)
method.clone
in class UriBuilder
public static UriBuilder fromTemplate(String uriTemplate)
uriTemplate
- public UriBuilder uriTemplate(String uriTemplate)
uriTemplate
- protected UriBuilder parseHierarchicalUri(String uriTemplate, Matcher match)
public UriBuilder uri(String uriTemplate) throws IllegalArgumentException
UriBuilder
uriTemplate
string and copies the parsed components of the supplied
URI to the UriBuilder replacing any existing values for those components.uri
in class UriBuilder
uriTemplate
- a URI template that will be used to initialize the UriBuilder, may
contain URI parameters.IllegalArgumentException
- if uriTemplate
is not a valid URI template or
is null
.public UriBuilder uri(URI uri) throws IllegalArgumentException
UriBuilder
uri
in class UriBuilder
uri
- the URI to copy components from.IllegalArgumentException
- if the uri
parameter is null
.public UriBuilder scheme(String scheme) throws IllegalArgumentException
UriBuilder
scheme
in class UriBuilder
scheme
- the URI scheme, may contain URI template parameters.
A null
value will unset the URI scheme, but will
not unset the any scheme-specific-part components.IllegalArgumentException
- if scheme is invalid.public UriBuilder schemeSpecificPart(String ssp) throws IllegalArgumentException
UriBuilder
URI
). This
method will overwrite any existing
values for authority, user-info, host, port and path.schemeSpecificPart
in class UriBuilder
ssp
- the URI scheme-specific-part, may contain URI template parameters.IllegalArgumentException
- if ssp cannot be parsed or is null
.public UriBuilder userInfo(String ui)
UriBuilder
userInfo
in class UriBuilder
ui
- the URI user-info, may contain URI template parameters.
A null
value will unset userInfo component of the URI.public UriBuilder host(String host) throws IllegalArgumentException
UriBuilder
host
in class UriBuilder
host
- the URI host, may contain URI template parameters.
A null
value will unset the host component of the URI, but
will not unset other authority component parts
(user info
or port
).IllegalArgumentException
- if host is invalid.public UriBuilder port(int port) throws IllegalArgumentException
UriBuilder
port
in class UriBuilder
port
- the URI port, a value of -1 will unset an explicit port.IllegalArgumentException
- if port is invalid.public UriBuilder path(String segment) throws IllegalArgumentException
UriBuilder
path
in class UriBuilder
segment
- the path, may contain URI template parameters.IllegalArgumentException
- if path is null
.public UriBuilder path(Class resource) throws IllegalArgumentException
UriBuilder
path
in class UriBuilder
resource
- a resource whose Path
value will be
used to obtain the path to append.IllegalArgumentException
- if resource is null
, or
if resource is not annotated with Path
.public UriBuilder path(Class resource, String method) throws IllegalArgumentException
UriBuilder
path(Method)
, it
can only be used in cases where there is a single method with the
specified name that is annotated with Path
.path
in class UriBuilder
resource
- the resource containing the method.method
- the name of the method whose Path
value will be
used to obtain the path to append.IllegalArgumentException
- if resource or method is null
,
or there is more than or less than one variant of the method annotated with
Path
.public UriBuilder path(Method method) throws IllegalArgumentException
UriBuilder
Path
-annotated method to the
existing path.
When constructing the final path, a '/' separator will be inserted
between the existing path and the supplied path if necessary.path
in class UriBuilder
method
- a method whose Path
value will be
used to obtain the path to append to the existing path.IllegalArgumentException
- if method is null
or is
not annotated with a Path
.public UriBuilder replaceMatrix(String matrix) throws IllegalArgumentException
UriBuilder
replaceMatrix
in class UriBuilder
matrix
- the matrix parameters, may contain URI template parameters.
A null
value will remove all matrix parameters of the current final segment
of the current URI path.IllegalArgumentException
- if matrix cannot be parsed.public UriBuilder replaceQuery(String query) throws IllegalArgumentException
UriBuilder
replaceQuery
in class UriBuilder
query
- the URI query string, may contain URI template parameters.
A null
value will remove all query parameters.IllegalArgumentException
- if query cannot be parsed.public UriBuilder fragment(String fragment) throws IllegalArgumentException
UriBuilder
fragment
in class UriBuilder
fragment
- the URI fragment, may contain URI template parameters.
A null
value will remove any existing fragment.IllegalArgumentException
public UriBuilder substitutePathParam(String name, Object value, boolean isEncoded)
name
- value
- isEncoded
- public URI buildFromMap(Map<String,? extends Object> values) throws IllegalArgumentException, UriBuilderException
UriBuilder
String
using
their toString()
method and are then encoded to match the
rules of the URI component to which they pertain. All '%'
characters
in the stringified values will be encoded.
The state of the builder is unaffected; this method may be called
multiple times on the same builder instance.
NOTE: By default all '/'
characters in the stringified values will be
encoded in path templates, i.e. the result is identical to invoking
buildFromMap(valueMap, true)
.
To override this behavior use buildFromMap(valueMap, false)
instead.
buildFromMap
in class UriBuilder
values
- a map of URI template parameter names and values.IllegalArgumentException
- if there are any URI template parameters
without a supplied value, or if a template parameter value is null
.UriBuilderException
- if a URI cannot be constructed based on the
current state of the builder.UriBuilder.buildFromMap(java.util.Map, boolean)
,
UriBuilder.buildFromEncodedMap(java.util.Map)
public URI buildFromEncodedMap(Map<String,? extends Object> values) throws IllegalArgumentException, UriBuilderException
UriBuilder
String
using
their toString()
method and are then encoded to match the
rules of the URI component to which they pertain. All % characters in
the stringified values that are not followed by two hexadecimal numbers
will be encoded.
The state of the builder is unaffected; this method may be called
multiple times on the same builder instance.buildFromEncodedMap
in class UriBuilder
values
- a map of URI template parameter names and values.IllegalArgumentException
- if there are any URI template parameters
without a supplied value, or if a template parameter value is null
.UriBuilderException
- if a URI cannot be constructed based on the
current state of the builder.UriBuilder.buildFromMap(java.util.Map)
,
UriBuilder.buildFromMap(java.util.Map, boolean)
public URI buildFromMap(Map<String,?> values, boolean encodeSlashInPath) throws IllegalArgumentException, UriBuilderException
UriBuilder
String
using
their toString()
method and are then encoded to match the
rules of the URI component to which they pertain. All '%'
characters
in the stringified values will be encoded.
The state of the builder is unaffected; this method may be called
multiple times on the same builder instance.
The encodeSlashInPath
parameter may be used to override the default
encoding of '/'
characters in the stringified template values
in cases when the template is part of the URI path component when using
the UriBuilder.buildFromMap(java.util.Map)
method. If the encodeSlashInPath
parameter is set to true
(default), the slash ('/'
) characters in
parameter values will be encoded if the template is placed in the URI path component.
If set to false
the default encoding behavior is overridden an slash characters
in template values will not be encoded when used to substitute path templates.
buildFromMap
in class UriBuilder
values
- a map of URI template parameter names and values.encodeSlashInPath
- if true
, the slash ('/'
) characters
in parameter values will be encoded if the template
is placed in the URI path component, otherwise the slash
characters will not be encoded in path templates.IllegalArgumentException
- if there are any URI template parameters
without a supplied value, or if a template parameter value is null
.UriBuilderException
- if a URI cannot be constructed based on the
current state of the builder.UriBuilder.buildFromMap(java.util.Map)
,
UriBuilder.buildFromEncodedMap(java.util.Map)
protected URI buildUriFromMap(Map<String,? extends Object> paramMap, boolean fromEncodedMap, boolean encodeSlash) throws IllegalArgumentException, UriBuilderException
protected StringBuffer replacePathParameter(String name, String value, boolean isEncoded, String string, StringBuffer buffer, boolean encodeSlash)
protected StringBuffer replaceParameter(Map<String,? extends Object> paramMap, boolean fromEncodedMap, boolean isTemplate, String string, StringBuffer buffer, boolean encodeSlash)
protected StringBuffer replaceQueryStringParameter(Map<String,? extends Object> paramMap, boolean fromEncodedMap, boolean isTemplate, String string, StringBuffer buffer)
public List<String> getPathParamNamesInDeclarationOrder()
public URI build(Object... values) throws IllegalArgumentException, UriBuilderException
UriBuilder
String
using
their toString()
method and are then encoded to match the
rules of the URI component to which they pertain. All '%' characters
in the stringified values will be encoded.
The state of the builder is unaffected; this method may be called
multiple times on the same builder instance.
All instances of the same template parameter will be replaced by the same value that corresponds to the position of the first instance of the template parameter. e.g. the template "{a}/{b}/{a}" with values {"x", "y", "z"} will result in the the URI "x/y/x", not "x/y/z".
NOTE: By default all '/'
characters in the stringified values will be
encoded in path templates, i.e. the result is identical to invoking
UriBuilder.build(Object[], boolean)
build(values, true)}.
To override this behavior use build(values, false)
instead.
build
in class UriBuilder
values
- a list of URI template parameter values.IllegalArgumentException
- if there are any URI template parameters
without a supplied value, or if a value is null
.UriBuilderException
- if a URI cannot be constructed based on the
current state of the builder.UriBuilder.build(Object[], boolean)
,
UriBuilder.buildFromEncoded(Object...)
protected URI buildFromValues(boolean encodeSlash, boolean encoded, Object... values)
public UriBuilder matrixParam(String name, Object... values) throws IllegalArgumentException
UriBuilder
matrixParam
in class UriBuilder
name
- the matrix parameter name, may contain URI template parameters.values
- the matrix parameter value(s), each object will be converted.
to a String
using its toString()
method. Stringified
values may contain URI template parameters.IllegalArgumentException
- if name or values is null
.public UriBuilder replaceMatrixParam(String name, Object... values) throws IllegalArgumentException
UriBuilder
replaceMatrixParam
in class UriBuilder
name
- the matrix parameter name, may contain URI template parameters.values
- the matrix parameter value(s), each object will be converted.
to a String
using its toString()
method. Stringified
values may contain URI template parameters. If values
is empty
or null
then all current values of the parameter are removed.IllegalArgumentException
- if name is null
.public UriBuilder clientQueryParam(String name, Object value) throws IllegalArgumentException
@QueryParam
parameters. We do not use UriBuilder.queryParam()
because
@QueryParam
parameters).
%
characters that are followed by two hex characters).
The JavaDoc for @QueryParam.value()
explicitly states that
the value is specified in decoded format and that "any percent
encoded literals within the value will not be decoded and will
instead be treated as literal text". This means that it is an
explicit bug to perform contextual URI encoding of this method's
name parameter; hence, we must always encode said parameter. This
method also foregoes contextual URI encoding on this method's value
parameter because it represents arbitrary data passed to a
QueryParam
parameter of a client proxy (since the client
proxy is nothing more than a transport layer, it should not be
"interpreting" such data; instead, it should faithfully transmit
this data over the wire).
name
- the name of the query parameter.value
- the value of the query parameter.IllegalArgumentException
public UriBuilder queryParam(String name, Object... values) throws IllegalArgumentException
UriBuilder
queryParam
in class UriBuilder
name
- the query parameter name, may contain URI template parameters.values
- the query parameter value(s), each object will be converted
to a String
using its toString()
method. Stringified
values may contain URI template parameters.IllegalArgumentException
- if name or values is null
.public UriBuilder replaceQueryParam(String name, Object... values) throws IllegalArgumentException
UriBuilder
replaceQueryParam
in class UriBuilder
name
- the query parameter name, may contain URI template parameters.values
- the query parameter value(s), each object will be converted
to a String
using its toString()
method. Stringified
values may contain URI template parameters. If values
is empty
or null
then all current values of the parameter are removed.IllegalArgumentException
- if name is null
.public String getHost()
public String getScheme()
public int getPort()
public String getUserInfo()
public String getPath()
public String getQuery()
public String getFragment()
public UriBuilder segment(String... segments) throws IllegalArgumentException
UriBuilder
segment
in class UriBuilder
segments
- the path segment values, each may contain URI template
parameters.IllegalArgumentException
- if segments or any element of segments
is null
.public URI buildFromEncoded(Object... values) throws IllegalArgumentException, UriBuilderException
UriBuilder
String
using
their toString()
method and are then encoded to match the
rules of the URI component to which they pertain. All % characters in
the stringified values that are not followed by two hexadecimal numbers
will be encoded.
The state of the builder is unaffected; this method may be called
multiple times on the same builder instance.
All instances of the same template parameter will be replaced by the same value that corresponds to the position of the first instance of the template parameter. e.g. the template "{a}/{b}/{a}" with values {"x", "y", "z"} will result in the the URI "x/y/x", not "x/y/z".
buildFromEncoded
in class UriBuilder
values
- a list of URI template parameter values.IllegalArgumentException
- if there are any URI template parameters
without a supplied value, or if a value is null
.UriBuilderException
- if a URI cannot be constructed based on the
current state of the builder.UriBuilder.build(Object[])
,
UriBuilder.build(Object[], boolean)
public UriBuilder replacePath(String path)
UriBuilder
replacePath
in class UriBuilder
path
- the path, may contain URI template parameters.
A null
value will unset the path component of the URI.public URI build(Object[] values, boolean encodeSlashInPath) throws IllegalArgumentException, UriBuilderException
UriBuilder
String
using
their toString()
method and are then encoded to match the
rules of the URI component to which they pertain. All '%' characters
in the stringified values will be encoded.
The state of the builder is unaffected; this method may be called
multiple times on the same builder instance.
All instances of the same template parameter will be replaced by the same value that corresponds to the position of the first instance of the template parameter. e.g. the template "{a}/{b}/{a}" with values {"x", "y", "z"} will result in the the URI "x/y/x", not "x/y/z".
The encodeSlashInPath
parameter may be used to override the default
encoding of '/'
characters in the stringified template values
in cases when the template is part of the URI path component when using
the UriBuilder.build(Object[])
method. If the encodeSlashInPath
parameter is set to true
(default), the slash ('/'
) characters in
parameter values will be encoded if the template is placed in the URI path component.
If set to false
the default encoding behavior is overridden an slash characters
in template values will not be encoded when used to substitute path templates.
build
in class UriBuilder
values
- a list of URI template parameter values.encodeSlashInPath
- if true
, the slash ('/'
) characters
in parameter values will be encoded if the template
is placed in the URI path component, otherwise the slash
characters will not be encoded in path templates.IllegalArgumentException
- if there are any URI template parameters
without a supplied value, or if a value is null
.UriBuilderException
- if a URI cannot be constructed based on the
current state of the builder.UriBuilder.build(Object[])
,
UriBuilder.buildFromEncoded(Object...)
public String toTemplate()
UriBuilder
toTemplate
in class UriBuilder
public UriBuilder resolveTemplate(String name, Object value) throws IllegalArgumentException
UriBuilder
name
in this UriBuilder
instance
using a supplied value.
In case a null
template name or value is entered a IllegalArgumentException
is thrown.resolveTemplate
in class UriBuilder
name
- name of the URI template.value
- value to be used to resolve the template.IllegalArgumentException
- if the resolved template name or value is null
.public UriBuilder resolveTemplates(Map<String,Object> templateValues) throws IllegalArgumentException
UriBuilder
UriBuilder
instance using supplied
name-value pairs.
A call to the method with an empty parameter map is ignored.resolveTemplates
in class UriBuilder
templateValues
- a map of URI template names and their values.IllegalArgumentException
- if the name-value map or any of the names or values
in the map is null
.public UriBuilder resolveTemplate(String name, Object value, boolean encodeSlashInPath) throws IllegalArgumentException
UriBuilder
name
in this UriBuilder
instance
using a supplied value.
In case a null
template name or value is entered a IllegalArgumentException
is thrown.resolveTemplate
in class UriBuilder
name
- name of the URI template.value
- value to be used to resolve the template.encodeSlashInPath
- if true
, the slash ('/'
) characters
in template values will be encoded if the template
is placed in the URI path component, otherwise the slash
characters will not be encoded in path templates.IllegalArgumentException
- if the resolved template name or value is null
.public UriBuilder resolveTemplateFromEncoded(String name, Object value) throws IllegalArgumentException
UriBuilder
name
in this UriBuilder
instance
using a supplied encoded value.
A template with a matching name will be replaced by the supplied value.
Value is converted to String
using its toString()
method and is then
encoded to match the rules of the URI component to which they pertain. All % characters in
the stringified values that are not followed by two hexadecimal numbers will be encoded.
In case a null
template name or encoded value is entered a IllegalArgumentException
is thrown.resolveTemplateFromEncoded
in class UriBuilder
name
- name of the URI template.value
- encoded value to be used to resolve the template.IllegalArgumentException
- if the resolved template name or encoded value is null
.public UriBuilder resolveTemplates(Map<String,Object> templateValues, boolean encodeSlashInPath) throws IllegalArgumentException
UriBuilder
UriBuilder
instance using supplied
name-value pairs.
A call to the method with an empty parameter map is ignored.resolveTemplates
in class UriBuilder
templateValues
- a map of URI template names and their values.encodeSlashInPath
- if true
, the slash ('/'
) characters
in template values will be encoded if the template
is placed in the URI path component, otherwise the slash
characters will not be encoded in path templates.IllegalArgumentException
- if the name-value map or any of the names or values
in the map is null
.public UriBuilder resolveTemplatesFromEncoded(Map<String,Object> templateValues) throws IllegalArgumentException
UriBuilder
UriBuilder
instance using supplied
name-value pairs.
All templates with their name matching one of the keys in the supplied map will be replaced
by the value in the supplied map. Values are converted to String
using
their toString()
method and are then encoded to match the
rules of the URI component to which they pertain. All % characters in
the stringified values that are not followed by two hexadecimal numbers
will be encoded.
A call to the method with an empty parameter map is ignored.resolveTemplatesFromEncoded
in class UriBuilder
templateValues
- a map of URI template names and their values.IllegalArgumentException
- if the name-value map or any of the names or values
in the map is null
.Copyright © 2016 JBoss by Red Hat. All rights reserved.