org.springframework.remoting.rmi

## 类 JndiRmiClientInterceptor

- java.lang.Object
- - org.springframework.jndi.JndiAccessor
  - - org.springframework.jndi.JndiLocatorSupport
    - - org.springframework.jndi.JndiObjectLocator
      - - org.springframework.remoting.rmi.JndiRmiClientInterceptor

- 所有已实现的接口:
    org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor, org.springframework.beans.factory.InitializingBean
  直接已知子类:
    JndiRmiProxyFactoryBean

      public class JndiRmiClientInterceptor
      extends JndiObjectLocator
      implements org.aopalliance.intercept.MethodInterceptor, org.springframework.beans.factory.InitializingBean

  `MethodInterceptor` for accessing RMI services from JNDI. Typically used for RMI-IIOP but can also be used for EJB home objects (for example, a Stateful Session Bean home). In contrast to a plain JNDI lookup, this accessor also performs narrowing through PortableRemoteObject.

  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.

  The JNDI environment can be specified as "jndiEnvironment" property, or be configured in a `jndi.properties` file or as system properties. For example:

      <property name="jndiEnvironment">
               <props>
                       <prop key="java.naming.factory.initial">com.sun.jndi.cosnaming.CNCtxFactory</prop>
                       <prop key="java.naming.provider.url">iiop://localhost:1050</prop>
               </props>
       </property>

  从以下版本开始:
    1.1
  作者:
    Juergen Hoeller
  另请参阅:
    `JndiAccessor.setJndiTemplate(org.springframework.jndi.JndiTemplate)`, `JndiAccessor.setJndiEnvironment(java.util.Properties)`, `JndiObjectLocator.setJndiName(java.lang.String)`, `JndiRmiServiceExporter`, `JndiRmiProxyFactoryBean`, `RemoteAccessException`, `RemoteException`, `Remote`

