Class URLUtils
- java.lang.Object
-
- com.nimbusds.oauth2.sdk.util.URLUtils
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static URL
getBaseURL(URL url)
Gets the base part (protocol, host, port and path) of the specified URL.static Map<String,List<String>>
parseParameters(String query)
Parses the specified URL query string into a parameter map.static String
serializeParameters(Map<String,List<String>> params)
Serialises the specified map of parameters into a URL query string.static String
serializeParametersAlt(Map<String,String[]> params)
Serialises the specified map of parameters into a URL query string.static URL
setEncodedFragment(URL url, String fragment)
Sets the encoded fragment of the specified URL.static URL
setEncodedQuery(URL url, String query)
Sets the encoded query of the specified URL.static Map<String,List<String>>
urlEncodeParameters(Map<String,List<String>> params)
Performsapplication/x-www-form-urlencoded
encoding on the specified parameter keys and values.
-
-
-
Field Detail
-
CHARSET
public static final String CHARSET
The default UTF-8 character set.- See Also:
- Constant Field Values
-
-
Method Detail
-
getBaseURL
public static URL getBaseURL(URL url)
Gets the base part (protocol, host, port and path) of the specified URL.- Parameters:
url
- The URL. May benull
.- Returns:
- The base part of the URL,
null
if the original URL isnull
or doesn't specify a protocol.
-
setEncodedQuery
public static URL setEncodedQuery(URL url, String query)
Sets the encoded query of the specified URL.- Parameters:
url
- The URL. May benull
.query
- The encoded query,null
if not specified.- Returns:
- The new URL.
-
setEncodedFragment
public static URL setEncodedFragment(URL url, String fragment)
Sets the encoded fragment of the specified URL.- Parameters:
url
- The URL. May benull
.fragment
- The encoded fragment,null
if not specified.- Returns:
- The new URL.
-
urlEncodeParameters
public static Map<String,List<String>> urlEncodeParameters(Map<String,List<String>> params)
Performsapplication/x-www-form-urlencoded
encoding on the specified parameter keys and values.- Parameters:
params
- A map of the parameters. May be empty ornull
.- Returns:
- The encoded parameters,
null
if not specified.
-
serializeParameters
public static String serializeParameters(Map<String,List<String>> params)
Serialises the specified map of parameters into a URL query string. The parameter keys and values areapplication/x-www-form-urlencoded
encoded.Parameters with
null
keys or values are ignored and not serialised.Note that the '?' character preceding the query string in GET requests is not included in the returned string.
Example query string:
response_type=code &client_id=s6BhdRkqt3 &state=xyz &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb
The opposite method is
parseParameters(java.lang.String)
.- Parameters:
params
- A map of the URL query parameters. May be empty ornull
.- Returns:
- The serialised URL query string, empty if no parameters.
-
serializeParametersAlt
public static String serializeParametersAlt(Map<String,String[]> params)
Serialises the specified map of parameters into a URL query string. Supports multiple key / value pairs that have the same key. The parameter keys and values areapplication/x-www-form-urlencoded
encoded.Parameters with
null
keys or values are ignored and not serialised.Note that the '?' character preceding the query string in GET requests is not included in the returned string.
Example query string:
response_type=code &client_id=s6BhdRkqt3 &state=xyz &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb
The opposite method is
parseParameters(java.lang.String)
.- Parameters:
params
- A map of the URL query parameters. May be empty ornull
.- Returns:
- The serialised URL query string, empty if no parameters.
-
parseParameters
public static Map<String,List<String>> parseParameters(String query)
Parses the specified URL query string into a parameter map. If a parameter has multiple values only the first one will be saved. The parameter keys and values areapplication/x-www-form-urlencoded
decoded.Note that the '?' character preceding the query string in GET requests must not be included.
Example query string:
response_type=code &client_id=s6BhdRkqt3 &state=xyz &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb
The opposite method
serializeParameters(java.util.Map<java.lang.String, java.util.List<java.lang.String>>)
.- Parameters:
query
- The URL query string to parse. May benull
.- Returns:
- A map of the URL query parameters, empty if none are found.
-
-