public abstract class

AbstractHttpInvokerRequestExecutor

extends Object
implements BeanClassLoaderAware HttpInvokerRequestExecutor
java.lang.Object
   ↳ org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor
Known Direct Subclasses

Class Overview

Abstract base implementation of the HttpInvokerRequestExecutor interface.

Pre-implements serialization of RemoteInvocation objects and deserialization of RemoteInvocationResults objects.

Summary

Constants
String CONTENT_TYPE_SERIALIZED_OBJECT Default content type: "application/x-java-serialized-object"
String ENCODING_GZIP
String HTTP_HEADER_ACCEPT_ENCODING
String HTTP_HEADER_ACCEPT_LANGUAGE
String HTTP_HEADER_CONTENT_ENCODING
String HTTP_HEADER_CONTENT_LENGTH
String HTTP_HEADER_CONTENT_TYPE
String HTTP_METHOD_POST
Fields
protected final Log logger
Public Constructors
AbstractHttpInvokerRequestExecutor()
Public Methods
final RemoteInvocationResult executeRequest(HttpInvokerClientConfiguration config, RemoteInvocation invocation)
Execute a request to send the given remote invocation.
String getContentType()
Return the content type to use for sending HTTP invoker requests.
boolean isAcceptGzipEncoding()
Return whether to accept GZIP encoding, that is, whether to send the HTTP "Accept-Encoding" header with "gzip" as value.
void setAcceptGzipEncoding(boolean acceptGzipEncoding)
Set whether to accept GZIP encoding, that is, whether to send the HTTP "Accept-Encoding" header with "gzip" as value.
void setBeanClassLoader(ClassLoader classLoader)
Callback that supplies the bean class loader to a bean instance.
void setContentType(String contentType)
Specify the content type to use for sending HTTP invoker requests.
Protected Methods
ObjectInputStream createObjectInputStream(InputStream is, String codebaseUrl)
Create an ObjectInputStream for the given InputStream and codebase.
InputStream decorateInputStream(InputStream is)
Return the InputStream to use for reading remote invocation results, potentially decorating the given original InputStream.
OutputStream decorateOutputStream(OutputStream os)
Return the OutputStream to use for writing remote invocations, potentially decorating the given original OutputStream.
abstract RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, ByteArrayOutputStream baos)
Execute a request to send the given serialized remote invocation.
RemoteInvocationResult doReadRemoteInvocationResult(ObjectInputStream ois)
Perform the actual reading of an invocation object from the given ObjectInputStream.
void doWriteRemoteInvocation(RemoteInvocation invocation, ObjectOutputStream oos)
Perform the actual writing of the given invocation object to the given ObjectOutputStream.
ClassLoader getBeanClassLoader()
Return the bean ClassLoader that this executor is supposed to use.
ByteArrayOutputStream getByteArrayOutputStream(RemoteInvocation invocation)
Serialize the given RemoteInvocation into a ByteArrayOutputStream.
RemoteInvocationResult readRemoteInvocationResult(InputStream is, String codebaseUrl)
Deserialize a RemoteInvocationResult object from the given InputStream.
void writeRemoteInvocation(RemoteInvocation invocation, OutputStream os)
Serialize the given RemoteInvocation to the given OutputStream.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.beans.factory.BeanClassLoaderAware
From interface org.springframework.remoting.httpinvoker.HttpInvokerRequestExecutor

Constants

public static final String CONTENT_TYPE_SERIALIZED_OBJECT

Default content type: "application/x-java-serialized-object"

Constant Value: "application/x-java-serialized-object"

protected static final String ENCODING_GZIP

Constant Value: "gzip"

protected static final String HTTP_HEADER_ACCEPT_ENCODING

Constant Value: "Accept-Encoding"

protected static final String HTTP_HEADER_ACCEPT_LANGUAGE

Constant Value: "Accept-Language"

protected static final String HTTP_HEADER_CONTENT_ENCODING

Constant Value: "Content-Encoding"

protected static final String HTTP_HEADER_CONTENT_LENGTH

Constant Value: "Content-Length"

protected static final String HTTP_HEADER_CONTENT_TYPE

Constant Value: "Content-Type"

protected static final String HTTP_METHOD_POST

Constant Value: "POST"

Fields

protected final Log logger

Public Constructors

public AbstractHttpInvokerRequestExecutor ()

Public Methods

public final RemoteInvocationResult executeRequest (HttpInvokerClientConfiguration config, RemoteInvocation invocation)

Execute a request to send the given remote invocation.

Parameters
config the HTTP invoker configuration that specifies the target service
invocation the RemoteInvocation to execute
Returns
  • the RemoteInvocationResult object
Throws
Exception

public String getContentType ()

Return the content type to use for sending HTTP invoker requests.

public boolean isAcceptGzipEncoding ()

Return whether to accept GZIP encoding, that is, whether to send the HTTP "Accept-Encoding" header with "gzip" as value.

public void setAcceptGzipEncoding (boolean acceptGzipEncoding)

