com.nativex.advertiser
Class HttpConnectionManager

java.lang.Object
  extended by com.nativex.advertiser.HttpConnectionManager

public class HttpConnectionManager
extends Object


Constructor Summary
HttpConnectionManager()
           
 
Method Summary
private  BasicHttpResponse executePost(ClientConnectionManager mgr, HttpPost httpPost)
          Executed a post request.
 String executeServerRequest(String url, String request)
          Method performing HttpClient operations for sending and receiving requests
private  ClientConnectionManager getConnectionManager()
          Implements ClientConnectionManager instance.
private  KeyStore getDefaultKeyStore()
          Accesses the default keystore.
 HttpClient getHttpClient()
           
private  StringBuilder getResponseAsString(BasicHttpResponse response)
          Converts the response to string.
private  SSLSocketFactory getSSLSocketFactory(KeyStore keystore)
          Provides the necessary SSL connection factory.
private  HttpPost populatePost(String url, String request)
          Creates the post object and populates the headers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpConnectionManager

public HttpConnectionManager()
Method Detail

getDefaultKeyStore

private KeyStore getDefaultKeyStore()
Accesses the default keystore.

Returns:
KeyStore. The keystore.

getSSLSocketFactory

private SSLSocketFactory getSSLSocketFactory(KeyStore keystore)
Provides the necessary SSL connection factory.

Parameters:
keystore - KeyStore. A keystore to use for the SSL connection factory.
Returns:
SSLSocketFactory. The SSL connection factory.

populatePost

private HttpPost populatePost(String url,
                              String request)
Creates the post object and populates the headers.


executePost

private BasicHttpResponse executePost(ClientConnectionManager mgr,
                                      HttpPost httpPost)
                               throws ClientProtocolException,
                                      IOException
Executed a post request.

Parameters:
mgr - ClientConnectionManager. The connection manager.
httpPost - HttpPost. The request.
Returns:
BasicHttpResponse. The response from the server for the post request.
Throws:
ClientProtocolException - The HttpClient can throw this exception.
IOException - The HttpClient can throw this exception.

getHttpClient

public HttpClient getHttpClient()

getResponseAsString

private StringBuilder getResponseAsString(BasicHttpResponse response)
                                   throws IllegalStateException,
                                          IOException
Converts the response to string.

Parameters:
response - BasicHttpResponse. The response.
Returns:
String. The string representation of the response.
Throws:
IllegalStateException - Could be thrown when reading the response InputStream.
IOException - Could be thrown when reading the response InputStream.

getConnectionManager

private ClientConnectionManager getConnectionManager()
                                              throws SSLException
Implements ClientConnectionManager instance.

Returns:
ClientConnectionManager. The connection manager instance.
Throws:
SSLException - Thrown if the SSLSocketFactory could not be instantiated.

executeServerRequest

public String executeServerRequest(String url,
                                   String request)
                            throws ClientProtocolException,
                                   IOException,
                                   SSLException
Method performing HttpClient operations for sending and receiving requests

Throws:
IOException - Could be thrown while executing the request.
SSLException - Could be thrown while initializing the connection manager.
ClientProtocolException