Class OAuth

java.lang.Object
oauth.signpost.OAuth

public class OAuth extends Object
  • Field Details

  • Constructor Details

    • OAuth

      public OAuth()
  • Method Details

    • percentEncode

      public static String percentEncode(String s)
    • percentDecode

      public static String percentDecode(String s)
    • formEncode

      public static <T extends Map.Entry<String, String>> void formEncode(Collection<T> parameters, OutputStream into) throws IOException
      Construct a x-www-form-urlencoded document containing the given sequence of name/value pairs. Use OAuth percent encoding (not exactly the encoding mandated by x-www-form-urlencoded).
      Throws:
      IOException
    • formEncode

      public static <T extends Map.Entry<String, String>> String formEncode(Collection<T> parameters) throws IOException
      Construct a x-www-form-urlencoded document containing the given sequence of name/value pairs. Use OAuth percent encoding (not exactly the encoding mandated by x-www-form-urlencoded).
      Throws:
      IOException
    • decodeForm

      public static HttpParameters decodeForm(String form)
      Parse a form-urlencoded document.
    • decodeForm

      public static HttpParameters decodeForm(InputStream content) throws IOException
      Throws:
      IOException
    • toMap

      public static <T extends Map.Entry<String, String>> Map<String,String> toMap(Collection<T> from)
      Construct a Map containing a copy of the given parameters. If several parameters have the same name, the Map will contain the first value, only.
    • safeToString

      public static final String safeToString(Object from)
    • isEmpty

      public static boolean isEmpty(String str)
    • addQueryParameters

      public static String addQueryParameters(String url, String... kvPairs)
      Appends a list of key/value pairs to the given URL, e.g.:
       String url = OAuth.addQueryParameters("http://example.com?a=1", b, 2, c, 3);
       
      which yields:
       http://example.com?a=1invalid input: '&b'=2invalid input: '&c'=3
       
      All parameters will be encoded according to OAuth's percent encoding rules.
      Parameters:
      url - the URL
      kvPairs - the list of key/value pairs
      Returns:
    • addQueryParameters

      public static String addQueryParameters(String url, Map<String,String> params)
    • addQueryString

      public static String addQueryString(String url, String queryString)
    • prepareOAuthHeader

      public static String prepareOAuthHeader(String... kvPairs)
      Builds an OAuth header from the given list of header fields. All parameters starting in 'oauth_*' will be percent encoded.
       String authHeader = OAuth.prepareOAuthHeader("realm", "http://example.com", "oauth_token", "x%y");
       
      which yields:
       OAuth realm="http://example.com", oauth_token="x%25y"
       
      Parameters:
      kvPairs - the list of key/value pairs
      Returns:
      a string eligible to be used as an OAuth HTTP Authorization header.
    • oauthHeaderToParamsMap

      public static HttpParameters oauthHeaderToParamsMap(String oauthHeader)
    • toHeaderElement

      public static String toHeaderElement(String name, String value)
      Helper method to concatenate a parameter and its value to a pair that can be used in an HTTP header. This method percent encodes both parts before joining them.
      Parameters:
      name - the OAuth parameter name, e.g. oauth_token
      value - the OAuth parameter value, e.g. 'hello oauth'
      Returns:
      a name/value pair, e.g. oauth_token="hello%20oauth"
    • debugOut

      public static void debugOut(String key, String value)