1 4 package org.objectweb.jonas.jtests.beans.jca15; 5 6 import java.rmi.RemoteException ; 7 import javax.ejb.CreateException ; 8 import javax.ejb.EJBException ; 9 import javax.ejb.RemoveException ; 10 import javax.ejb.EJBObject ; 11 import javax.ejb.SessionBean ; 12 import javax.ejb.SessionContext ; 13 import javax.naming.Context ; 14 import javax.naming.InitialContext ; 15 import javax.naming.NamingException ; 16 import javax.resource.cci.Connection ; 17 import javax.resource.spi.ManagedConnection ; 18 import javax.resource.spi.ConnectionEvent ; 19 import javax.resource.spi.ResourceAdapter ; 20 import ersatz.resourceadapter.ManagedConnectionFactoryImpl; 21 import ersatz.resourceadapter.ConnectionImpl; 22 import ersatz.resourceadapter.ConnectionFactoryImpl; 23 import ersatz.resourceadapter.ResourceAdapterImpl; 24 25 26 29 public class InboundCASLR implements SessionBean { 30 31 SessionContext ejbContext; 32 private ConnectionFactoryImpl cccf = null; private ManagedConnectionFactoryImpl mcf = null; 34 private ConnectionImpl conn = null; 35 InitialContext ic=null; 36 String cName = "InboundCASLR"; 37 38 42 43 public void setSessionContext(SessionContext ctx) { 44 Utility.log(cName+"setSessionContext"); 45 ejbContext = ctx; 46 } 47 48 49 public void ejbRemove() { 50 Utility.log(""); 51 } 52 53 54 public void ejbCreate() throws CreateException { 55 Utility.log(""); 56 } 57 58 public void ejbPassivate() { 59 Utility.log(""); 60 } 61 62 public void ejbActivate() { 63 Utility.log(""); 64 } 65 66 70 73 public void method1(String rar_jndi_name, String testName) 74 throws Exception 75 { 76 Utility.log("============================ "+testName); 77 try { 78 ic = new InitialContext (); 79 } catch (Exception e1) { 80 Utility.log(cName+".method1 error: InitialContext failed"); 81 throw e1; 82 } 83 try { 84 cccf = (ConnectionFactoryImpl)ic.lookup(rar_jndi_name); 85 Utility.log(cName+".method1 : found "+rar_jndi_name); 86 } catch (Exception e2) { 87 Utility.log(cName+".method1 error: lookup failed for "+rar_jndi_name); 88 throw e2; 89 } 90 91 try { 92 conn = (ConnectionImpl)cccf.getConnection(); 93 Utility.log(cName+".method1 : getConnection conn="+conn); 94 if (conn==null) { 95 Utility.log(cName+".method1 error: getConnection returned null connection."); 96 throw new Exception (""); 97 } 98 } catch (Exception e3) { 99 Utility.log(cName+".method1 error: getConnection failed " 100 +e3.toString()); 101 throw e3; 102 } 103 104 } 105 106 109 public void closeUp(int w) { 110 try { 111 if (w>0) { 112 conn.close(ConnectionEvent.CONNECTION_ERROR_OCCURRED); 115 Utility.log(cName+".closeUp : closed physical connection"); 116 } else { 117 conn.close(); 120 Utility.log(cName+".closeUp : closed connection"); 121 } 122 } catch (Exception e) { 123 Utility.log(cName+".closeUp error: close handle/physical connection failed"); 124 } 125 } 126 129 130 133 public String getEIS_URL() 134 throws Exception 135 { 136 Utility.log(cName+".getEIS_URL"); 137 mcf = (ManagedConnectionFactoryImpl) cccf.getMcf(); 138 ResourceAdapterImpl ra = (ResourceAdapterImpl)mcf.getResourceAdapter(); 139 140 String cp1 = "none"; 141 if (ra==null) return cp1; 142 try { 143 cp1 = ra.getEIS_URL(); 144 } catch (Exception e) { 145 Utility.log(cName+".getEIS_URL get <configuration-property> error: failed"); 146 throw e; 147 } 148 return cp1; 149 } 150 public boolean deliverMsg(String msg) throws Exception 151 { 152 boolean success; 153 154 Utility.log(cName+".deliverMsg to resource adapter"); 155 mcf = (ManagedConnectionFactoryImpl) cccf.getMcf(); 156 ResourceAdapterImpl ra = (ResourceAdapterImpl)mcf.getResourceAdapter(); 157 try { 158 success = ra.deliverMsg(msg); 159 Utility.log(cName+".deliverMsg o.k. msg="+msg); 160 } catch (Exception e) { 161 Utility.log(cName+".deliverMsg error: e="+e.toString()); 162 success=false; 163 } 164 return success; 165 } 166 } 167 168 | Popular Tags |