Base class for interceptors proxying remote Stateless Session Beans.
Designed for EJB 2.x, but works for EJB 3 Session Beans as well.
Such an interceptor must be the last interceptor in the advice chain.
In this case, there is no target object.
| Method from org.springframework.ejb.access.AbstractRemoteSlsbInvokerInterceptor Detail: |
abstract protected Object doInvoke(MethodInvocation invocation) throws Throwable
Perform the given invocation on the current EJB home.
Template method to be implemented by subclasses. |
protected Method getCreateMethod(Object home) throws EjbAccessException {
if (this.homeAsComponent) {
return null;
}
if (!(home instanceof EJBHome)) {
// An EJB3 Session Bean...
this.homeAsComponent = true;
return null;
}
return super.getCreateMethod(home);
}
Check for EJB3-style home object that serves as EJB component directly. |
public Object invokeInContext(MethodInvocation invocation) throws Throwable {
try {
return doInvoke(invocation);
}
catch (RemoteConnectFailureException ex) {
return handleRemoteConnectFailure(invocation, ex);
}
catch (RemoteException ex) {
if (isConnectFailure(ex)) {
return handleRemoteConnectFailure(invocation, ex);
}
else {
throw ex;
}
}
}
Fetches an EJB home object and delegates to doInvoke.
If configured to refresh on connect failure, it will call
#refreshAndRetry on corresponding RMI exceptions. |
protected boolean isConnectFailure(RemoteException ex) {
return RmiClientInterceptorUtils.isConnectFailure(ex);
}
|
protected boolean isHomeRefreshable() {
return this.refreshHomeOnConnectFailure;
}
|
protected Object lookup() throws NamingException {
Object homeObject = super.lookup();
if (this.homeInterface != null) {
try {
homeObject = PortableRemoteObject.narrow(homeObject, this.homeInterface);
}
catch (ClassCastException ex) {
throw new RemoteLookupFailureException(
"Could not narrow EJB home stub to home interface [" + this.homeInterface.getName() + "]", ex);
}
}
return homeObject;
}
This overridden lookup implementation performs a narrow operation
after the JNDI lookup, provided that a home interface is specified. |
protected Object newSessionBeanInstance() throws NamingException, InvocationTargetException {
if (logger.isDebugEnabled()) {
logger.debug("Trying to create reference to remote EJB");
}
Object ejbInstance = create();
if (logger.isDebugEnabled()) {
logger.debug("Obtained reference to remote EJB: " + ejbInstance);
}
return ejbInstance;
}
|
protected Object refreshAndRetry(MethodInvocation invocation) throws Throwable {
try {
refreshHome();
}
catch (NamingException ex) {
throw new RemoteLookupFailureException("Failed to locate remote EJB [" + getJndiName() + "]", ex);
}
return doInvoke(invocation);
}
Refresh the EJB home object and retry the given invocation.
Called by invoke on connect failure. |
protected void removeSessionBeanInstance(EJBObject ejb) {
if (ejb != null && !this.homeAsComponent) {
try {
ejb.remove();
}
catch (Throwable ex) {
logger.warn("Could not invoke 'remove' on remote EJB proxy", ex);
}
}
}
Remove the given EJB instance.
To be invoked by concrete remote SLSB invoker subclasses. |
public void setHomeInterface(Class homeInterface) {
if (homeInterface != null && !homeInterface.isInterface()) {
throw new IllegalArgumentException(
"Home interface class [" + homeInterface.getClass() + "] is not an interface");
}
this.homeInterface = homeInterface;
}
Set a home interface that this invoker will narrow to before performing
the parameterless SLSB create() call that returns the actual
SLSB proxy.
Default is none, which will work on all J2EE servers that are not based
on CORBA. A plain javax.ejb.EJBHome interface is known to be
sufficient to make a WebSphere 5.0 Remote SLSB work. On other servers,
the specific home interface for the target SLSB might be necessary. |
public void setRefreshHomeOnConnectFailure(boolean refreshHomeOnConnectFailure) {
this.refreshHomeOnConnectFailure = refreshHomeOnConnectFailure;
}
Set whether to refresh the EJB home on connect failure.
Default is "false".
Can be turned on to allow for hot restart of the EJB server.
If a cached EJB home throws an RMI exception that indicates a
remote connect failure, a fresh home will be fetched and the
invocation will be retried. |