net.rim.pushsdk.commons.http
Class HttpClientImpl

java.lang.Object
  extended by net.rim.pushsdk.commons.http.HttpClientImpl
All Implemented Interfaces:
HttpClient

public class HttpClientImpl
extends Object
implements HttpClient

Default implementation of the HttpClient interface. Uses the standard Java URL and HttpURLConnection classes.

Note: This class supports SSL URLs, but is only useful for TLS. All certificates will be trusted by default. If you wish to have certificate validation, you should create your own implementation that implements a TrustManager.

Dependencies that must be injected to properly initialize this object for use:
- pushSDKProperties

Author:
mdicesare

Field Summary
 
Fields inherited from interface net.rim.pushsdk.commons.http.HttpClient
BUFFER_SIZE, CHARACTER_ENCODING_SCHEMA
 
Constructor Summary
HttpClientImpl()
           
 
Method Summary
 void setPushSDKProperties(PushSDKProperties pushSDKProperties)
          Sets the push SDK properties to use with this HttpClient implementation.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpClientImpl

public HttpClientImpl()
Method Detail

setPushSDKProperties

public void setPushSDKProperties(PushSDKProperties pushSDKProperties)
Sets the push SDK properties to use with this HttpClient implementation.

Parameters:
pushSDKProperties - the push SDK properties

transmitPOST

public HttpResponse transmitPOST(String url,
                                 ByteArrayOutputStream payload,
                                 String contentType,
                                 String username,
                                 String password,
                                 HttpHeaderList headers)
                          throws MalformedURLException,
                                 SocketTimeoutException,
                                 IOException
Description copied from interface: HttpClient
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'

Specified by:
transmitPOST in interface HttpClient
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

public HttpResponse transmitGET(String url,
                                String contentType,
                                String username,
                                String password,
                                HttpHeaderList headers)
                         throws MalformedURLException,
                                SocketTimeoutException,
                                IOException
Description copied from interface: HttpClient
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'

Specified by:
transmitGET in interface HttpClient
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.