Class JndiRmiClientInterceptor

    • Constructor Detail

      • JndiRmiClientInterceptor

        public JndiRmiClientInterceptor()
    • Method Detail

      • setServiceInterface

        public void setServiceInterface(java.lang.Class<?> serviceInterface)
        Set the interface of the service to access. The interface must be suitable for the particular service and remoting tool.

        Typically required to be able to create a suitable service proxy, but can also be optional if the lookup returns a typed stub.

      • getServiceInterface

        public java.lang.Class<?> getServiceInterface()
        Return the interface of the service to access.
      • setRemoteInvocationFactory

        public void setRemoteInvocationFactory(RemoteInvocationFactory remoteInvocationFactory)
        Set the RemoteInvocationFactory to use for this accessor. Default is a DefaultRemoteInvocationFactory.

        A custom invocation factory can add further context information to the invocation, for example user credentials.

      • getRemoteInvocationFactory

        public RemoteInvocationFactory getRemoteInvocationFactory()
        Return the RemoteInvocationFactory used by this accessor.
      • setLookupStubOnStartup

        public void setLookupStubOnStartup(boolean lookupStubOnStartup)
        Set whether to look up the RMI stub on startup. Default is "true".

        Can be turned off to allow for late start of the RMI server. In this case, the RMI stub will be fetched on first access.

        See Also:
      • setCacheStub

        public void setCacheStub(boolean cacheStub)
        Set whether to cache the RMI stub once it has been located. Default is "true".

        Can be turned off to allow for hot restart of the RMI server. In this case, the RMI stub will be fetched for each invocation.

        See Also:
      • setRefreshStubOnConnectFailure

        public void setRefreshStubOnConnectFailure(boolean refreshStubOnConnectFailure)
        Set whether to refresh the RMI stub on connect failure. Default is "false".

        Can be turned on to allow for hot restart of the RMI server. If a cached RMI stub throws an RMI exception that indicates a remote connect failure, a fresh proxy will be fetched and the invocation will be retried.

        See Also:
        ConnectException, ConnectIOException, NoSuchObjectException
      • setExposeAccessContext

        public void setExposeAccessContext(boolean exposeAccessContext)
        Set whether to expose the JNDI environment context for all access to the target RMI stub, i.e. for all method invocations on the exposed object reference.

        Default is "false", i.e. to only expose the JNDI context for object lookup. Switch this flag to "true" in order to expose the JNDI environment (including the authorization context) for each RMI invocation, as needed by WebLogic for RMI stubs with authorization requirements.

      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws javax.naming.NamingException
        Description copied from interface: InitializingBean
        Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

        This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

        Specified by:
        afterPropertiesSet in interface InitializingBean
        afterPropertiesSet in class JndiObjectLocator
      • getStub

        protected java.lang.Object getStub()
                                    throws javax.naming.NamingException,
        Return the RMI stub to use. Called for each invocation.

        The default implementation returns the stub created on initialization, if any. Else, it invokes lookupStub() to get a new stub for each invocation. This can be overridden in subclasses, for example in order to cache a stub for a given amount of time before recreating it, or to test the stub whether it is still alive.

        the RMI stub to use for an invocation
        javax.naming.NamingException - if stub creation failed
        RemoteLookupFailureException - if RMI stub creation failed
      • isConnectFailure

        protected boolean isConnectFailure(java.rmi.RemoteException ex)
        Determine whether the given RMI exception indicates a connect failure.

        The default implementation delegates to RmiClientInterceptorUtils.isConnectFailure(java.rmi.RemoteException).

        ex - the RMI exception to check
        whether the exception should be treated as connect failure
      • refreshAndRetry

        protected java.lang.Object refreshAndRetry(MethodInvocation invocation)
                                                      throws java.lang.Throwable
        Refresh the RMI stub and retry the given invocation. Called by invoke on connect failure.
        invocation - the AOP method invocation
        the invocation result, if any
        java.lang.Throwable - in case of invocation failure
        See Also:
      • doInvoke

        protected java.lang.Object doInvoke(MethodInvocation invocation,
                                                      java.lang.Object stub)
                                               throws java.lang.Throwable
        Perform the given invocation on the given RMI stub.
        invocation - the AOP method invocation
        stub - the RMI stub to invoke
        the invocation result, if any
        java.lang.Throwable - in case of invocation failure
      • doInvoke

        protected java.lang.Object doInvoke(MethodInvocation methodInvocation,
                                            RmiInvocationHandler invocationHandler)
                                     throws java.rmi.RemoteException,
        Apply the given AOP method invocation to the given RmiInvocationHandler.

        The default implementation delegates to createRemoteInvocation(org.aopalliance.intercept.MethodInvocation).

        methodInvocation - the current AOP method invocation
        invocationHandler - the RmiInvocationHandler to apply the invocation to
        the invocation result
        java.rmi.RemoteException - in case of communication errors
        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
        See Also:
      • createRemoteInvocation

        protected RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation)
        Create a new RemoteInvocation object for the given AOP method invocation.

        The default implementation delegates to the configured RemoteInvocationFactory. This can be overridden in subclasses in order to provide custom RemoteInvocation subclasses, containing additional invocation parameters (e.g. user credentials).

        Note that it is preferable to build a custom RemoteInvocationFactory as a reusable strategy, instead of overriding this method.

        methodInvocation - the current AOP method invocation
        the RemoteInvocation object
        See Also: