Class UrlUtils

    • Method Detail

      • extractParametersFromQueryString

        public static Map<String,​List<String>> extractParametersFromQueryString​(String queryString)
        For the given queryString, extract a mapping of query string parameter names to values.

        Example of a queryString is accessToken=123&expires=345.

        Parameters:
        queryString - The URL query string from which parameters are extracted.
        Returns:
        A mapping of query string parameter names to values. If queryString is null, an empty Map is returned.
        Throws:
        IllegalStateException - If unable to URL-decode because the JVM doesn't support StandardCharsets.UTF_8.
      • extractParametersFromUrl

        public static Map<String,​List<String>> extractParametersFromUrl​(String url)
        For the given url, extract a mapping of query string parameter names to values.

        Adapted from an implementation by BalusC and dfrankow, available at http://stackoverflow.com/questions/1667278/parsing-query-strings-in-java.

        Parameters:
        url - The URL from which parameters are extracted.
        Returns:
        A mapping of query string parameter names to values. If url is null, an empty Map is returned.
        Throws:
        IllegalStateException - If unable to URL-decode because the JVM doesn't support StandardCharsets.UTF_8.
      • replaceOrAddQueryParameter

        public static String replaceOrAddQueryParameter​(String url,
                                                        String key,
                                                        String value)
        Modify the query string in the given url and return the new url as String.

        The given key/value pair is added to the url. If the key is already present, it is replaced with the new value.

        Parameters:
        url - The URL which parameters should be modified.
        key - the key, that should be modified or added
        value - the value of the key/value pair
        Returns:
        the modified URL as String
      • removeQueryParameter

        public static String removeQueryParameter​(String url,
                                                  String key)
        Remove the given key from the url query string and return the new URL as String.
        Parameters:
        url - The URL from which parameters are extracted.
        key - the key, that should be removed
        Returns:
        the modified URL as String