org.springbyexample.httpclient
Class AbstractHttpClientTemplate<T>

java.lang.Object
  extended by org.springbyexample.httpclient.AbstractHttpClientTemplate<T>
All Implemented Interfaces:
DisposableBean, InitializingBean
Direct Known Subclasses:
HttpClientOxmTemplate, HttpClientTemplate

public abstract class AbstractHttpClientTemplate<T>
extends Object
implements InitializingBean, DisposableBean

Base HttpClient template class.

Author:
David Winterfeldt

Field Summary
protected  boolean authenticationPreemptive
           
protected  HttpClient client
           
protected  HttpConnectionManager connectionManager
           
protected  String defaultUri
           
protected  List<Credentials> lCredentials
           
 
Constructor Summary
AbstractHttpClientTemplate()
          Constructor.
AbstractHttpClientTemplate(String defaultUri)
          Constructor.
AbstractHttpClientTemplate(String defaultUri, boolean init)
          Constructor.
 
Method Summary
 void afterPropertiesSet()
          Implementation of InitializingBean that initializes the HttpClient if it is null and also sets the connection manager to MultiThreadedHttpConnectionManager if it is null while initializing the HttpClient.
 void destroy()
          Implementation of DisposableBean that shuts down the connection manager if it is an instance of MultiThreadedHttpConnectionManager.
 void executeGetMethod()
          Execute get method.
 void executeGetMethod(Map<String,String> hParams)
          Execute get method.
 void executeGetMethod(Map<String,String> hParams, ResponseCallback<?> callback)
          Execute get method.
 void executeGetMethod(ResponseCallback<?> callback)
          Execute get method.
 void executeGetMethod(String uri, Map<String,String> hParams)
          Execute get method.
 void executeGetMethod(String uri, Map<String,String> hParams, ResponseCallback<?> callback)
          Execute get method.
 void executePostMethod()
          Execute post method.
 void executePostMethod(Map<String,String> hParams)
          Execute post method.
 void executePostMethod(Map<String,String> hParams, ResponseCallback<?> callback)
          Execute post method.
 void executePostMethod(ResponseCallback<?> callback)
          Execute post method.
 void executePostMethod(String uri, T requestPayload, Map<String,String> hParams)
          Execute post method.
abstract  void executePostMethod(String uri, T requestPayload, Map<String,String> hParams, ResponseCallback<?> callback)
          Execute post method.
 HttpClient getClient()
          Gets http client.
 HttpConnectionManager getConnectionManager()
          Gets connection manager.
 List<Credentials> getCredentials()
          Gets HTTP authorization credentials.
 String getDefaultUri()
          Gets default uri.
 boolean isAuthenticationPreemptive()
          Whether or not authentication is preemptive.
protected abstract  void processHttpMethod(HttpMethod httpMethod, ResponseCallback<?> callback)
          Processes HttpMethod by executing the method, validating the response, and calling the callback.
protected  void processHttpMethodParams(HttpMethod httpMethod, Map<String,String> hParams)
          Processes HttpMethod parameters.
 void setAuthenticationPreemptive(boolean authenticationPreemptive)
          Sets whether or not authentication is preemptive.
 void setClient(HttpClient client)
          Sets http client.
 void setConnectionManager(HttpConnectionManager connectionManager)
          Sets connection manager.
 void setCredentials(List<Credentials> credentials)
          Sets HTTP authorization credentials.
 void setDefaultUri(String defaultUri)
          Sets default uri.
protected  void validateResponse(HttpMethod httpMethod)
          Validate response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

client

protected HttpClient client

connectionManager

protected HttpConnectionManager connectionManager

defaultUri

protected String defaultUri

authenticationPreemptive

protected boolean authenticationPreemptive

lCredentials

protected List<Credentials> lCredentials
Constructor Detail

AbstractHttpClientTemplate

public AbstractHttpClientTemplate()
Constructor.


AbstractHttpClientTemplate

public AbstractHttpClientTemplate(String defaultUri)
Constructor.

Parameters:
defaultUri - Default uri.

AbstractHttpClientTemplate

public AbstractHttpClientTemplate(String defaultUri,
                                  boolean init)
Constructor.

Parameters:
defaultUri - Default uri.
init - Whether or not to initialize the bean (typically for programatic use).
Method Detail

getClient

public HttpClient getClient()
Gets http client.


setClient

public void setClient(HttpClient client)
Sets http client.


getConnectionManager

public HttpConnectionManager getConnectionManager()
Gets connection manager.


