org.apache.camel.util
Class URISupport

java.lang.Object
  extended by org.apache.camel.util.URISupport

public final class URISupport
extends Object

URI utilities.

Version:

Field Summary
static String RAW_TOKEN_END
           
static String RAW_TOKEN_START
           
 
Method Summary
static String createQueryString(Map<String,Object> options)
          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 parameters

Used by various Camel components

static URI createURIWithQuery(URI uri, String query)
          Creates a URI with the given query
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.
static Map<String,Object> parseParameters(URI uri)
          Parses the query parameters of the uri (eg the query part).
static Map<String,Object> parseQuery(String uri)
          Parses the query part of the uri (eg the parameters).
static Map<String,Object> parseQuery(String uri, boolean useRaw)
          Parses the query part of the uri (eg the parameters).
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.
static String stripPrefix(String value, String prefix)
          Strips the prefix from the value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RAW_TOKEN_START

public static final String RAW_TOKEN_START
See Also:
Constant Field Values

RAW_TOKEN_END

public static final String RAW_TOKEN_END
See Also:
Constant Field Values
Method Detail

sanitizeUri

public static String sanitizeUri(String uri)
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:
for the matched pattern

sanitizePath

public 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.

Parameters:
path - the URI path to sanitize
Returns:
null if the path is null, otherwise the sanitized path

parseQuery

public static Map<String,Object> parseQuery(String uri)
                                     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 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:
RAW_TOKEN_START, RAW_TOKEN_END

parseQuery

public static Map<String,Object> parseQuery(String uri,
                                            boolean useRaw)
                                     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 uri
useRaw - 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:
RAW_TOKEN_START, RAW_TOKEN_END

parseParameters

public static Map<String,Object> parseParameters(URI uri)
                                          throws URISyntaxException
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.

resolveRawParameterValues

public 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). 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:
parseQuery(String), RAW_TOKEN_START, RAW_TOKEN_END

createURIWithQuery

public static URI createURIWithQuery(URI uri,
                                     String query)
                              throws URISyntaxException
Creates a URI with the given query

Parameters:
uri - the uri
query - the query to append to the uri
Returns:
uri with the query appended
Throws:
URISyntaxException - is thrown if uri has invalid syntax.

stripPrefix

public static String stripPrefix(String value,
                                 String prefix)
Strips the prefix from the value.

Returns the value as-is if not starting with the prefix.

Parameters:
value - the value
prefix - the prefix to remove from value
Returns:
the value without the prefix

createQueryString

public static String createQueryString(Map<String,Object> options)
                                throws URISyntaxException
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.
Throws:
URISyntaxException - is thrown if uri has invalid syntax.

createRemainingURI

public static URI createRemainingURI(URI originalURI,
                                     Map<String,Object> params)
                              throws URISyntaxException
Creates a URI from the original URI and the remaining parameters

Used by various Camel components

Throws:
URISyntaxException

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 invalid
UnsupportedEncodingException - is thrown if encoding error
See Also:
RAW_TOKEN_START, RAW_TOKEN_END


Apache Camel