org.springframework.remoting.rmi
Class RmiClientInterceptor

java.lang.Object
  extended byorg.springframework.remoting.support.RemoteAccessor
      extended byorg.springframework.remoting.support.UrlBasedRemoteAccessor
          extended byorg.springframework.remoting.rmi.RmiClientInterceptor
All Implemented Interfaces:
org.aopalliance.aop.Advice, InitializingBean, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor
Direct Known Subclasses:
RmiProxyFactoryBean

public class RmiClientInterceptor
extends UrlBasedRemoteAccessor
implements org.aopalliance.intercept.MethodInterceptor, InitializingBean

Interceptor for accessing conventional RMI services or RMI invokers. The service URL must be a valid RMI URL like "rmi://localhost:1099/myservice".

RMI invokers work at the RmiInvocationHandler level, needing only one stub for any service. Service interfaces do not have to extend java.rmi.Remote or throw RemoteException; Spring's unchecked RemoteAccessException will be thrown on remote invocation failure. Of course, in and out parameters have to be serializable.

With conventional RMI services, this invoker is typically used with the RMI service interface. Alternatively, this invoker can also proxy a remote RMI service with a matching non-RMI business interface, i.e. an interface that mirrors the RMI service methods but does not declare RemoteExceptions. In the latter case, RemoteExceptions thrown by the RMI stub will automatically get converted to Spring's unchecked RemoteAccessException.

Since:
29.09.2003
Author:
Juergen Hoeller
See Also:
RmiServiceExporter, RmiInvocationHandler, RemoteAccessException, RemoteException, Remote

Field Summary
 
Fields inherited from class org.springframework.remoting.support.RemoteAccessor
logger
 
Constructor Summary
RmiClientInterceptor()
           
 
Method Summary
 void afterPropertiesSet()
          Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
protected  java.rmi.Remote createRmiProxy()
          Create the RMI proxy.
protected  java.rmi.Remote getRmiProxy()
          Return the underlying RMI proxy that this interceptor delegates to.
 java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
           
protected  java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation methodInvocation, RmiInvocationHandler invocationHandler)
          Apply the given AOP method invocation to the given RmiInvocationHandler.
 
Methods inherited from class org.springframework.remoting.support.UrlBasedRemoteAccessor
getServiceUrl, setServiceUrl
 
Methods inherited from class org.springframework.remoting.support.RemoteAccessor
getServiceInterface, setServiceInterface
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RmiClientInterceptor

public RmiClientInterceptor()
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Description copied from interface: InitializingBean
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
java.lang.Exception - in the event of misconfiguration (such as failure to set an essential property) or if initialization fails.

createRmiProxy

protected java.rmi.Remote createRmiProxy()
                                  throws java.lang.Exception
Create the RMI proxy. Default implementation looks up the service URL via java.rmi.Naming. Can be overridden in subclasses.

Throws:
java.lang.Exception
See Also:
Naming.lookup(java.lang.String)

getRmiProxy

protected java.rmi.Remote getRmiProxy()
Return the underlying RMI proxy that this interceptor delegates to.


invoke

public java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
                        throws java.lang.Throwable
Specified by:
invoke in interface org.aopalliance.intercept.MethodInterceptor
Throws:
java.lang.Throwable

invoke

protected java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation methodInvocation,
                                  RmiInvocationHandler invocationHandler)
                           throws java.rmi.RemoteException,
                                  java.lang.NoSuchMethodException,
                                  java.lang.IllegalAccessException,
                                  java.lang.reflect.InvocationTargetException
Apply the given AOP method invocation to the given RmiInvocationHandler. The default implementation calls invoke with a plain RemoteInvocation.

Can be overridden in subclasses to provide custom RemoteInvocation subclasses, containing additional invocation parameters like user credentials. Can also process the returned result object.

Parameters:
methodInvocation - the current AOP method invocation
invocationHandler - the RmiInvocationHandler to apply the invocation to
Returns:
the invocation result
Throws:
java.lang.NoSuchMethodException - if the method name could not be resolved
java.lang.IllegalAccessException - if the method could not be accessed
java.lang.reflect.InvocationTargetException - if the method invocation resulted in an exception
java.rmi.RemoteException
See Also:
RemoteInvocation


Copyright (C) 2003-2004 The Spring Framework Project.