setConnectionManager

public void setConnectionManager(HttpConnectionManager connectionManager)
Sets connection manager.


getDefaultUri

public String getDefaultUri()
Gets default uri.


setDefaultUri

public void setDefaultUri(String defaultUri)
Sets default uri.


isAuthenticationPreemptive

public boolean isAuthenticationPreemptive()
Whether or not authentication is preemptive. If true, authentication credentials will be sent before a challenge is issued for an authentication scope with credentials. Defaults to false.


setAuthenticationPreemptive

public void setAuthenticationPreemptive(boolean authenticationPreemptive)
Sets whether or not authentication is preemptive. If true, authentication credentials will be sent before a challenge is issued for an authentication scope with credentials. Defaults to false.


getCredentials

public List<Credentials> getCredentials()
Gets HTTP authorization credentials.


setCredentials

public void setCredentials(List<Credentials> credentials)
Sets HTTP authorization credentials.


afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Implementation of InitializingBean that initializes the HttpClient if it is null and also sets the connection manager to MultiThreadedHttpConnectionManager if it is null while initializing the HttpClient.

Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception

destroy

public void destroy()
             throws Exception
Implementation of DisposableBean that shuts down the connection manager if it is an instance of MultiThreadedHttpConnectionManager.

Specified by:
destroy in interface DisposableBean
Throws:
Exception

executeGetMethod

public void executeGetMethod()
Execute get method.


executeGetMethod

public void executeGetMethod(ResponseCallback<?> callback)
Execute get method.

Parameters:
callback - Callback with HTTP method's response.

executeGetMethod

public void executeGetMethod(Map<String,String> hParams)
Execute get method.

Parameters:
hParams - Parameters for the HTTP get.

executeGetMethod

public void executeGetMethod(Map<String,String> hParams,
                             ResponseCallback<?> callback)
Execute get method.

Parameters:
hParams - Parameters for the HTTP get.
callback - Callback with HTTP method's response.

executeGetMethod

public void executeGetMethod(String uri,
                             Map<String,String> hParams)
Execute get method.

Parameters:
uri - URI to use when processing this HTTP request instead of using the default URI.
hParams - Parameters for the HTTP get.

executeGetMethod

public void executeGetMethod(String uri,
                             Map<String,String> hParams,
                             ResponseCallback<?> callback)
Execute get method.

Parameters:
uri - URI to use when processing this HTTP request instead of using the default URI.
hParams - Parameters for the HTTP get.
callback - Callback with HTTP method's response.

executePostMethod

public void executePostMethod()
Execute post method.


executePostMethod

public void executePostMethod(ResponseCallback<?> callback)
Execute post method.

Parameters:
callback - Callback with HTTP method's response.

executePostMethod

public void executePostMethod(Map<String,String> hParams)
Execute post method.

Parameters:
hParams - Parameters for the HTTP post.

executePostMethod

public void executePostMethod(Map<String,String> hParams,
                              ResponseCallback<?> callback)
Execute post method.

Parameters:
hParams - Parameters for the HTTP post.
callback - Callback with HTTP method's response.

executePostMethod

public void executePostMethod(String uri,
                              T requestPayload,
                              Map<String,String> hParams)
Execute post method.

Parameters:
uri - URI to use when processing this HTTP request instead of using the default URI.
requestPayload - Request data to post.
hParams - Parameters for the HTTP post.

executePostMethod

public abstract void executePostMethod(String uri,
                                       T requestPayload,
                                       Map<String,String> hParams,
                                       ResponseCallback<?> callback)
Execute post method.

Parameters:
uri - URI to use when processing this HTTP request instead of using the default URI.
requestPayload - Request data to post.
hParams - Parameters for the HTTP post.
callback - Callback with HTTP method's response.

processHttpMethod

protected abstract void processHttpMethod(HttpMethod httpMethod,
                                          ResponseCallback<?> callback)
Processes HttpMethod by executing the method, validating the response, and calling the callback.

Parameters:
httpMethod - HttpMethod to process.
callback - Callback with HTTP method's response.

processHttpMethodParams

protected void processHttpMethodParams(HttpMethod httpMethod,
                                       Map<String,String> hParams)
Processes HttpMethod parameters.

Parameters:
httpMethod - HttpMethod to process.
hParams - Parameters for the HTTP get.

validateResponse

protected void validateResponse(HttpMethod httpMethod)
Validate response.

Parameters:
httpMethod - HttpMethod to validate.


Copyright © 2008-2009 Spring by Example. All Rights Reserved.