Class HttpParameters

  • All Implemented Interfaces:
    Serializable, Map<String,​SortedSet<String>>

    public class HttpParameters
    extends Object
    implements Map<String,​SortedSet<String>>, Serializable
    A multi-map of HTTP request parameters. Each key references a SortedSet of parameters collected from the request during message signing. Parameter values are sorted as per ://oauth.net/core/1.0a/#anchor13. Every key/value pair will be percent-encoded upon insertion. This class has special semantics tailored to being useful for message signing; it's not a general purpose collection class to handle request parameters.
    Author:
    Matthias Kaeppler
    See Also:
    Serialized Form
    • Constructor Detail

      • HttpParameters

        public HttpParameters()
    • Method Detail

      • put

        public String put​(String key,
                          String value)
        Convenience method to add a single value for the parameter specified by 'key'.
        Parameters:
        key - the parameter name
        value - the parameter value
        Returns:
        the value
      • put

        public String put​(String key,
                          String value,
                          boolean percentEncode)
        Convenience method to add a single value for the parameter specified by 'key'.
        Parameters:
        key - the parameter name
        value - the parameter value
        percentEncode - whether key and value should be percent encoded before being inserted into the map
        Returns:
        the value
      • putAll

        public void putAll​(String[] keyValuePairs,
                           boolean percentEncode)
      • putMap

        public void putMap​(Map<String,​List<String>> m)
        Convenience method to merge a Map>.
        Parameters:
        m - the map
      • getFirst

        public String getFirst​(Object key)
        Convenience method for {@link #getFirst(key, false)}.
        Parameters:
        key - the parameter name (must be percent encoded if it contains unsafe characters!)
        Returns:
        the first value found for this parameter
      • getFirst

        public String getFirst​(Object key,
                               boolean percentDecode)
        Returns the first value from the set of all values for the given parameter name. If the key passed to this method contains special characters, you MUST first percent encode it using OAuth.percentEncode(String), otherwise the lookup will fail (that's because upon storing values in this map, keys get percent-encoded).
        Parameters:
        key - the parameter name (must be percent encoded if it contains unsafe characters!)
        percentDecode - whether the value being retrieved should be percent decoded
        Returns:
        the first value found for this parameter
      • getAsQueryString

        public String getAsQueryString​(Object key)
        Concatenates all values for the given key to a list of key/value pairs suitable for use in a URL query string.
        Parameters:
        key - the parameter name
        Returns:
        the query string
      • getAsQueryString

        public String getAsQueryString​(Object key,
                                       boolean percentEncode)
        Concatenates all values for the given key to a list of key/value pairs suitable for use in a URL query string.
        Parameters:
        key - the parameter name
        percentEncode - whether key should be percent encoded before being used with the map
        Returns:
        the query string
      • getAsHeaderElement

        public String getAsHeaderElement​(String key)