public class HttpInvokerClientInterceptor extends org.springframework.remoting.support.RemoteInvocationBasedAccessor implements org.aopalliance.intercept.MethodInterceptor, HttpInvokerClientConfiguration
MethodInterceptor
for accessing an
HTTP invoker service. The service URL must be an HTTP URL exposing
an HTTP invoker service.
Serializes remote invocation objects and deserializes remote invocation result objects. Uses Java serialization just like RMI, but provides the same ease of setup as Caucho's HTTP-based Hessian protocol.
HTTP invoker is a very extensible and customizable protocol.
It supports the RemoteInvocationFactory mechanism, like RMI invoker,
allowing to include additional invocation attributes (for example,
a security context). Furthermore, it allows to customize request
execution via the HttpInvokerRequestExecutor
strategy.
Can use the JDK's RMIClassLoader
to load classes
from a given codebase
, performing on-demand dynamic
code download from a remote location. The codebase can consist of multiple
URLs, separated by spaces. Note that RMIClassLoader requires a SecurityManager
to be set, analogous to when using dynamic class download with standard RMI!
(See the RMI documentation for details.)
WARNING: Be aware of vulnerabilities due to unsafe Java deserialization: Manipulated input streams could lead to unwanted code execution on the server during the deserialization step. As a consequence, do not expose HTTP invoker endpoints to untrusted clients but rather just between your own services. In general, we strongly recommend any other message format (e.g. JSON) instead.
UrlBasedRemoteAccessor.setServiceUrl(java.lang.String)
,
setCodebaseUrl(java.lang.String)
,
RemoteInvocationBasedAccessor.setRemoteInvocationFactory(org.springframework.remoting.support.RemoteInvocationFactory)
,
setHttpInvokerRequestExecutor(org.springframework.remoting.httpinvoker.HttpInvokerRequestExecutor)
,
HttpInvokerServiceExporter
,
HttpInvokerProxyFactoryBean
,
RMIClassLoader
Constructor and Description |
---|
HttpInvokerClientInterceptor() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected org.springframework.remoting.RemoteAccessException |
convertHttpInvokerAccessException(Throwable ex)
Convert the given HTTP invoker access exception to an appropriate
Spring
RemoteAccessException . |
protected org.springframework.remoting.support.RemoteInvocationResult |
executeRequest(org.springframework.remoting.support.RemoteInvocation invocation)
Execute the given remote invocation via the
HttpInvokerRequestExecutor . |
protected org.springframework.remoting.support.RemoteInvocationResult |
executeRequest(org.springframework.remoting.support.RemoteInvocation invocation,
org.aopalliance.intercept.MethodInvocation originalInvocation)
Execute the given remote invocation via the
HttpInvokerRequestExecutor . |
String |
getCodebaseUrl()
Return the codebase URL to download classes from if not found locally.
|
HttpInvokerRequestExecutor |
getHttpInvokerRequestExecutor()
Return the HttpInvokerRequestExecutor used by this remote accessor.
|
Object |
invoke(org.aopalliance.intercept.MethodInvocation methodInvocation) |
void |
setCodebaseUrl(String codebaseUrl)
Set the codebase URL to download classes from if not found locally.
|
void |
setHttpInvokerRequestExecutor(HttpInvokerRequestExecutor httpInvokerRequestExecutor)
Set the HttpInvokerRequestExecutor implementation to use for executing
remote invocations.
|
createRemoteInvocation, getRemoteInvocationFactory, recreateRemoteInvocationResult, setRemoteInvocationFactory
getServiceUrl, setServiceUrl
getServiceInterface, setServiceInterface
getBeanClassLoader, overrideThreadContextClassLoader, resetThreadContextClassLoader, setBeanClassLoader
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getServiceUrl
public void setCodebaseUrl(@Nullable String codebaseUrl)
Follows RMI's codebase conventions for dynamic class download. In contrast to RMI, where the server determines the URL for class download (via the "java.rmi.server.codebase" system property), it's the client that determines the codebase URL here. The server will usually be the same as for the service URL, just pointing to a different path there.
UrlBasedRemoteAccessor.setServiceUrl(java.lang.String)
,
CodebaseAwareObjectInputStream
,
RMIClassLoader
@Nullable public String getCodebaseUrl()
getCodebaseUrl
in interface HttpInvokerClientConfiguration
null
if noneRMIClassLoader
public void setHttpInvokerRequestExecutor(HttpInvokerRequestExecutor httpInvokerRequestExecutor)
Default is SimpleHttpInvokerRequestExecutor
. Alternatively,
consider using HttpComponentsHttpInvokerRequestExecutor
for more
sophisticated needs.
public HttpInvokerRequestExecutor getHttpInvokerRequestExecutor()
Creates a default SimpleHttpInvokerRequestExecutor if no executor has been initialized already.
public void afterPropertiesSet()
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
afterPropertiesSet
in class org.springframework.remoting.support.UrlBasedRemoteAccessor
public Object invoke(org.aopalliance.intercept.MethodInvocation methodInvocation) throws Throwable
invoke
in interface org.aopalliance.intercept.MethodInterceptor
Throwable
protected org.springframework.remoting.support.RemoteInvocationResult executeRequest(org.springframework.remoting.support.RemoteInvocation invocation, org.aopalliance.intercept.MethodInvocation originalInvocation) throws Exception
HttpInvokerRequestExecutor
.
This implementation delegates to executeRequest(RemoteInvocation)
.
Can be overridden to react to the specific original MethodInvocation.
invocation
- the RemoteInvocation to executeoriginalInvocation
- the original MethodInvocation (can e.g. be cast
to the ProxyMethodInvocation interface for accessing user attributes)Exception
- in case of errorsprotected org.springframework.remoting.support.RemoteInvocationResult executeRequest(org.springframework.remoting.support.RemoteInvocation invocation) throws Exception
HttpInvokerRequestExecutor
.
Can be overridden in subclasses to pass a different configuration object to the executor. Alternatively, add further configuration properties in a subclass of this accessor: By default, the accessor passed itself as configuration object to the executor.
invocation
- the RemoteInvocation to executeIOException
- if thrown by I/O operationsClassNotFoundException
- if thrown during deserializationException
- in case of general errorsgetHttpInvokerRequestExecutor()
,
HttpInvokerClientConfiguration
@Nullable protected org.springframework.remoting.RemoteAccessException convertHttpInvokerAccessException(Throwable ex)
RemoteAccessException
.ex
- the exception to convertnull
to have the
original exception propagated to the caller