com.funambol.util
Class HttpTransportAgent

java.lang.Object
  extended by com.funambol.util.HttpTransportAgent
All Implemented Interfaces:
TransportAgent

public final class HttpTransportAgent
extends java.lang.Object
implements TransportAgent

Represents a HTTP client implementation


Nested Class Summary
protected  class HttpTransportAgent.ConnectionTimer
          This class is used (with a Timer) to monitor a connection and interrupt it if it hangs for more than command timeout.
 
Constructor Summary
HttpTransportAgent(java.lang.String requestURL, boolean compress, boolean forceCookies)
          Create a new HttpTransportAgent.
HttpTransportAgent(java.lang.String requestURL, java.lang.String userAgent, boolean compress, boolean forceCookies)
          Create a new HttpTransportAgent using the default charset.
HttpTransportAgent(java.lang.String requestURL, java.lang.String userAgent, java.lang.String charset, boolean compress, boolean forceCookies)
          Initialize a new HttpTransportAgent with a URL and a charset to use.
 
Method Summary
 void enableCompression(boolean enable)
          Enable the http "gzip" compression parameter usage
 java.lang.String getRequestContentType()
           
 java.lang.String getResponseDate()
          Get the last response date
 byte[] sendMessage(byte[] request)
          Send the http request and read the response.
 java.lang.String sendMessage(java.lang.String request)
          Send a message using the default (UTF-8) charset.
 java.lang.String sendMessage(java.lang.String request, java.lang.String charset)
          Send the http request specifying the required encoding charset for the http headers.
 void setAuthentication(HttpAuthentication newAuth)
          Set the authentication object to use to authenticate requests made with this transport agent.
 void setRequestContentType(java.lang.String type)
          Set the content type used for http requests
 void setRequestURL(java.lang.String requestURL)
          Set the request's url
 void setResendMessageOnErrors(boolean resendMessageOnErrors)
          Set if the messages should be resent in case of errors
 void setRetryOnWrite(int retryOnWrite)
          Set the number of http writing attempts
 void setThreshold(int threshold)
          Set the http "Size-Threshold" header parameter
 void setTimeoutConnection(long timeout)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpTransportAgent

public HttpTransportAgent(java.lang.String requestURL,
                          boolean compress,
                          boolean forceCookies)
Create a new HttpTransportAgent.

Parameters:
requestURL - is the url where to send the request; must not be null
compress - if true the http compression is enabled, disabled otherwise
forceCookies -

HttpTransportAgent

public HttpTransportAgent(java.lang.String requestURL,
                          java.lang.String userAgent,
                          boolean compress,
                          boolean forceCookies)
Create a new HttpTransportAgent using the default charset.

Parameters:
requestURL - is the url where to send the request; must not be null
userAgent - the user agent parameter to be filled into the http headers
compress - if true the http compression is enabled, disabled otherwise
forceCookies - if true sets http headers to force the use of cookies instead of Url Rewriting to manage the current http session.

HttpTransportAgent

public HttpTransportAgent(java.lang.String requestURL,
                          java.lang.String userAgent,
                          java.lang.String charset,
                          boolean compress,
                          boolean forceCookies)
Initialize a new HttpTransportAgent with a URL and a charset to use.

Parameters:
requestURL - must be non-null
userAgent - a string to be used as userAgent.
charset - a valid charset, the device charset is used by default.
Method Detail

sendMessage

public java.lang.String sendMessage(java.lang.String request)
                             throws CodedException
Send a message using the default (UTF-8) charset.

Specified by:
sendMessage in interface TransportAgent
Parameters:
requestURL - must be non-null
Returns:
String formatted http response
Throws:
CodedException - when the connection cannot be established with the server because the implementation tries to access a not existent url or when there are network coverage problems

sendMessage

public java.lang.String sendMessage(java.lang.String request,
                                    java.lang.String charset)
                             throws CodedException
Send the http request specifying the required encoding charset for the http headers. The response is therefore read and returned. Calls to this method are globally synchronized (synchronized on a static var) because the object does uses static variables that prevent multiple requests. The reason why static variables are used is that on some platforms, this is apparently the only way to get around some connectivity issues.

Specified by:
sendMessage in interface TransportAgent
Parameters:
request - the http request body
charset - the charset to be included into the http headers
Returns:
String formatted http response
Throws:
CodedException - when the connection cannot be established with the server because the implementation tries to access a not existent url or when there are network coverage problems

sendMessage

public byte[] sendMessage(byte[] request)
                   throws CodedException
Send the http request and read the response. if request.lenght is empty, a simple get is performed

Parameters:
request - the http request body
Returns:
byte[] raw http response
Throws:
CodedException - when the connection cannot be established with the server because the implementation tries to access a not existent url or when there are network coverage problems

enableCompression

public void enableCompression(boolean enable)
Enable the http "gzip" compression parameter usage

Parameters:
enable - enables "gzip" http header parameter to be written if true

setThreshold

public void setThreshold(int threshold)
Set the http "Size-Threshold" header parameter

Parameters:
threshold - is the "Size-Threshold" value to be added to http headers

setRequestURL

public void setRequestURL(java.lang.String requestURL)
Set the request's url

Specified by:
setRequestURL in interface TransportAgent
Parameters:
requestURL - the request's destination url

getResponseDate

public java.lang.String getResponseDate()
Get the last response date

Specified by:
getResponseDate in interface TransportAgent
Returns:
the last response date (String format), if available, null otherwise

setRequestContentType

public void setRequestContentType(java.lang.String type)
Set the content type used for http requests

Parameters:
type -

getRequestContentType

public java.lang.String getRequestContentType()
Returns:
the content type used for http requests

setRetryOnWrite

public void setRetryOnWrite(int retryOnWrite)
Set the number of http writing attempts

Specified by:
setRetryOnWrite in interface TransportAgent
Parameters:
retryOnWrite - the number of attempts to write http requests

setResendMessageOnErrors

public void setResendMessageOnErrors(boolean resendMessageOnErrors)
Set if the messages should be resent in case of errors


setTimeoutConnection

public void setTimeoutConnection(long timeout)

setAuthentication

public void setAuthentication(HttpAuthentication newAuth)
Set the authentication object to use to authenticate requests made with this transport agent.

Parameters:
HttpAuthentication - The authentication that contains the username, password, and uri to authenticate with.


Copyright © 2001-2009 Funambol.