public abstract class AbstractHttpClientTemplate<T> extends Object implements org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean
HttpClient
template class.Modifier and Type | Field and Description |
---|---|
protected boolean |
authenticationPreemptive |
protected org.apache.commons.httpclient.HttpClient |
client |
protected org.apache.commons.httpclient.HttpConnectionManager |
connectionManager |
protected String |
defaultUri |
protected List<Credentials> |
lCredentials |
Constructor and Description |
---|
AbstractHttpClientTemplate()
Constructor.
|
AbstractHttpClientTemplate(String defaultUri)
Constructor.
|
AbstractHttpClientTemplate(String defaultUri,
boolean init)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
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.
|
org.apache.commons.httpclient.HttpClient |
getClient()
Gets http client.
|
org.apache.commons.httpclient.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(org.apache.commons.httpclient.HttpMethod httpMethod,
ResponseCallback<?> callback)
Processes
HttpMethod by executing the method,
validating the response, and calling the callback. |
protected void |
processHttpMethodParams(org.apache.commons.httpclient.HttpMethod httpMethod,
Map<String,String> hParams)
Processes
HttpMethod parameters. |
void |
setAuthenticationPreemptive(boolean authenticationPreemptive)
Sets whether or not authentication is preemptive.
|
void |
setClient(org.apache.commons.httpclient.HttpClient client)
Sets http client.
|
void |
setConnectionManager(org.apache.commons.httpclient.HttpConnectionManager connectionManager)
Sets connection manager.
|
void |
setCredentials(List<Credentials> credentials)
Sets HTTP authorization credentials.
|
void |
setDefaultUri(String defaultUri)
Sets default uri.
|
protected void |
validateResponse(org.apache.commons.httpclient.HttpMethod httpMethod)
Validate response.
|
protected org.apache.commons.httpclient.HttpClient client
protected org.apache.commons.httpclient.HttpConnectionManager connectionManager
protected String defaultUri
protected boolean authenticationPreemptive
protected List<Credentials> lCredentials
public AbstractHttpClientTemplate()
public AbstractHttpClientTemplate(String defaultUri)
defaultUri
- Default uri.public AbstractHttpClientTemplate(String defaultUri, boolean init)
defaultUri
- Default uri.init
- Whether or not to initialize the bean
(typically for programatic use).public org.apache.commons.httpclient.HttpClient getClient()
public void setClient(org.apache.commons.httpclient.HttpClient client)
public org.apache.commons.httpclient.HttpConnectionManager getConnectionManager()
public void setConnectionManager(org.apache.commons.httpclient.HttpConnectionManager connectionManager)
public String getDefaultUri()
public void setDefaultUri(String defaultUri)
public boolean isAuthenticationPreemptive()
true
, authentication credentials
will be sent before a challenge is issued
for an authentication scope with credentials.
Defaults to false
.public void setAuthenticationPreemptive(boolean authenticationPreemptive)
true
, authentication credentials
will be sent before a challenge is issued
for an authentication scope with credentials.
Defaults to false
.public List<Credentials> getCredentials()
public void setCredentials(List<Credentials> credentials)
public void afterPropertiesSet() throws Exception
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
.afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Exception
public void destroy() throws Exception
DisposableBean
that
shuts down the connection manager if it is an instance of
MultiThreadedHttpConnectionManager
.destroy
in interface org.springframework.beans.factory.DisposableBean
Exception
public void executeGetMethod()
public void executeGetMethod(ResponseCallback<?> callback)
callback
- Callback with HTTP method's response.public void executeGetMethod(Map<String,String> hParams)
hParams
- Parameters for the HTTP get.public void executeGetMethod(Map<String,String> hParams, ResponseCallback<?> callback)
hParams
- Parameters for the HTTP get.callback
- Callback with HTTP method's response.public void executeGetMethod(String uri, Map<String,String> hParams)
uri
- URI to use when processing this HTTP request instead
of using the default URI.hParams
- Parameters for the HTTP get.public void executeGetMethod(String uri, Map<String,String> hParams, ResponseCallback<?> callback)
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.public void executePostMethod()
public void executePostMethod(ResponseCallback<?> callback)
callback
- Callback with HTTP method's response.public void executePostMethod(Map<String,String> hParams)
hParams
- Parameters for the HTTP post.public void executePostMethod(Map<String,String> hParams, ResponseCallback<?> callback)
hParams
- Parameters for the HTTP post.callback
- Callback with HTTP method's response.public void executePostMethod(String uri, T requestPayload, Map<String,String> hParams)
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.public abstract void executePostMethod(String uri, T requestPayload, Map<String,String> hParams, ResponseCallback<?> callback)
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.protected abstract void processHttpMethod(org.apache.commons.httpclient.HttpMethod httpMethod, ResponseCallback<?> callback)
HttpMethod
by executing the method,
validating the response, and calling the callback.httpMethod
- HttpMethod
to process.callback
- Callback with HTTP method's response.protected void processHttpMethodParams(org.apache.commons.httpclient.HttpMethod httpMethod, Map<String,String> hParams)
HttpMethod
parameters.httpMethod
- HttpMethod
to process.hParams
- Parameters for the HTTP get.protected void validateResponse(org.apache.commons.httpclient.HttpMethod httpMethod)
httpMethod
- HttpMethod
to validate.Copyright © 2008-2013 Spring by Example. All Rights Reserved.