- - ### 字段概要

    - ### 从类继承的字段 org.springframework.jndi.JndiLocatorSupport

      `CONTAINER_PREFIX`

    - ### 从类继承的字段 org.springframework.jndi.JndiAccessor

      `logger`

  - ### 构造器概要

    构造器
    构造器和说明
    `JndiRmiClientInterceptor()`

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `void` | `afterPropertiesSet()`
    `protected RemoteInvocation` | `createRemoteInvocation(org.aopalliance.intercept.MethodInvocation methodInvocation)` Create a new RemoteInvocation object for the given AOP method invocation.
    `protected Object` | `doInvoke(org.aopalliance.intercept.MethodInvocation invocation, Object stub)` Perform the given invocation on the given RMI stub.
    `protected Object` | `doInvoke(org.aopalliance.intercept.MethodInvocation methodInvocation, RmiInvocationHandler invocationHandler)` Apply the given AOP method invocation to the given `RmiInvocationHandler`.
    `RemoteInvocationFactory` | `getRemoteInvocationFactory()` Return the RemoteInvocationFactory used by this accessor.
    `Class<?>` | `getServiceInterface()` Return the interface of the service to access.
    `protected Object` | `getStub()` Return the RMI stub to use.
    `Object` | `invoke(org.aopalliance.intercept.MethodInvocation invocation)` Fetches an RMI stub and delegates to `doInvoke(org.aopalliance.intercept.MethodInvocation, java.lang.Object)`.
    `protected boolean` | `isConnectFailure(RemoteException ex)` Determine whether the given RMI exception indicates a connect failure.
    `protected Object` | `lookupStub()` Create the RMI stub, typically by looking it up.
    `void` | `prepare()` Fetches the RMI stub on startup, if necessary.
    `protected Object` | `refreshAndRetry(org.aopalliance.intercept.MethodInvocation invocation)` Refresh the RMI stub and retry the given invocation.
    `void` | `setCacheStub(boolean cacheStub)` Set whether to cache the RMI stub once it has been located.
    `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.
    `void` | `setLookupStubOnStartup(boolean lookupStubOnStartup)` Set whether to look up the RMI stub on startup.
    `void` | `setRefreshStubOnConnectFailure(boolean refreshStubOnConnectFailure)` Set whether to refresh the RMI stub on connect failure.
    `void` | `setRemoteInvocationFactory(RemoteInvocationFactory remoteInvocationFactory)` Set the RemoteInvocationFactory to use for this accessor.
    `void` | `setServiceInterface(Class<?> serviceInterface)` Set the interface of the service to access.

    - ### 从类继承的方法 org.springframework.jndi.JndiObjectLocator

      `getExpectedType, getJndiName, lookup, setExpectedType, setJndiName`

    - ### 从类继承的方法 org.springframework.jndi.JndiLocatorSupport

      `convertJndiName, isResourceRef, lookup, lookup, setResourceRef`

    - ### 从类继承的方法 org.springframework.jndi.JndiAccessor

      `getJndiEnvironment, getJndiTemplate, setJndiEnvironment, setJndiTemplate`

    - ### 从类继承的方法 java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 构造器详细资料

    - #### JndiRmiClientInterceptor

          public JndiRmiClientInterceptor()

  - ### 方法详细资料

    - #### setServiceInterface

          public void setServiceInterface(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 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.

      另请参阅:
        `setCacheStub(boolean)`

    - #### 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.

      另请参阅:
        `setLookupStubOnStartup(boolean)`

    - #### 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.

      另请参阅:
        `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 NamingException

      指定者:
        `afterPropertiesSet` 在接口中 `org.springframework.beans.factory.InitializingBean`
      覆盖:
        `afterPropertiesSet` 在类中 `JndiObjectLocator`
      抛出:
        `NamingException`

    - #### prepare

          public void prepare()
                       throws RemoteLookupFailureException

      Fetches the RMI stub on startup, if necessary.
      抛出:
        `RemoteLookupFailureException` - if RMI stub creation failed
      另请参阅:
        `setLookupStubOnStartup(boolean)`, `lookupStub()`

    - #### lookupStub

          protected Object lookupStub()
                               throws RemoteLookupFailureException

      Create the RMI stub, typically by looking it up.

      Called on interceptor initialization if "cacheStub" is "true"; else called for each invocation by `getStub()`.

      The default implementation retrieves the service from the JNDI environment. This can be overridden in subclasses.

      返回:
        the RMI stub to store in this interceptor
      抛出:
        `RemoteLookupFailureException` - if RMI stub creation failed
      另请参阅:
        `setCacheStub(boolean)`, `JndiObjectLocator.lookup()`

    - #### getStub

          protected Object getStub()
                            throws NamingException,
                                   RemoteLookupFailureException

      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
      抛出:
        `NamingException` - if stub creation failed
        `RemoteLookupFailureException` - if RMI stub creation failed

    - #### invoke

          public Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
                        throws Throwable

      Fetches an RMI stub and delegates to `doInvoke(org.aopalliance.intercept.MethodInvocation, java.lang.Object)`. If configured to refresh on connect failure, it will call `refreshAndRetry(org.aopalliance.intercept.MethodInvocation)` on corresponding RMI exceptions.
      指定者:
        `invoke` 在接口中 `org.aopalliance.intercept.MethodInterceptor`
      抛出:
        `Throwable`
      另请参阅:
        `getStub()`, `doInvoke(org.aopalliance.intercept.MethodInvocation, java.lang.Object)`, `refreshAndRetry(org.aopalliance.intercept.MethodInvocation)`, `ConnectException`, `ConnectIOException`, `NoSuchObjectException`

    - #### isConnectFailure

          protected boolean isConnectFailure(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

          @Nullable
          protected Object refreshAndRetry(org.aopalliance.intercept.MethodInvocation invocation)
                                               throws 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
      抛出:
        `Throwable` - in case of invocation failure
      另请参阅:
        `invoke(org.aopalliance.intercept.MethodInvocation)`

    - #### doInvoke

          @Nullable
          protected Object doInvoke(org.aopalliance.intercept.MethodInvocation invocation,
                                               Object stub)
                                        throws 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
      抛出:
        `Throwable` - in case of invocation failure

    - #### doInvoke

          protected Object doInvoke(org.aopalliance.intercept.MethodInvocation methodInvocation,
                                    RmiInvocationHandler invocationHandler)
                             throws RemoteException,
                                    NoSuchMethodException,
                                    IllegalAccessException,
                                    InvocationTargetException

      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
      抛出:
        `RemoteException` - in case of communication errors
        `NoSuchMethodException` - if the method name could not be resolved
        `IllegalAccessException` - if the method could not be accessed
        `InvocationTargetException` - if the method invocation resulted in an exception
      另请参阅:
        `RemoteInvocation`

    - #### createRemoteInvocation

          protected RemoteInvocation createRemoteInvocation(org.aopalliance.intercept.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
      另请参阅:
        `RemoteInvocationFactory.createRemoteInvocation(org.aopalliance.intercept.MethodInvocation)`