Class URISupport

    • 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:
        and #USERINFO_PASSWORD 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
      • extractRemainderPath

        public static String extractRemainderPath​(URI u,
                                                  boolean useRaw)
        Extracts the scheme specific path from the URI that is used as the remainder option when creating endpoints.
        Parameters:
        u - the URI
        useRaw - whether to force using raw values
        Returns:
        the remainder path
      • extractQuery

        public static String extractQuery​(String uri)
        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

        public static String stripQuery​(String uri)
        Strips the query parameters from the uri
        Parameters:
        uri - the uri
        Returns:
        the uri without the query parameter
      • parseQuery

        public static Map<String,​ObjectparseQuery​(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_PREFIX, RAW_TOKEN_START, RAW_TOKEN_END
      • parseQuery

        public static Map<String,​ObjectparseQuery​(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_PREFIX, RAW_TOKEN_START, RAW_TOKEN_END
      • parseQuery

        public static Map<String,​ObjectparseQuery​(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 uri
        useRaw - whether to force using raw values
        lenient - 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:
        RAW_TOKEN_PREFIX, RAW_TOKEN_START, RAW_TOKEN_END
      • scanRaw

        public static List<Pair<Integer>> scanRaw​(String str)
        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 with isRaw(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(int, List), RAW_TOKEN_PREFIX, RAW_TOKEN_START, RAW_TOKEN_END
      • isRaw

        public static boolean isRaw​(int index,
                                    List<Pair<Integer>> pairs)
        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 with scanRaw(String) and is supposed to consume the returned value of that method as the second parameter pairs.

        Parameters:
        index - the index to be tested
        pairs - 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:
        scanRaw(String), RAW_TOKEN_PREFIX, RAW_TOKEN_START, RAW_TOKEN_END
      • 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
      • stripSuffix

        public static String stripSuffix​(String value,
                                         String suffix)
        Strips the suffix from the value.

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

        Parameters:
        value - the value
        suffix - the suffix to remove from value
        Returns:
        the value without the suffix
      • 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.
      • createQueryString

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