public abstract class AbstractHttpInvokerRequestExecutor extends Object implements HttpInvokerRequestExecutor, org.springframework.beans.factory.BeanClassLoaderAware
Pre-implements serialization of RemoteInvocation objects and deserialization of RemoteInvocationResults objects.
doExecuteRequest(org.springframework.remoting.httpinvoker.HttpInvokerClientConfiguration, java.io.ByteArrayOutputStream)
Modifier and Type | Field and Description |
---|---|
static String |
CONTENT_TYPE_SERIALIZED_OBJECT
Default content type: "application/x-java-serialized-object"
|
protected static String |
ENCODING_GZIP |
protected static String |
HTTP_HEADER_ACCEPT_ENCODING |
protected static String |
HTTP_HEADER_ACCEPT_LANGUAGE |
protected static String |
HTTP_HEADER_CONTENT_ENCODING |
protected static String |
HTTP_HEADER_CONTENT_LENGTH |
protected static String |
HTTP_HEADER_CONTENT_TYPE |
protected static String |
HTTP_METHOD_POST |
protected Log |
logger |
Constructor and Description |
---|
AbstractHttpInvokerRequestExecutor() |
Modifier and Type | Method and Description |
---|---|
protected ObjectInputStream |
createObjectInputStream(InputStream is,
String codebaseUrl)
Create an ObjectInputStream for the given InputStream and codebase.
|
protected InputStream |
decorateInputStream(InputStream is)
Return the InputStream to use for reading remote invocation results,
potentially decorating the given original InputStream.
|
protected OutputStream |
decorateOutputStream(OutputStream os)
Return the OutputStream to use for writing remote invocations,
potentially decorating the given original OutputStream.
|
protected abstract org.springframework.remoting.support.RemoteInvocationResult |
doExecuteRequest(HttpInvokerClientConfiguration config,
ByteArrayOutputStream baos)
Execute a request to send the given serialized remote invocation.
|
protected org.springframework.remoting.support.RemoteInvocationResult |
doReadRemoteInvocationResult(ObjectInputStream ois)
Perform the actual reading of an invocation object from the
given ObjectInputStream.
|
protected void |
doWriteRemoteInvocation(org.springframework.remoting.support.RemoteInvocation invocation,
ObjectOutputStream oos)
Perform the actual writing of the given invocation object to the
given ObjectOutputStream.
|
org.springframework.remoting.support.RemoteInvocationResult |
executeRequest(HttpInvokerClientConfiguration config,
org.springframework.remoting.support.RemoteInvocation invocation)
Execute a request to send the given remote invocation.
|
protected ClassLoader |
getBeanClassLoader()
Return the bean ClassLoader that this executor is supposed to use.
|
protected ByteArrayOutputStream |
getByteArrayOutputStream(org.springframework.remoting.support.RemoteInvocation invocation)
Serialize the given RemoteInvocation into a ByteArrayOutputStream.
|
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.
|
protected org.springframework.remoting.support.RemoteInvocationResult |
readRemoteInvocationResult(InputStream is,
String codebaseUrl)
Deserialize a RemoteInvocationResult object from the given InputStream.
|
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) |
void |
setContentType(String contentType)
Specify the content type to use for sending HTTP invoker requests.
|
protected void |
writeRemoteInvocation(org.springframework.remoting.support.RemoteInvocation invocation,
OutputStream os)
Serialize the given RemoteInvocation to the given OutputStream.
|
public static final String CONTENT_TYPE_SERIALIZED_OBJECT
protected static final String HTTP_METHOD_POST
protected static final String HTTP_HEADER_ACCEPT_LANGUAGE
protected static final String HTTP_HEADER_ACCEPT_ENCODING
protected static final String HTTP_HEADER_CONTENT_ENCODING
protected static final String HTTP_HEADER_CONTENT_TYPE
protected static final String HTTP_HEADER_CONTENT_LENGTH
protected static final String ENCODING_GZIP
protected final Log logger
public void setContentType(String contentType)
Default is "application/x-java-serialized-object".
public String getContentType()
public void setAcceptGzipEncoding(boolean acceptGzipEncoding)
Default is "true". Turn this flag off if you do not want GZIP response compression even if enabled on the HTTP server.
public boolean isAcceptGzipEncoding()
public void setBeanClassLoader(ClassLoader classLoader)
setBeanClassLoader
in interface org.springframework.beans.factory.BeanClassLoaderAware
protected ClassLoader getBeanClassLoader()
public final org.springframework.remoting.support.RemoteInvocationResult executeRequest(HttpInvokerClientConfiguration config, org.springframework.remoting.support.RemoteInvocation invocation) throws Exception
HttpInvokerRequestExecutor
executeRequest
in interface HttpInvokerRequestExecutor
config
- the HTTP invoker configuration that specifies the
target serviceinvocation
- the RemoteInvocation to executeIOException
- if thrown by I/O operationsClassNotFoundException
- if thrown during deserializationException
- in case of general errorsprotected ByteArrayOutputStream getByteArrayOutputStream(org.springframework.remoting.support.RemoteInvocation invocation) throws IOException
invocation
- the RemoteInvocation objectIOException
- if thrown by I/O methodsprotected void writeRemoteInvocation(org.springframework.remoting.support.RemoteInvocation invocation, OutputStream os) throws IOException
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.
invocation
- the RemoteInvocation objectos
- the OutputStream to write toIOException
- if thrown by I/O methodsdecorateOutputStream(java.io.OutputStream)
,
doWriteRemoteInvocation(org.springframework.remoting.support.RemoteInvocation, java.io.ObjectOutputStream)
protected OutputStream decorateOutputStream(OutputStream os) throws IOException
The default implementation returns the given stream as-is. Can be overridden, for example, for custom encryption or compression.
os
- the original OutputStreamIOException
protected void doWriteRemoteInvocation(org.springframework.remoting.support.RemoteInvocation invocation, ObjectOutputStream oos) throws IOException
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.
invocation
- the RemoteInvocation objectoos
- the ObjectOutputStream to write toIOException
- if thrown by I/O methodsObjectOutputStream.writeObject(java.lang.Object)
protected abstract org.springframework.remoting.support.RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws Exception
Implementations will usually call readRemoteInvocationResult
to deserialize a returned RemoteInvocationResult object.
config
- the HTTP invoker configuration that specifies the
target servicebaos
- the ByteArrayOutputStream that contains the serialized
RemoteInvocation objectIOException
- if thrown by I/O operationsClassNotFoundException
- if thrown during deserializationException
- in case of general errorsreadRemoteInvocationResult(java.io.InputStream, String)
protected org.springframework.remoting.support.RemoteInvocationResult readRemoteInvocationResult(InputStream is, String codebaseUrl) throws IOException, ClassNotFoundException
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.
is
- the InputStream to read fromcodebaseUrl
- the codebase URL to load classes from if not found locallyIOException
- if thrown by I/O methodsClassNotFoundException
- if thrown during deserializationdecorateInputStream(java.io.InputStream)
,
createObjectInputStream(java.io.InputStream, java.lang.String)
,
doReadRemoteInvocationResult(java.io.ObjectInputStream)
protected InputStream decorateInputStream(InputStream is) throws IOException
The default implementation returns the given stream as-is. Can be overridden, for example, for custom encryption or compression.
is
- the original InputStreamIOException
protected ObjectInputStream createObjectInputStream(InputStream is, String codebaseUrl) throws IOException
is
- the InputStream to read fromcodebaseUrl
- the codebase URL to load classes from if not found locally
(can be null
)IOException
- if creation of the ObjectInputStream failedCodebaseAwareObjectInputStream
protected org.springframework.remoting.support.RemoteInvocationResult doReadRemoteInvocationResult(ObjectInputStream ois) throws IOException, ClassNotFoundException
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.
ois
- the ObjectInputStream to read fromIOException
- if thrown by I/O methodsClassNotFoundException
- if the class name of a serialized object
couldn't get resolvedObjectOutputStream.writeObject(java.lang.Object)