|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.jndi.JndiAccessor org.springframework.jndi.JndiLocatorSupport org.springframework.jndi.JndiObjectLocator org.springframework.remoting.rmi.JndiRmiClientInterceptor
public class JndiRmiClientInterceptor
Interceptor for accessing RMI services from JNDI. Typically used for RMI-IIOP (CORBA), 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>
JndiAccessor.setJndiTemplate(org.springframework.jndi.JndiTemplate)
,
JndiAccessor.setJndiEnvironment(java.util.Properties)
,
JndiObjectLocator.setJndiName(java.lang.String)
,
JndiRmiServiceExporter
,
JndiRmiProxyFactoryBean
,
RemoteAccessException
,
RemoteException
,
Remote
,
PortableRemoteObject.narrow(java.lang.Object, java.lang.Class)
Field Summary |
---|
Fields inherited from class org.springframework.jndi.JndiLocatorSupport |
---|
CONTAINER_PREFIX |
Fields inherited from class org.springframework.jndi.JndiAccessor |
---|
logger |
Constructor Summary | |
---|---|
JndiRmiClientInterceptor()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
Check the jndiName property and initiate a lookup. |
protected Object |
doInvoke(MethodInvocation invocation,
Remote stub)
Perform the given invocation on the given RMI stub. |
Class |
getServiceInterface()
Return the interface of the service to access. |
protected Remote |
getStub()
Return the RMI stub to use. |
Object |
invoke(MethodInvocation invocation)
Fetches an RMI stub and delegates to doInvoke. |
protected boolean |
isConnectFailure(RemoteException ex)
Determine whether the given RMI exception indicates a connect failure. |
protected Remote |
lookupStub()
Create the RMI stub, typically by looking it up. |
void |
prepare()
Fetches RMI stub on startup, if necessary. |
protected Object |
refreshAndRetry(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 |
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 |
setServiceInterface(Class serviceInterface)
Set the interface of the service to access. |
Methods inherited from class org.springframework.jndi.JndiObjectLocator |
---|
getJndiName, lookup, setJndiName |
Methods inherited from class org.springframework.jndi.JndiLocatorSupport |
---|
convertJndiName, isResourceRef, lookup, setResourceRef |
Methods inherited from class org.springframework.jndi.JndiAccessor |
---|
getJndiEnvironment, getJndiTemplate, setJndiEnvironment, setJndiTemplate |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JndiRmiClientInterceptor()
Method Detail |
---|
public void setServiceInterface(Class serviceInterface)
Typically required to be able to create a suitable service proxy, but can also be optional if the lookup returns a typed stub.
public Class getServiceInterface()
public void setLookupStubOnStartup(boolean lookupStubOnStartup)
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)
public void setCacheStub(boolean cacheStub)
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)
public void setRefreshStubOnConnectFailure(boolean refreshStubOnConnectFailure)
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
public void afterPropertiesSet() throws NamingException
JndiObjectLocator
The JNDI object will thus be fetched eagerly on initialization.
For refreshing the JNDI object, subclasses can invoke lookup
at any later time.
afterPropertiesSet
in interface InitializingBean
afterPropertiesSet
in class JndiObjectLocator
NamingException
JndiObjectLocator.lookup()
public void prepare() throws NamingException
NamingException
- if thrown by JNDI APIsetLookupStubOnStartup(boolean)
,
lookupStub()
protected Remote lookupStub() throws NamingException
Default implementation looks up the service URL via java.rmi.Naming. Can be overridden in subclasses.
NamingException
- if stub creation failedsetCacheStub(boolean)
,
getStub()
,
Naming.lookup(java.lang.String)
protected Remote getStub() throws NamingException
Default implementation returns the stub created on initialization, if any; else, it invokes lookupStub to get a new stub for each invocation.
Can be overridden in subclasses, for example to cache a stub for a given amount of time before recreating it, or to test the stub whether it is still alive.
NamingException
- if stub creation failedlookupStub()
public Object invoke(MethodInvocation invocation) throws Throwable
invoke
in interface MethodInterceptor
Throwable
getStub()
,
doInvoke(org.aopalliance.intercept.MethodInvocation, java.rmi.Remote)
,
refreshAndRetry(org.aopalliance.intercept.MethodInvocation)
,
ConnectException
,
ConnectIOException
,
NoSuchObjectException
protected boolean isConnectFailure(RemoteException ex)
ex
- the RMI exception to check
RmiClientInterceptorUtils.isConnectFailure(java.rmi.RemoteException)
protected Object refreshAndRetry(MethodInvocation invocation) throws Throwable
invocation
- the AOP method invocation
Throwable
- in case of invocation failureinvoke(org.aopalliance.intercept.MethodInvocation)
protected Object doInvoke(MethodInvocation invocation, Remote stub) throws Throwable
invocation
- the AOP method invocationstub
- the RMI stub to invoke
Throwable
- in case of invocation failure
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |