public class

SimpleHttpInvokerRequestExecutor

extends AbstractHttpInvokerRequestExecutor
java.lang.Object
   ↳ org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor
     ↳ org.springframework.remoting.httpinvoker.SimpleHttpInvokerRequestExecutor

Class Overview

HttpInvokerRequestExecutor implementation that uses standard J2SE facilities to execute POST requests, without support for HTTP authentication or advanced configuration options.

Designed for easy subclassing, customizing specific template methods. However, consider CommonsHttpInvokerRequestExecutor for more sophisticated needs: The J2SE HttpURLConnection is rather limited in its capabilities.

Summary

[Expand]
Inherited Constants
From class org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor
[Expand]
Inherited Fields
From class org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor
Public Constructors
SimpleHttpInvokerRequestExecutor()
Protected Methods
RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, ByteArrayOutputStream baos)
Execute the given request through a standard J2SE HttpURLConnection.
boolean isGzipResponse(HttpURLConnection con)
Determine whether the given response is a GZIP response.
HttpURLConnection openConnection(HttpInvokerClientConfiguration config)
Open an HttpURLConnection for the given remote invocation request.
void prepareConnection(HttpURLConnection con, int contentLength)
Prepare the given HTTP connection.
InputStream readResponseBody(HttpInvokerClientConfiguration config, HttpURLConnection con)
Extract the response body from the given executed remote invocation request.
void validateResponse(HttpInvokerClientConfiguration config, HttpURLConnection con)
Validate the given response as contained in the HttpURLConnection object, throwing an exception if it does not correspond to a successful HTTP response.
void writeRequestBody(HttpInvokerClientConfiguration config, HttpURLConnection con, ByteArrayOutputStream baos)
Set the given serialized remote invocation as request body.
[Expand]
Inherited Methods
From class org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor
From class java.lang.Object
From interface org.springframework.beans.factory.BeanClassLoaderAware
From interface org.springframework.remoting.httpinvoker.HttpInvokerRequestExecutor

Public Constructors

public SimpleHttpInvokerRequestExecutor ()

Protected Methods

protected RemoteInvocationResult doExecuteRequest (HttpInvokerClientConfiguration config, ByteArrayOutputStream baos)

Execute the given request through a standard J2SE HttpURLConnection.

This method implements the basic processing workflow: The actual work happens in this class's template methods.

Parameters
config the HTTP invoker configuration that specifies the target service
baos the ByteArrayOutputStream that contains the serialized RemoteInvocation object
Returns
  • the RemoteInvocationResult object

protected boolean isGzipResponse (HttpURLConnection con)

Determine whether the given response is a GZIP response.

Default implementation checks whether the HTTP "Content-Encoding" header contains "gzip" (in any casing).

Parameters
con the HttpURLConnection to check

protected HttpURLConnection openConnection (HttpInvokerClientConfiguration config)

Open an HttpURLConnection for the given remote invocation request.

Parameters
config the HTTP invoker configuration that specifies the target service
Returns
  • the HttpURLConnection for the given request
Throws
IOException if thrown by I/O methods
See Also

protected void prepareConnection (HttpURLConnection con, int contentLength)

Prepare the given HTTP connection.

The default implementation specifies POST as method, "application/x-java-serialized-object" as "Content-Type" header, and the given content length as "Content-Length" header.

Parameters
con the HTTP connection to prepare
contentLength the length of the content to send
Throws
IOException if thrown by HttpURLConnection methods

protected InputStream readResponseBody (HttpInvokerClientConfiguration config, HttpURLConnection con)

Extract the response body from the given executed remote invocation request.

The default implementation simply reads the serialized invocation from the HttpURLConnection's InputStream. If the response is recognized as GZIP response, the InputStream will get wrapped in a GZIPInputStream.

Parameters
config the HTTP invoker configuration that specifies the target service
con the HttpURLConnection to read the response body from
Returns
  • an InputStream for the response body
Throws
IOException if thrown by I/O methods

protected void validateResponse (HttpInvokerClientConfiguration config, HttpURLConnection con)

Validate the given response as contained in the HttpURLConnection object, throwing an exception if it does not correspond to a successful HTTP response.

Default implementation rejects any HTTP status code beyond 2xx, to avoid parsing the response body and trying to deserialize from a corrupted stream.

Parameters
config the HTTP invoker configuration that specifies the target service
con the HttpURLConnection to validate
Throws
IOException if validation failed

protected void writeRequestBody (HttpInvokerClientConfiguration config, HttpURLConnection con, ByteArrayOutputStream baos)

Set the given serialized remote invocation as request body.

The default implementation simply write the serialized invocation to the HttpURLConnection's OutputStream. This can be overridden, for example, to write a specific encoding and potentially set appropriate HTTP request headers.

Parameters
config the HTTP invoker configuration that specifies the target service
con the HttpURLConnection to write the request body to
baos the ByteArrayOutputStream that contains the serialized RemoteInvocation object
Throws
IOException if thrown by I/O methods