net.rim.pushsdk.commons.http
Interface HttpClient

All Known Implementing Classes:
HttpClientImpl

public interface HttpClient

Interface defining operations to enable transmitting HTTP GET and HTTP POST requests and returning the corresponding HTTP response.

Author:
mdicesare

Field Summary
static int BUFFER_SIZE
          Size of the byte buffer (1024 bytes) used for reading data chunks of data from an HTTP input stream.
static String CHARACTER_ENCODING_SCHEMA
          Character encoding schema used to convert response body bytes (UTF-8) to String.
 
Method Summary
 HttpResponse transmitGET(String url, String contentType, String username, String password, HttpHeaderList headers)
          Performs the HTTP GET of the URL and returns the corresponding response message.
 HttpResponse transmitPOST(String url, ByteArrayOutputStream payload, String contentType, String username, String password, HttpHeaderList headers)
          Performs the HTTP POST of the request message and returns the corresponding response message.
 

Field Detail

CHARACTER_ENCODING_SCHEMA

static final String CHARACTER_ENCODING_SCHEMA
Character encoding schema used to convert response body bytes (UTF-8) to String.

See Also:
Constant Field Values

BUFFER_SIZE

static final int BUFFER_SIZE
Size of the byte buffer (1024 bytes) used for reading data chunks of data from an HTTP input stream.

See Also:
Constant Field Values
Method Detail

transmitPOST

HttpResponse transmitPOST(String url,
                          ByteArrayOutputStream payload,
                          String contentType,
                          String username,
                          String password,
                          HttpHeaderList headers)
                          throws MalformedURLException,
                                 SocketTimeoutException,
                                 IOException
Performs the HTTP POST of the request message and returns the corresponding response message.

Note: This method will use the values for the connection timeout, read timeout, and keep alive persistent connections specified by the push SDK properties for the HTTP client.

Headers automatically set by this method (any will be overridden if the same header name is in the headers parameter):
Content-Type - set to have a value of: the value of the contentType parameter
Content-Length - set to have a value of: the size of the payLoad in bytes
User-Agent - set to have a value of: 'Push Service SDK/' (e.g. Push Service SDK/1.1)
Authorization - Optional, only if a username and password are specified - set to have a value of: 'Basic username:password' base64 encoded
Connection - Optional, only if http.is.persistent=false in the PushSDK.properties file - set to have a value of: 'close'

Parameters:
url - the URL to send the request to
payload - the request to send
contentType - the type of content being transmitted; will be set as a 'Content-Type' HTTP header (if the headers parameter has a header with a name Content-Type this value will be overridden)
username - the user name for authentication
password - the password for authentication
headers - Any additional custom headers that will overwrite any default headers. Can be null, or zero or more HTTP headers to include with the POST.
Returns:
the response from the HTTP POST; callers should check the response status code
Throws:
MalformedURLException - if the URL specified is malformed
SocketTimeoutException - if the timeout expires before the connection can be established; it can also be thrown when reading from the returned input stream if the read timeout expires before data is available to be read
IOException - if any IO errors occur

transmitGET

HttpResponse transmitGET(String url,
                         String contentType,
                         String username,
                         String password,
                         HttpHeaderList headers)
                         throws MalformedURLException,
                                SocketTimeoutException,
                                IOException
Performs the HTTP GET of the URL and returns the corresponding response message.

Note: This method will use the values for the connection timeout, read timeout, and keep alive persistent connections specified by the push SDK properties for the HTTP client.

Headers automatically set by this method (any will be overridden if the same header name is in the headers parameter):
Content-Type - set to have a value of: the value of the contentType parameter
User-Agent - set to have a value of: 'Push Service SDK/' (e.g. Push Service SDK/1.1)
Authorization - Optional, only if a username and password are specified - set to have a value of: 'Basic username:password' base64 encoded
Connection - Optional, only if http.is.persistent=false in the PushSDK.properties file - set to have a value of: 'close'

Parameters:
url - the URL to send the request to
contentType - the type of content being transmitted; will be set as a 'Content-Type' HTTP header (if the headers parameter has a header with a name Content-Type this value will be overridden)
username - the user name for authentication
password - the password for authentication
headers - Any additional custom headers that will overwrite any default headers. Can be null, or zero or more HTTP headers to include with the GET.
Returns:
the response from the HTTP GET; callers should check the response code
Throws:
MalformedURLException - if the URL specified is malformed
SocketTimeoutException - if the timeout expires before the connection can be established; it can also be thrown when reading from the returned input stream if the read timeout expires before data is available to be read
IOException - if any IO errors occur


Copyright © 2011 Research In Motion. All Rights Reserved.