|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor org.springframework.remoting.httpinvoker.HttpComponentsHttpInvokerRequestExecutor
public class HttpComponentsHttpInvokerRequestExecutor
HttpInvokerRequestExecutor
implementation that uses
Apache HttpComponents HttpClient
to execute POST requests.
Allows to use a pre-configured HttpClient
instance, potentially with authentication, HTTP connection pooling, etc.
Also designed for easy subclassing, providing specific template methods.
SimpleHttpInvokerRequestExecutor
Field Summary |
---|
Fields inherited from class org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor |
---|
CONTENT_TYPE_SERIALIZED_OBJECT, ENCODING_GZIP, HTTP_HEADER_ACCEPT_ENCODING, HTTP_HEADER_ACCEPT_LANGUAGE, HTTP_HEADER_CONTENT_ENCODING, HTTP_HEADER_CONTENT_LENGTH, HTTP_HEADER_CONTENT_TYPE, HTTP_METHOD_POST, logger |
Constructor Summary | |
---|---|
HttpComponentsHttpInvokerRequestExecutor()
Create a new instance of the HttpComponentsHttpInvokerRequestExecutor with a default HttpClient that uses a default ThreadSafeClientConnManager . |
|
HttpComponentsHttpInvokerRequestExecutor(org.apache.http.client.HttpClient httpClient)
Create a new instance of the HttpComponentsClientHttpRequestFactory with the given HttpClient instance. |
Method Summary | |
---|---|
protected org.apache.http.client.methods.HttpPost |
createHttpPost(HttpInvokerClientConfiguration config)
Create a HttpPost for the given configuration. |
protected RemoteInvocationResult |
doExecuteRequest(HttpInvokerClientConfiguration config,
ByteArrayOutputStream baos)
Execute the given request through the HttpClient. |
protected org.apache.http.HttpResponse |
executeHttpPost(HttpInvokerClientConfiguration config,
org.apache.http.client.HttpClient httpClient,
org.apache.http.client.methods.HttpPost httpPost)
Execute the given HttpPost instance. |
org.apache.http.client.HttpClient |
getHttpClient()
Return the HttpClient instance that this request executor uses. |
protected InputStream |
getResponseBody(HttpInvokerClientConfiguration config,
org.apache.http.HttpResponse httpResponse)
Extract the response body from the given executed remote invocation request. |
protected boolean |
isGzipResponse(org.apache.http.HttpResponse httpResponse)
Determine whether the given response indicates a GZIP response. |
void |
setConnectTimeout(int timeout)
Set the connection timeout for the underlying HttpClient. |
void |
setHttpClient(org.apache.http.client.HttpClient httpClient)
Set the HttpClient instance to use for this request executor. |
void |
setReadTimeout(int timeout)
Set the socket read timeout for the underlying HttpClient. |
protected void |
setRequestBody(HttpInvokerClientConfiguration config,
org.apache.http.client.methods.HttpPost httpPost,
ByteArrayOutputStream baos)
Set the given serialized remote invocation as request body. |
protected void |
validateResponse(HttpInvokerClientConfiguration config,
org.apache.http.HttpResponse response)
Validate the given response as contained in the HttpPost object, throwing an exception if it does not correspond to a successful HTTP response. |
Methods inherited from class org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor |
---|
createObjectInputStream, decorateInputStream, decorateOutputStream, doReadRemoteInvocationResult, doWriteRemoteInvocation, executeRequest, getBeanClassLoader, getByteArrayOutputStream, getContentType, isAcceptGzipEncoding, readRemoteInvocationResult, setAcceptGzipEncoding, setBeanClassLoader, setContentType, writeRemoteInvocation |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HttpComponentsHttpInvokerRequestExecutor()
HttpClient
that uses a default ThreadSafeClientConnManager
.
public HttpComponentsHttpInvokerRequestExecutor(org.apache.http.client.HttpClient httpClient)
HttpClient
instance.
httpClient
- the HttpClient instance to use for this request executorMethod Detail |
---|
public void setHttpClient(org.apache.http.client.HttpClient httpClient)
HttpClient
instance to use for this request executor.
public org.apache.http.client.HttpClient getHttpClient()
HttpClient
instance that this request executor uses.
public void setConnectTimeout(int timeout)
timeout
- the timeout value in millisecondspublic void setReadTimeout(int timeout)
timeout
- the timeout value in millisecondsDEFAULT_READ_TIMEOUT_MILLISECONDS
protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws IOException, ClassNotFoundException
This method implements the basic processing workflow: The actual work happens in this class's template methods.
doExecuteRequest
in class AbstractHttpInvokerRequestExecutor
config
- the HTTP invoker configuration that specifies the
target servicebaos
- the ByteArrayOutputStream that contains the serialized
RemoteInvocation object
IOException
- if thrown by I/O operations
ClassNotFoundException
- if thrown during deserializationcreateHttpPost(org.springframework.remoting.httpinvoker.HttpInvokerClientConfiguration)
,
setRequestBody(org.springframework.remoting.httpinvoker.HttpInvokerClientConfiguration, org.apache.http.client.methods.HttpPost, java.io.ByteArrayOutputStream)
,
executeHttpPost(org.springframework.remoting.httpinvoker.HttpInvokerClientConfiguration, org.apache.http.client.HttpClient, org.apache.http.client.methods.HttpPost)
,
validateResponse(org.springframework.remoting.httpinvoker.HttpInvokerClientConfiguration, org.apache.http.HttpResponse)
,
getResponseBody(org.springframework.remoting.httpinvoker.HttpInvokerClientConfiguration, org.apache.http.HttpResponse)
protected org.apache.http.client.methods.HttpPost createHttpPost(HttpInvokerClientConfiguration config) throws IOException
The default implementation creates a standard HttpPost with "application/x-java-serialized-object" as "Content-Type" header.
config
- the HTTP invoker configuration that specifies the
target service
IOException
- if thrown by I/O methodsprotected void setRequestBody(HttpInvokerClientConfiguration config, org.apache.http.client.methods.HttpPost httpPost, ByteArrayOutputStream baos) throws IOException
The default implementation simply sets the serialized invocation as the HttpPost's request body. This can be overridden, for example, to write a specific encoding and to potentially set appropriate HTTP request headers.
config
- the HTTP invoker configuration that specifies the target servicehttpPost
- the HttpPost to set the request body onbaos
- the ByteArrayOutputStream that contains the serialized
RemoteInvocation object
IOException
- if thrown by I/O methodsprotected org.apache.http.HttpResponse executeHttpPost(HttpInvokerClientConfiguration config, org.apache.http.client.HttpClient httpClient, org.apache.http.client.methods.HttpPost httpPost) throws IOException
config
- the HTTP invoker configuration that specifies the target servicehttpClient
- the HttpClient to execute onhttpPost
- the HttpPost to execute
IOException
- if thrown by I/O methodsprotected void validateResponse(HttpInvokerClientConfiguration config, org.apache.http.HttpResponse response) throws IOException
Default implementation rejects any HTTP status code beyond 2xx, to avoid parsing the response body and trying to deserialize from a corrupted stream.
config
- the HTTP invoker configuration that specifies the target serviceresponse
- the resulting HttpResponse to validate
IOException
- if validation failedprotected InputStream getResponseBody(HttpInvokerClientConfiguration config, org.apache.http.HttpResponse httpResponse) throws IOException
The default implementation simply fetches the HttpPost's response body stream. If the response is recognized as GZIP response, the InputStream will get wrapped in a GZIPInputStream.
config
- the HTTP invoker configuration that specifies the target servicehttpResponse
- the resulting HttpResponse to read the response body from
IOException
- if thrown by I/O methodsisGzipResponse(org.apache.http.HttpResponse)
,
GZIPInputStream
protected boolean isGzipResponse(org.apache.http.HttpResponse httpResponse)
The default implementation checks whether the HTTP "Content-Encoding" header contains "gzip" (in any casing).
httpResponse
- the resulting HttpResponse to check
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |