Package org.apache.camel.util
Class URISupport
java.lang.Object
org.apache.camel.util.URISupport
URI utilities.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
appendParametersToURI
(String originalURI, Map<String, Object> newParameters) Appends the given parameters to the given URI.static String
buildMultiValueQuery
(String key, Iterable<Object> values) static String
createQueryString
(Collection<String> sortedKeys, Map<String, Object> options, boolean encode) Deprecated.static String
createQueryString
(Map<String, Object> options) Assembles a query from the given map.static String
createQueryString
(Map<String, Object> options, boolean encode) Assembles a query from the given map.static URI
createRemainingURI
(URI originalURI, Map<String, Object> params) Creates a URI from the original URI and the remaining parametersstatic URI
createURIWithQuery
(URI uri, String query) Creates a URI with the given queryextractProperties
(Map<String, Object> properties, String optionPrefix) static String
extractQuery
(String uri) Extracts the query part of the given uristatic String
extractRemainderPath
(URI u, boolean useRaw) Extracts the scheme specific path from the URI that is used as the remainder option when creating endpoints.static String
getDecodeQuery
(String uri) static boolean
Tests if the index is within any pair of the start and end indexes which represent the start and end positions of a RAW token.static String
static String
normalizeUri
(String uri) Normalizes the uri by reordering the parameters so they are sorted and thus we can use the uris for endpoint matching.parseParameters
(URI uri) Parses the query parameters of the uri (eg the query part).parseQuery
(String uri) Parses the query part of the uri (eg the parameters).parseQuery
(String uri, boolean useRaw) Parses the query part of the uri (eg the parameters).parseQuery
(String uri, boolean useRaw, boolean lenient) Parses the query part of the uri (eg the parameters).static String
pathAndQueryOf
(URI uri) static String
prepareQuery
(URI uri) static String
removeNoiseFromUri
(String uri) Remove whitespace noise from uri, xxxUri attributes, eg new lines, and tabs etc, which allows end users to format their Camel routes in more human-readable format, but at runtime those attributes must be trimmed.static void
resolveRawParameterValues
(Map<String, Object> parameters) Traverses the given parameters, and resolve any parameter values which uses the RAW token syntax: key=RAW(value).static String
sanitizePath
(String path) Removes detected sensitive information (such as passwords) from the path part of an URI (that is, the part without the query parameters or component prefix) and returns the result.static String
sanitizeUri
(String uri) Removes detected sensitive information (such as passwords) from the URI and returns the result.Scans RAW tokens in the string and returns the list of pair indexes which tell where a RAW token starts and ends in the string.static String
stripPrefix
(String value, String prefix) Strips the prefix from the value.static String
stripQuery
(String uri) Strips the query parameters from the uristatic String
stripSuffix
(String value, String suffix) Strips the suffix from the value.
-
Field Details
-
RAW_TOKEN_PREFIX
- See Also:
-
RAW_TOKEN_START
-
RAW_TOKEN_END
-
-
Method Details
-
sanitizeUri
Removes detected sensitive information (such as passwords) from the URI and returns the result.- Parameters:
uri
- The uri to sanitize.- Returns:
- Returns null if the uri is null, otherwise the URI with the passphrase, password or secretKey sanitized.
- See Also:
-
and #USERINFO_PASSWORD for the matched pattern
-
sanitizePath
Removes detected sensitive information (such as passwords) from the path part of an URI (that is, the part without the query parameters or component prefix) and returns the result.- Parameters:
path
- the URI path to sanitize- Returns:
- null if the path is null, otherwise the sanitized path
-
extractRemainderPath
Extracts the scheme specific path from the URI that is used as the remainder option when creating endpoints.- Parameters:
u
- the URIuseRaw
- whether to force using raw values- Returns:
- the remainder path
-
extractQuery
Extracts the query part of the given uri- Parameters:
uri
- the uri- Returns:
- the query parameters or null if the uri has no query
-
stripQuery
Strips the query parameters from the uri- Parameters:
uri
- the uri- Returns:
- the uri without the query parameter
-
parseQuery
Parses the query part of the uri (eg the parameters). The URI parameters will by default be URI encoded. However you can define a parameter values with the syntax: key=RAW(value) which tells Camel to not encode the value, and use the value as is (eg key=value) and the value has not been encoded.- Parameters:
uri
- the uri- Returns:
- the parameters, or an empty map if no parameters (eg never null)
- Throws:
URISyntaxException
- is thrown if uri has invalid syntax.- See Also:
-
parseQuery
Parses the query part of the uri (eg the parameters). The URI parameters will by default be URI encoded. However you can define a parameter values with the syntax: key=RAW(value) which tells Camel to not encode the value, and use the value as is (eg key=value) and the value has not been encoded.- Parameters:
uri
- the uriuseRaw
- whether to force using raw values- Returns:
- the parameters, or an empty map if no parameters (eg never null)
- Throws:
URISyntaxException
- is thrown if uri has invalid syntax.- See Also:
-
parseQuery
public static Map<String,Object> parseQuery(String uri, boolean useRaw, boolean lenient) throws URISyntaxException Parses the query part of the uri (eg the parameters). The URI parameters will by default be URI encoded. However you can define a parameter values with the syntax: key=RAW(value) which tells Camel to not encode the value, and use the value as is (eg key=value) and the value has not been encoded.- Parameters:
uri
- the uriuseRaw
- whether to force using raw valueslenient
- whether to parse lenient and ignore trailing & markers which has no key or value which can happen when using HTTP components- Returns:
- the parameters, or an empty map if no parameters (eg never null)
- Throws:
URISyntaxException
- is thrown if uri has invalid syntax.- See Also:
-
scanRaw
Scans RAW tokens in the string and returns the list of pair indexes which tell where a RAW token starts and ends in the string. This is a companion method withisRaw(int, List)
and the returned value is supposed to be used as the parameter of that method.- Parameters:
str
- the string to scan RAW tokens- Returns:
- the list of pair indexes which represent the start and end positions of a RAW token
- See Also:
-
isRaw
Tests if the index is within any pair of the start and end indexes which represent the start and end positions of a RAW token. This is a companion method withscanRaw(String)
and is supposed to consume the returned value of that method as the second parameter pairs.- Parameters:
index
- the index to be testedpairs
- the list of pair indexes which represent the start and end positions of a RAW token- Returns:
- true if the index is within any pair of the indexes, false otherwise
- See Also:
-
parseParameters
Parses the query parameters of the uri (eg the query part).- Parameters:
uri
- the uri- Returns:
- the parameters, or an empty map if no parameters (eg never null)
- Throws:
URISyntaxException
- is thrown if uri has invalid syntax.
-
prepareQuery
-
resolveRawParameterValues
Traverses the given parameters, and resolve any parameter values which uses the RAW token syntax: key=RAW(value). This method will then remove the RAW tokens, and replace the content of the value, with just the value.- Parameters:
parameters
- the uri parameters- See Also:
-
createURIWithQuery
Creates a URI with the given query- Parameters:
uri
- the uriquery
- the query to append to the uri- Returns:
- uri with the query appended
- Throws:
URISyntaxException
- is thrown if uri has invalid syntax.
-
stripPrefix
Strips the prefix from the value. Returns the value as-is if not starting with the prefix.- Parameters:
value
- the valueprefix
- the prefix to remove from value- Returns:
- the value without the prefix
-
stripSuffix
Strips the suffix from the value. Returns the value as-is if not ending with the prefix.- Parameters:
value
- the valuesuffix
- the suffix to remove from value- Returns:
- the value without the suffix
-
createQueryString
Assembles a query from the given map.- Parameters:
options
- the map with the options (eg key/value pairs)- Returns:
- a query string with key1=value&key2=value2&..., or an empty string if there is no options.
-
createQueryString
Assembles a query from the given map.- Parameters:
options
- the map with the options (eg key/value pairs)encode
- whether to URL encode the query string- Returns:
- a query string with key1=value&key2=value2&..., or an empty string if there is no options.
-
createQueryString
@Deprecated public static String createQueryString(Collection<String> sortedKeys, Map<String, Object> options, boolean encode) Deprecated. -
createRemainingURI
public static URI createRemainingURI(URI originalURI, Map<String, Object> params) throws URISyntaxExceptionCreates a URI from the original URI and the remaining parameters Used by various Camel components- Throws:
URISyntaxException
-
appendParametersToURI
public static String appendParametersToURI(String originalURI, Map<String, Object> newParameters) throws URISyntaxException, UnsupportedEncodingExceptionAppends the given parameters to the given URI. It keeps the original parameters and if a new parameter is already defined inoriginalURI
, it will be replaced by its value innewParameters
.- Parameters:
originalURI
- the original URInewParameters
- the parameters to add- Returns:
- the URI with all the parameters
- Throws:
URISyntaxException
- is thrown if the uri syntax is invalidUnsupportedEncodingException
- is thrown if encoding error
-
normalizeUri
public static String normalizeUri(String uri) throws URISyntaxException, UnsupportedEncodingException Normalizes the uri by reordering the parameters so they are sorted and thus we can use the uris for endpoint matching. The URI parameters will by default be URI encoded. However you can define a parameter values with the syntax: key=RAW(value) which tells Camel to not encode the value, and use the value as is (eg key=value) and the value has not been encoded.- Parameters:
uri
- the uri- Returns:
- the normalized uri
- Throws:
URISyntaxException
- in thrown if the uri syntax is invalidUnsupportedEncodingException
- is thrown if encoding error- See Also:
-
extractProperties
-
getDecodeQuery
-
pathAndQueryOf
-
joinPaths
-
buildMultiValueQuery
-
removeNoiseFromUri
Remove whitespace noise from uri, xxxUri attributes, eg new lines, and tabs etc, which allows end users to format their Camel routes in more human-readable format, but at runtime those attributes must be trimmed. The parser removes most of the noise, but keeps spaces in the attribute values
-