Set whether to accept GZIP encoding, that is, whether to send the HTTP "Accept-Encoding" header with "gzip" as value.

Default is "true". Turn this flag off if you do not want GZIP response compression even if enabled on the HTTP server.

public void setBeanClassLoader (ClassLoader classLoader)

Callback that supplies the bean class loader to a bean instance.

Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean's afterPropertiesSet() method or a custom init-method.

Parameters
classLoader the owning class loader; may be null in which case a default ClassLoader must be used, for example the ClassLoader obtained via getDefaultClassLoader()

public void setContentType (String contentType)

Specify the content type to use for sending HTTP invoker requests.

Default is "application/x-java-serialized-object".

Protected Methods

protected ObjectInputStream createObjectInputStream (InputStream is, String codebaseUrl)

Create an ObjectInputStream for the given InputStream and codebase. The default implementation creates a CodebaseAwareObjectInputStream.

Parameters
is the InputStream to read from
codebaseUrl the codebase URL to load classes from if not found locally (can be null)
Returns
  • the new ObjectInputStream instance to use
Throws
IOException if creation of the ObjectInputStream failed

protected InputStream decorateInputStream (InputStream is)

Return the InputStream to use for reading remote invocation results, potentially decorating the given original InputStream.

The default implementation returns the given stream as-is. Can be overridden, for example, for custom encryption or compression.

Parameters
is the original InputStream
Returns
  • the potentially decorated InputStream
Throws
IOException

protected OutputStream decorateOutputStream (OutputStream os)

Return the OutputStream to use for writing remote invocations, potentially decorating the given original OutputStream.

The default implementation returns the given stream as-is. Can be overridden, for example, for custom encryption or compression.

Parameters
os the original OutputStream
Returns
  • the potentially decorated OutputStream
Throws
IOException

protected abstract RemoteInvocationResult doExecuteRequest (HttpInvokerClientConfiguration config, ByteArrayOutputStream baos)

Execute a request to send the given serialized remote invocation.

Implementations will usually call readRemoteInvocationResult to deserialize a returned RemoteInvocationResult object.

Parameters
config the HTTP invoker configuration that specifies the target service
baos the ByteArrayOutputStream that contains the serialized RemoteInvocation object
Returns
  • the RemoteInvocationResult object
Throws
IOException if thrown by I/O operations
ClassNotFoundException if thrown during deserialization
Exception in case of general errors

protected RemoteInvocationResult doReadRemoteInvocationResult (ObjectInputStream ois)

Perform the actual reading of an invocation object from the given ObjectInputStream.

The default implementation simply calls readObject. Can be overridden for deserialization of a custom wrapper object rather than the plain invocation, for example an encryption-aware holder.

Parameters
ois the ObjectInputStream to read from
Returns
  • the RemoteInvocationResult object
Throws
IOException if thrown by I/O methods
ClassNotFoundException if the class name of a serialized object couldn't get resolved

protected void doWriteRemoteInvocation (RemoteInvocation invocation, ObjectOutputStream oos)

Perform the actual writing of the given invocation object to the given ObjectOutputStream.

The default implementation simply calls writeObject. Can be overridden for serialization of a custom wrapper object rather than the plain invocation, for example an encryption-aware holder.

Parameters
invocation the RemoteInvocation object
oos the ObjectOutputStream to write to
Throws
IOException if thrown by I/O methods

protected ClassLoader getBeanClassLoader ()

Return the bean ClassLoader that this executor is supposed to use.

protected ByteArrayOutputStream getByteArrayOutputStream (RemoteInvocation invocation)

Serialize the given RemoteInvocation into a ByteArrayOutputStream.

Parameters
invocation the RemoteInvocation object
Returns
  • a ByteArrayOutputStream with the serialized RemoteInvocation
Throws
IOException if thrown by I/O methods

protected RemoteInvocationResult readRemoteInvocationResult (InputStream is, String codebaseUrl)

Deserialize a RemoteInvocationResult object from the given InputStream.

Gives decorateInputStream a chance to decorate the stream first (for example, for custom encryption or compression). Creates an ObjectInputStream via createObjectInputStream and calls doReadRemoteInvocationResult to actually read the object.

Can be overridden for custom serialization of the invocation.

Parameters
is the InputStream to read from
codebaseUrl the codebase URL to load classes from if not found locally
Returns
  • the RemoteInvocationResult object
Throws
IOException if thrown by I/O methods
ClassNotFoundException if thrown during deserialization

protected void writeRemoteInvocation (RemoteInvocation invocation, OutputStream os)

Serialize the given RemoteInvocation to the given OutputStream.

The default implementation gives decorateOutputStream a chance to decorate the stream first (for example, for custom encryption or compression). Creates an ObjectOutputStream for the final stream and calls doWriteRemoteInvocation to actually write the object.

Can be overridden for custom serialization of the invocation.

Parameters
invocation the RemoteInvocation object
os the OutputStream to write to
Throws
IOException if thrown by I/O methods