org.brickred.socialauth.util
Class HttpUtil

java.lang.Object
  extended by org.brickred.socialauth.util.HttpUtil

public class HttpUtil
extends Object

This class is used to make HTTP requests. We did try NOT writing this class and instead use Apache Commons HTTP Client. However it has been reported by users that Commons HTTP Client does not work on Google AppEngine. Hence we have handcoded this class using HTTPURLConnection and incorporated only as much functionality as is needed for OAuth clients. This class may be completed rewritten in future, or may be removed if a version of Commons HTTP Client compatible with AppEngine is released.

Author:
tarunn@brickred.com

Constructor Summary
HttpUtil()
           
 
Method Summary
static String buildParams(Map<String,String> params)
          Generates a query string from given Map while sorting the parameters in the canonical order as required by oAuth before signing
static String decodeURIComponent(String encodedURI)
          It decodes the given string
static Response doHttpRequest(String urlStr, String requestMethod, Map<String,String> params, Map<String,String> header, InputStream inputStream, String fileName, String fileParamName)
           
static Response doHttpRequest(String urlStr, String requestMethod, String body, Map<String,String> header)
          Makes HTTP request using java.net.HTTPURLConnection
static String encodeURIComponent(String value)
           
static void setConnectionTimeout(int timeout)
          Sets the connection time out.
static void setProxyConfig(String host, int port)
          Sets the proxy host and port.
static void write(DataOutputStream out, String outStr)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpUtil

public HttpUtil()
Method Detail

doHttpRequest

public static Response doHttpRequest(String urlStr,
                                     String requestMethod,
                                     String body,
                                     Map<String,String> header)
                              throws Exception
Makes HTTP request using java.net.HTTPURLConnection

Parameters:
urlStr - the URL String
requestMethod - Method type
body - Body to pass in request.
header - Header parameters
Returns:
Response Object
Throws:
Exception

doHttpRequest

public static Response doHttpRequest(String urlStr,
                                     String requestMethod,
                                     Map<String,String> params,
                                     Map<String,String> header,
                                     InputStream inputStream,
                                     String fileName,
                                     String fileParamName)
                              throws Exception
Parameters:
urlStr - the URL String
requestMethod - Method type
params - Parameters to pass in request
header - Header parameters
inputStream - Input stream of image
fileName - Image file name
fileParamName - Image Filename parameter. It requires in some provider.
Returns:
Response object
Throws:
Exception

buildParams

public static String buildParams(Map<String,String> params)
                          throws Exception
Generates a query string from given Map while sorting the parameters in the canonical order as required by oAuth before signing

Parameters:
params - Parameters Map to generate query string
Returns:
String
Throws:
Exception

encodeURIComponent

public static String encodeURIComponent(String value)
                                 throws Exception
Throws:
Exception

decodeURIComponent

public static String decodeURIComponent(String encodedURI)
It decodes the given string

Parameters:
encodedURI -
Returns:
decoded string

setProxyConfig

public static void setProxyConfig(String host,
                                  int port)
Sets the proxy host and port. This will be implicitly called if "proxy.host" and "proxy.port" properties are given in properties file

Parameters:
host - proxy host
port - proxy port

setConnectionTimeout

public static void setConnectionTimeout(int timeout)
Sets the connection time out. This will be implicitly called if "http.connectionTimeOut" property is given in properties file

Parameters:
timeout - httpconnection timeout value

write

public static void write(DataOutputStream out,
                         String outStr)
                  throws IOException
Throws:
IOException


Copyright © 2013. All Rights Reserved.