org.springbyexample.httpclient
Class HttpClientOxmTemplate<T>

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

@Component
public class HttpClientOxmTemplate<T>
extends AbstractHttpClientTemplate<T>
implements InitializingBean

Template for easier use of HttpClient and also uses Spring Web Services OXM framework to marshall/unmarshall XML from requests and responses.

Author:
David Winterfeldt

Field Summary
protected  Marshaller marshaller
           
protected  Unmarshaller unmarshaller
           
 
Fields inherited from class org.springbyexample.httpclient.AbstractHttpClientTemplate
authenticationPreemptive, client, connectionManager, defaultUri, lCredentials
 
Constructor Summary
HttpClientOxmTemplate()
          Constructor.
HttpClientOxmTemplate(String defaultUri)
          Constructor.
HttpClientOxmTemplate(String defaultUri, Marshaller marshaller, Unmarshaller unmarshaller)
          Constructor.
HttpClientOxmTemplate(String defaultUri, Marshaller marshaller, Unmarshaller unmarshaller, 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 executePostMethod(String uri, T requestPayload, Map<String,String> hParams, ResponseCallback<?> callback)
          Execute post method.
 void executePostMethod(T requestPayload)
          Execute post method.
 void executePostMethod(T requestPayload, Map<String,String> hParams)
          Execute post method.
 void executePostMethod(T requestPayload, Map<String,String> hParams, ResponseCallback<?> callback)
          Execute post method.
 void executePostMethod(T requestPayload, ResponseCallback<?> callback)
          Execute post method.
 Marshaller getMarshaller()
          Gets marshaller.
 Unmarshaller getUnmarshaller()
          Gets unmarshaller.
protected  void processHttpMethod(HttpMethod httpMethod, ResponseCallback callback)
          Processes HttpMethod by executing the method, validating the response, and calling the callback.
 void setMarshaller(Marshaller marshaller)
          Sets marshaller.
 void setUnmarshaller(Unmarshaller unmarshaller)
          Sets unmarshaller.
 
Methods inherited from class org.springbyexample.httpclient.AbstractHttpClientTemplate
destroy, executeGetMethod, executeGetMethod, executeGetMethod, executeGetMethod, executeGetMethod, executeGetMethod, executePostMethod, executePostMethod, executePostMethod, executePostMethod, executePostMethod, getClient, getConnectionManager, getCredentials, getDefaultUri, isAuthenticationPreemptive, processHttpMethodParams, setAuthenticationPreemptive, setClient, setConnectionManager, setCredentials, setDefaultUri, validateResponse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

marshaller

protected Marshaller marshaller

unmarshaller

protected Unmarshaller unmarshaller
Constructor Detail

HttpClientOxmTemplate

public HttpClientOxmTemplate()
Constructor.


HttpClientOxmTemplate

public HttpClientOxmTemplate(String defaultUri)
Constructor.

Parameters:
defaultUri - Default uri.

HttpClientOxmTemplate

public HttpClientOxmTemplate(String defaultUri,
                             Marshaller marshaller,
                             Unmarshaller unmarshaller)
Constructor.

Parameters:
defaultUri - Default uri.
marshaller - Marshaller to use for marshalling requests.
unmarshaller - Unmarshaller to use for unmarshalling requests.

HttpClientOxmTemplate

public HttpClientOxmTemplate(String defaultUri,
                             Marshaller marshaller,
                             Unmarshaller unmarshaller,
                             boolean init)
Constructor.

Parameters:
defaultUri - Default uri.
marshaller - Marshaller to use for marshalling requests.
unmarshaller - Unmarshaller to use for unmarshalling requests.
init - Whether or not to initialize the bean.
Method Detail

getMarshaller

public Marshaller getMarshaller()
Gets marshaller.


setMarshaller

public void setMarshaller(Marshaller marshaller)
Sets marshaller.


getUnmarshaller

public Unmarshaller getUnmarshaller()
Gets unmarshaller.


setUnmarshaller

public void setUnmarshaller(Unmarshaller unmarshaller)
Sets unmarshaller.


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
Overrides:
afterPropertiesSet in class AbstractHttpClientTemplate<T>
Throws:
Exception

executePostMethod

public void executePostMethod(T requestPayload)
Execute post method.

Parameters:
requestPayload - Request data to post after marshalling. The Marshaller should be able to process this instance.

executePostMethod

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

Parameters:
requestPayload - Request data to post after marshalling. The Marshaller should be able to process this instance.
callback - Callback with HTTP method's response.

executePostMethod

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

Parameters:
requestPayload - Request data to post after marshalling. The Marshaller should be able to process this instance.
hParams - Parameters for the HTTP post.

executePostMethod

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

Parameters:
requestPayload - Request data to post after marshalling. The Marshaller should be able to process this instance.
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,
                              ResponseCallback<?> callback)
Execute post method.

Specified by:
executePostMethod in class AbstractHttpClientTemplate<T>
Parameters:
uri - URI to use when processing this HTTP request instead of using the default URI.
requestPayload - Request data to post after marshalling. The Marshaller should be able to process this instance.
hParams - Parameters for the HTTP post.
callback - Callback with HTTP method's response.

processHttpMethod

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

Specified by:
processHttpMethod in class AbstractHttpClientTemplate<T>
Parameters:
httpMethod - HttpMethod to process.
callback - Callback with HTTP method's response.


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