1 16 17 package org.springframework.ejb.access; 18 19 import java.lang.reflect.InvocationTargetException ; 20 import java.rmi.RemoteException ; 21 22 import javax.ejb.CreateException ; 23 import javax.ejb.EJBObject ; 24 import javax.naming.NamingException ; 25 26 import org.aopalliance.intercept.MethodInvocation; 27 28 import org.springframework.remoting.RemoteLookupFailureException; 29 import org.springframework.remoting.rmi.RmiClientInterceptorUtils; 30 31 62 public class SimpleRemoteSlsbInvokerInterceptor extends AbstractRemoteSlsbInvokerInterceptor { 63 64 71 protected Object doInvoke(MethodInvocation invocation) throws Throwable { 72 EJBObject ejb = null; 73 try { 74 ejb = getSessionBeanInstance(); 75 return RmiClientInterceptorUtils.doInvoke(invocation, ejb); 76 } 77 catch (NamingException ex) { 78 throw new RemoteLookupFailureException("Failed to locate remote EJB [" + getJndiName() + "]", ex); 79 } 80 catch (InvocationTargetException ex) { 81 Throwable targetEx = ex.getTargetException(); 82 if (targetEx instanceof RemoteException ) { 83 RemoteException rex = (RemoteException ) targetEx; 84 throw RmiClientInterceptorUtils.convertRmiAccessException( 85 invocation.getMethod(), rex, isConnectFailure(rex), getJndiName()); 86 } 87 else if (targetEx instanceof CreateException ) { 88 throw RmiClientInterceptorUtils.convertRmiAccessException( 89 invocation.getMethod(), targetEx, "Could not create remote EJB [" + getJndiName() + "]"); 90 } 91 throw targetEx; 92 } 93 finally { 94 if (ejb != null) { 95 releaseSessionBeanInstance(ejb); 96 } 97 } 98 } 99 100 107 protected EJBObject getSessionBeanInstance() throws NamingException , InvocationTargetException { 108 return newSessionBeanInstance(); 109 } 110 111 117 protected void releaseSessionBeanInstance(EJBObject ejb) { 118 removeSessionBeanInstance(ejb); 119 } 120 121 } 122 | Popular Tags |