public abstract class AbstractHttpInvokerRequestExecutor extends java.lang.Object implements HttpInvokerRequestExecutor, 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 java.lang.String |
CONTENT_TYPE_SERIALIZED_OBJECT
Default content type: "application/x-java-serialized-object".
|
protected static java.lang.String |
ENCODING_GZIP |
protected static java.lang.String |
HTTP_HEADER_ACCEPT_ENCODING |
protected static java.lang.String |
HTTP_HEADER_ACCEPT_LANGUAGE |
protected static java.lang.String |
HTTP_HEADER_CONTENT_ENCODING |
protected static java.lang.String |
HTTP_HEADER_CONTENT_LENGTH |
protected static java.lang.String |
HTTP_HEADER_CONTENT_TYPE |
protected static java.lang.String |
HTTP_METHOD_POST |
protected Log |
logger |
Constructor and Description |
---|
AbstractHttpInvokerRequestExecutor() |
Modifier and Type | Method and Description |
---|---|
protected java.io.ObjectInputStream |
createObjectInputStream(java.io.InputStream is,
java.lang.String codebaseUrl)
Create an ObjectInputStream for the given InputStream and codebase.
|
protected java.io.InputStream |
decorateInputStream(java.io.InputStream is)
Return the InputStream to use for reading remote invocation results,
potentially decorating the given original InputStream.
|
protected java.io.OutputStream |
decorateOutputStream(java.io.OutputStream os)
Return the OutputStream to use for writing remote invocations,
potentially decorating the given original OutputStream.
|
protected abstract RemoteInvocationResult |
doExecuteRequest(HttpInvokerClientConfiguration config,
java.io.ByteArrayOutputStream baos)
Execute a request to send the given serialized remote invocation.
|
protected RemoteInvocationResult |
doReadRemoteInvocationResult(java.io.ObjectInputStream ois)
Perform the actual reading of an invocation object from the
given ObjectInputStream.
|
protected void |
doWriteRemoteInvocation(RemoteInvocation invocation,
java.io.ObjectOutputStream oos)
Perform the actual writing of the given invocation object to the
given ObjectOutputStream.
|
RemoteInvocationResult |
executeRequest(HttpInvokerClientConfiguration config,
RemoteInvocation invocation)
Execute a request to send the given remote invocation.
|
protected java.lang.ClassLoader |
getBeanClassLoader()
Return the bean ClassLoader that this executor is supposed to use.
|
protected java.io.ByteArrayOutputStream |
getByteArrayOutputStream(RemoteInvocation invocation)
Serialize the given RemoteInvocation into a ByteArrayOutputStream.
|
java.lang.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 RemoteInvocationResult |
readRemoteInvocationResult(java.io.InputStream is,
java.lang.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(java.lang.ClassLoader classLoader)
Callback that supplies the bean
class loader to
a bean instance. |
void |
setContentType(java.lang.String contentType)
Specify the content type to use for sending HTTP invoker requests.
|
protected void |
writeRemoteInvocation(RemoteInvocation invocation,
java.io.OutputStream os)
Serialize the given RemoteInvocation to the given OutputStream.
|
public static final java.lang.String CONTENT_TYPE_SERIALIZED_OBJECT
protected static final java.lang.String HTTP_METHOD_POST
protected static final java.lang.String HTTP_HEADER_ACCEPT_LANGUAGE
protected static final java.lang.String HTTP_HEADER_ACCEPT_ENCODING
protected static final java.lang.String HTTP_HEADER_CONTENT_ENCODING
protected static final java.lang.String HTTP_HEADER_CONTENT_TYPE
protected static final java.lang.String HTTP_HEADER_CONTENT_LENGTH
protected static final java.lang.String ENCODING_GZIP
protected final Log logger
public void setContentType(java.lang.String contentType)
Default is "application/x-java-serialized-object".
public java.lang.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(java.lang.ClassLoader classLoader)
BeanClassLoaderAware
class loader
to
a bean instance.
Invoked after the population of normal bean properties but
before an initialization callback such as
InitializingBean's
InitializingBean.afterPropertiesSet()
method or a custom init-method.
setBeanClassLoader
in interface BeanClassLoaderAware
classLoader
- the owning class loader@Nullable protected java.lang.ClassLoader getBeanClassLoader()
public final RemoteInvocationResult executeRequest(HttpInvokerClientConfiguration config, RemoteInvocation invocation) throws java.lang.Exception
HttpInvokerRequestExecutor
executeRequest
in interface HttpInvokerRequestExecutor
config
- the HTTP invoker configuration that specifies the
target serviceinvocation
- the RemoteInvocation to executejava.io.IOException
- if thrown by I/O operationsjava.lang.ClassNotFoundException
- if thrown during deserializationjava.lang.Exception
- in case of general errorsprotected java.io.ByteArrayOutputStream getByteArrayOutputStream(RemoteInvocation invocation) throws java.io.IOException
invocation
- the RemoteInvocation objectjava.io.IOException
- if thrown by I/O methodsprotected void writeRemoteInvocation(RemoteInvocation invocation, java.io.OutputStream os) throws java.io.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 tojava.io.IOException
- if thrown by I/O methodsdecorateOutputStream(java.io.OutputStream)
,
doWriteRemoteInvocation(org.springframework.remoting.support.RemoteInvocation, java.io.ObjectOutputStream)
protected java.io.OutputStream decorateOutputStream(java.io.OutputStream os) throws java.io.IOException
The default implementation returns the given stream as-is. Can be overridden, for example, for custom encryption or compression.
os
- the original OutputStreamjava.io.IOException
protected void doWriteRemoteInvocation(RemoteInvocation invocation, java.io.ObjectOutputStream oos) throws java.io.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 tojava.io.IOException
- if thrown by I/O methodsObjectOutputStream.writeObject(java.lang.Object)
protected abstract RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, java.io.ByteArrayOutputStream baos) throws java.lang.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 objectjava.io.IOException
- if thrown by I/O operationsjava.lang.ClassNotFoundException
- if thrown during deserializationjava.lang.Exception
- in case of general errorsreadRemoteInvocationResult(java.io.InputStream, String)
protected RemoteInvocationResult readRemoteInvocationResult(java.io.InputStream is, @Nullable java.lang.String codebaseUrl) throws java.io.IOException, java.lang.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 locallyjava.io.IOException
- if thrown by I/O methodsjava.lang.ClassNotFoundException
- if thrown during deserializationdecorateInputStream(java.io.InputStream)
,
createObjectInputStream(java.io.InputStream, java.lang.String)
,
doReadRemoteInvocationResult(java.io.ObjectInputStream)
protected java.io.InputStream decorateInputStream(java.io.InputStream is) throws java.io.IOException
The default implementation returns the given stream as-is. Can be overridden, for example, for custom encryption or compression.
is
- the original InputStreamjava.io.IOException
protected java.io.ObjectInputStream createObjectInputStream(java.io.InputStream is, @Nullable java.lang.String codebaseUrl) throws java.io.IOException
is
- the InputStream to read fromcodebaseUrl
- the codebase URL to load classes from if not found locally
(can be null
)java.io.IOException
- if creation of the ObjectInputStream failedCodebaseAwareObjectInputStream
protected RemoteInvocationResult doReadRemoteInvocationResult(java.io.ObjectInputStream ois) throws java.io.IOException, java.lang.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 fromjava.io.IOException
- if thrown by I/O methodsjava.lang.ClassNotFoundException
- if the class name of a serialized object
couldn't get resolvedObjectOutputStream.writeObject(java.lang.Object)