public final class Uris extends Object
Modifier and Type | Method and Description |
---|---|
static URI |
appendQuery(URI uri,
Form query)
Returns a new URI with the given query parameters appended to the original
ones, if any.
|
static URI |
create(String scheme,
String rawUserInfo,
String host,
int port,
String rawPath,
String rawQuery,
String rawFragment)
Returns a hierarchical URI constructed from the given components.
|
static URI |
createNonStrict(String scheme,
String rawUserInfo,
String host,
int port,
String rawPath,
String rawQuery,
String rawFragment)
Returns a hierarchical URI constructed from the given components.
|
static URI |
createUri(String scheme,
String rawUserInfo,
String hostname,
int port,
String rawPath,
String rawQueryString,
String rawFragment,
boolean preserveOriginalQueryString)
Create a new URI given all provided URI components, query string can be strictly processed or not.
|
static String |
formDecodeParameterNameOrValue(String nameOrValue)
Decodes the provided form encoded parameter name or value as per application/x-www-form-urlencoded.
|
static String |
formEncodeParameterNameOrValue(String nameOrValue)
Form encodes the provided parameter name or value as per application/x-www-form-urlencoded.
|
static URI |
rebase(URI uri,
URI base)
Changes the base scheme, host and port of a request to that specified in a base URI,
or leaves them unchanged if the base URI is
null . |
static String |
urlDecodeFragment(String fragment)
Decodes the provided URL encoded fragment as per RFC 3986.
|
static String |
urlDecodePathElement(String pathElement)
Decodes the provided URL encoded path element as per RFC 3986.
|
static String |
urlDecodeQueryParameterNameOrValue(String nameOrValue)
Decodes the provided URL encoded query parameter name or value as per RFC 3986.
|
static String |
urlDecodeUserInfo(String userInfo)
Decodes the provided URL encoded userInfo as per RFC 3986.
|
static String |
urlEncodeFragment(String fragment)
URL encodes the provided fragment as per RFC 3986.
|
static String |
urlEncodePathElement(String pathElement)
URL encodes the provided path element as per RFC 3986.
|
static String |
urlEncodeQueryParameterNameOrValue(String nameOrValue)
URL encodes the provided query parameter name or value as per RFC 3986.
|
static String |
urlEncodeUserInfo(String userInfo)
URL encodes the provided userInfo as per RFC 3986.
|
static URI |
withoutQueryAndFragment(URI uri)
Returns a new URI having the same scheme, authority and path, but no
query nor fragment.
|
static URI |
withQuery(URI uri,
Form query)
Returns a new URI having the provided query parameters.
|
public static URI create(String scheme, String rawUserInfo, String host, int port, String rawPath, String rawQuery, String rawFragment) throws URISyntaxException
Unlike createNonStrict(java.lang.String, java.lang.String, java.lang.String, int, java.lang.String, java.lang.String, java.lang.String)
, this method does not tolerate invalid characters, such
as double-quotes, in the query string.
scheme
- the scheme component of the URI or null
if none.rawUserInfo
- the raw user-information component of the URI or null
if none.host
- the host component of the URI or null
if none.port
- the port number of the URI or -1
if none.rawPath
- the raw path component of the URI or null
if none.rawQuery
- the raw query component of the URI or null
if none. The raw query must not contain
characters that should have been percent encoded.rawFragment
- the raw fragment component of the URI or null
if none.URISyntaxException
- if the resulting URI would be malformed per RFC 2396.public static URI createNonStrict(String scheme, String rawUserInfo, String host, int port, String rawPath, String rawQuery, String rawFragment) throws URISyntaxException
Unlike create(java.lang.String, java.lang.String, java.lang.String, int, java.lang.String, java.lang.String, java.lang.String)
, this method tolerates invalid characters, such as double-quotes,
in the query string.
scheme
- the scheme component of the URI or null
if none.rawUserInfo
- the raw user-information component of the URI or null
if none.host
- the host component of the URI or null
if none.port
- the port number of the URI or -1
if none.rawPath
- the raw path component of the URI or null
if none.rawQuery
- the raw query component of the URI or null
if none. The raw query may contain
characters that should have been percent encoded.rawFragment
- the raw fragment component of the URI or null
if none.URISyntaxException
- if the resulting URI would be malformed per RFC 2396.public static URI rebase(URI uri, URI base)
null
. This implementation only
uses scheme, host and port. The remaining components of the URI remain intact.uri
- the URI whose base is to be changed.base
- the URI to base the other URI on.public static URI withQuery(URI uri, Form query)
uri
- the URI whose query is to be changed.query
- the form containing the query parameters.public static URI withoutQueryAndFragment(URI uri)
uri
- the URI whose query and fragments are to be removed.public static String formDecodeParameterNameOrValue(String nameOrValue)
nameOrValue
- the form encoded parameter name or value, which may be null
.null
if nameOrValue
was null
.public static String formEncodeParameterNameOrValue(String nameOrValue)
nameOrValue
- the parameter name or value, which may be null
.null
if nameOrValue
was null
.public static String urlDecodePathElement(String pathElement)
pathElement
- the URL encoded path element, which may be null
.null
if pathElement
was null
.public static String urlEncodePathElement(String pathElement)
pathElement
- the path element, which may be null
.null
if pathElement
was null
.public static String urlDecodeQueryParameterNameOrValue(String nameOrValue)
nameOrValue
- the URL encoded query parameter name or value, which may be null
.null
if nameOrValue
was null
.public static String urlEncodeQueryParameterNameOrValue(String nameOrValue)
nameOrValue
- the query parameter name or value, which may be null
.null
if nameOrValue
was null
.public static String urlDecodeFragment(String fragment)
fragment
- the URL encoded fragment, which may be null
.null
if fragment
was null
.public static String urlEncodeFragment(String fragment)
fragment
- the fragment, which may be null
.null
if fragment
was null
.public static String urlDecodeUserInfo(String userInfo)
userInfo
- the URL encoded userInfo, which may be null
.null
if userInfo
was null
.public static String urlEncodeUserInfo(String userInfo)
userInfo
- the userInfo, which may be null
.null
if userInfo
was null
.public static URI appendQuery(URI uri, Form query)
uri
- The URI whose query is to be changed, not null
.query
- The form containing the query parameters to add.public static URI createUri(String scheme, String rawUserInfo, String hostname, int port, String rawPath, String rawQueryString, String rawFragment, boolean preserveOriginalQueryString) throws URISyntaxException
If preserveOriginalQueryString
set to false
(the default), invalid chars are actively
percent-encoded.
Note that active percent-encoding has side effect: we execute a decode/encode round-trip, therefore
percent-encoded chars (in the original query) may not stay untouched (if they not strictly require
percent-encoding as per RFC-3986).
If set to true
, query string is preserved, but if it contains invalid characters, CHF will
reject the request with a Bad Request error response.
scheme
- URI schemerawUserInfo
- URI raw user infohostname
- URI host nameport
- URI port (can be -1 for default port)rawPath
- URI raw pathrawQueryString
- URI raw query stringrawFragment
- URI raw query stringpreserveOriginalQueryString
- preserve query strings (strict) or tolerate invalid charsURISyntaxException
- if the URI cannot be build (invalid chars, ...)Copyright 2011-2017 ForgeRock AS.