twitter4j.http
Class HttpClient

java.lang.Object
  extended by twitter4j.http.HttpClient
All Implemented Interfaces:
java.io.Serializable

public class HttpClient
extends java.lang.Object
implements java.io.Serializable

A utility class to handle HTTP request/response.

Author:
Yusuke Yamamoto - yusuke at mac.com
See Also:
Serialized Form

Field Summary
private static int BAD_GATEWAY
           
private static int BAD_REQUEST
           
private  int connectionTimeout
           
static int EXCEEDED_RATE_LIMIT_QUOTA
           
private static int FORBIDDEN
           
private static java.util.Map<HttpClientConfiguration,HttpClient> instanceMap
           
private static int INTERNAL_SERVER_ERROR
           
private static boolean isJDK14orEarlier
           
private static Logger logger
           
private static int NOT_ACCEPTABLE
           
private static int NOT_AUTHORIZED
           
private static int NOT_FOUND
           
private static int NOT_MODIFIED
           
private static int OK
           
private  java.lang.String proxyAuthPassword
           
private  java.lang.String proxyAuthUser
           
private  java.lang.String proxyHost
           
private  int proxyPort
           
private  int readTimeout
           
private  int retryCount
           
private  int retryIntervalSeconds
           
private static long serialVersionUID
           
static int SERVICE_UNAVAILABLE
           
 
Constructor Summary
HttpClient()
           
HttpClient(HttpClientConfiguration conf)
           
 
Method Summary
static java.lang.String encode(java.lang.String str)
           
 boolean equals(java.lang.Object o)
           
 HttpResponse get(java.lang.String url)
           
private static java.lang.String getCause(int statusCode)
           
private  java.net.HttpURLConnection getConnection(java.lang.String url)
           
 int getConnectionTimeout()
           
static HttpClient getInstance(HttpClientConfiguration conf)
           
 java.lang.String getProxyAuthPassword()
           
 java.lang.String getProxyAuthUser()
           
 java.lang.String getProxyHost()
           
 int getProxyPort()
           
 int getReadTimeout()
           
 int hashCode()
           
 HttpResponse post(java.lang.String url, HttpParameter[] params)
           
 HttpResponse request(HttpRequest req)
           
 void setConnectionTimeout(int connectionTimeout)
          Sets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced by this URLConnection.
private  void setHeaders(HttpRequest req, java.net.HttpURLConnection connection)
          sets HTTP headers
 void setProxyAuthPassword(java.lang.String proxyAuthPassword)
          Sets proxy authentication password.
 void setProxyAuthUser(java.lang.String proxyAuthUser)
          Sets proxy authentication user.
 void setProxyHost(java.lang.String proxyHost)
          Sets proxy host.
 void setProxyPort(int proxyPort)
          Sets proxy port.
 void setReadTimeout(int readTimeout)
          Sets the read timeout to a specified timeout, in milliseconds.
 void setRetryCount(int retryCount)
           
 void setRetryIntervalSeconds(int retryIntervalSeconds)
           
private  void write(java.io.DataOutputStream out, java.lang.String outStr)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final Logger logger

OK

private static final int OK
See Also:
Constant Field Values

NOT_MODIFIED

private static final int NOT_MODIFIED
See Also:
Constant Field Values

BAD_REQUEST

private static final int BAD_REQUEST
See Also:
Constant Field Values

NOT_AUTHORIZED

private static final int NOT_AUTHORIZED
See Also:
Constant Field Values

FORBIDDEN

private static final int FORBIDDEN
See Also:
Constant Field Values

NOT_FOUND

private static final int NOT_FOUND
See Also:
Constant Field Values

NOT_ACCEPTABLE

private static final int NOT_ACCEPTABLE
See Also:
Constant Field Values

EXCEEDED_RATE_LIMIT_QUOTA

public static final int EXCEEDED_RATE_LIMIT_QUOTA
See Also:
Search API: new HTTP response code 420 for rate limiting starting 1/18/2010, Constant Field Values

INTERNAL_SERVER_ERROR

private static final int INTERNAL_SERVER_ERROR
See Also:
Constant Field Values

BAD_GATEWAY

private static final int BAD_GATEWAY
See Also:
Constant Field Values

SERVICE_UNAVAILABLE

public static final int SERVICE_UNAVAILABLE
See Also:
Constant Field Values

proxyHost

private java.lang.String proxyHost

proxyPort

private int proxyPort

proxyAuthUser

private java.lang.String proxyAuthUser

proxyAuthPassword

private java.lang.String proxyAuthPassword

connectionTimeout

private int connectionTimeout

readTimeout

private int readTimeout

retryCount

private int retryCount

retryIntervalSeconds

private int retryIntervalSeconds

isJDK14orEarlier

private static boolean isJDK14orEarlier

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

instanceMap

private static final java.util.Map<HttpClientConfiguration,HttpClient> instanceMap
Constructor Detail

HttpClient

public HttpClient()

HttpClient

public HttpClient(HttpClientConfiguration conf)
Method Detail

getInstance

public static HttpClient getInstance(HttpClientConfiguration conf)

getProxyHost

public java.lang.String getProxyHost()

setProxyHost

public void setProxyHost(java.lang.String proxyHost)
Sets proxy host.

Parameters:
proxyHost -

getProxyPort

public int getProxyPort()

setProxyPort

public void setProxyPort(int proxyPort)
Sets proxy port.

Parameters:
proxyPort -

getProxyAuthUser

public java.lang.String getProxyAuthUser()

setProxyAuthUser

public void setProxyAuthUser(java.lang.String proxyAuthUser)
Sets proxy authentication user. System property -Dtwitter4j.http.proxyUser overrides this attribute.

Parameters:
proxyAuthUser -

getProxyAuthPassword

public java.lang.String getProxyAuthPassword()

setProxyAuthPassword

public void setProxyAuthPassword(java.lang.String proxyAuthPassword)
Sets proxy authentication password. System property -Dtwitter4j.http.proxyPassword overrides this attribute.

Parameters:
proxyAuthPassword -

getConnectionTimeout

public int getConnectionTimeout()

setConnectionTimeout

public void setConnectionTimeout(int connectionTimeout)
Sets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced by this URLConnection.

Parameters:
connectionTimeout - - an int that specifies the connect timeout value in milliseconds

getReadTimeout

public int getReadTimeout()

setReadTimeout

public void setReadTimeout(int readTimeout)
Sets the read timeout to a specified timeout, in milliseconds.

Parameters:
readTimeout - - an int that specifies the timeout value to be used in milliseconds

setRetryCount

public void setRetryCount(int retryCount)

setRetryIntervalSeconds

public void setRetryIntervalSeconds(int retryIntervalSeconds)

get

public HttpResponse get(java.lang.String url)
                 throws TwitterException
Throws:
TwitterException

post

public HttpResponse post(java.lang.String url,
                         HttpParameter[] params)
                  throws TwitterException
Throws:
TwitterException

request

public HttpResponse request(HttpRequest req)
                     throws TwitterException
Throws:
TwitterException

write

private void write(java.io.DataOutputStream out,
                   java.lang.String outStr)
            throws java.io.IOException
Throws:
java.io.IOException

encode

public static java.lang.String encode(java.lang.String str)

setHeaders

private void setHeaders(HttpRequest req,
                        java.net.HttpURLConnection connection)
sets HTTP headers

Parameters:
req - The request
connection - HttpURLConnection

getConnection

private java.net.HttpURLConnection getConnection(java.lang.String url)
                                          throws java.io.IOException
Throws:
java.io.IOException

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getCause

private static java.lang.String getCause(int statusCode)