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.ConnectionManager ; 19 import ersatz.resourceadapter.*; 20 import javax.resource.spi.ConnectionEvent ; 21 22 23 25 public class RuntimeCASLR implements SessionBean { 26 27 SessionContext ejbContext; 28 private ManagedConnectionFactoryImpl mcf = null; private ConnectionFactoryImpl cccf = null; private ConnectionImpl conn = null; 31 private ConnectionSpecImpl csp = null; private ConnectionRequestInfoImpl crii = null; 33 InitialContext ic=null; 34 private String res_auth = ""; 35 String cName = "RuntimeCASLR"; 36 37 41 42 public void setSessionContext(SessionContext ctx) { 43 Utility.log(cName+".setSessionContext"); 44 ejbContext = ctx; 45 } 46 47 48 public void ejbRemove() { 49 Utility.log(cName+".ejbRemove"); 50 } 51 52 53 public void ejbCreate() throws CreateException { 54 Utility.log(cName+".ejbCreate"); 55 } 56 57 public void ejbPassivate() { 58 Utility.log(cName+".ejbPassivate"); 59 } 60 61 public void ejbActivate() { 62 Utility.log(cName+".ejbActivate"); 63 } 64 65 public void setResAuth(String ra) { 69 res_auth=ra; } 71 72 75 public void method1(String rar_jndi_name, String testName) 76 throws Exception 77 { 78 Utility.log("============================ "+testName); 79 Utility.log(cName+".method1 : lookup "+rar_jndi_name); 80 try { 81 ic = new InitialContext (); 82 } catch (Exception e1) { 83 Utility.log(cName+".method1 error: InitialContext failed"); 84 throw e1; 85 } 86 try { 87 cccf = (ConnectionFactoryImpl)ic.lookup(rar_jndi_name); 88 Utility.log(cName+".method1 : found "+rar_jndi_name); 89 } catch (Exception e2) { 90 Utility.log(cName+".method1 error: lookup failed for "+rar_jndi_name); 91 throw e2; 92 } 93 94 try { 100 csp = new ConnectionSpecImpl(); csp.setUserName("Ersatz_User_Name"); 102 csp.setPassword("__Jtest_Pass_word__"); 103 Utility.log(cName 104 +".method1 : ConnectionSpecImpl + Ersatz_User_Name,__Jtest_Pass_word__"); 105 } catch (Exception e3) { 106 Utility.log(cName+".method1 : new connection spec failed"); 107 throw e3; 108 } 109 try { 110 conn = (ConnectionImpl)cccf.getConnection(); 111 if (conn==null) { 112 Utility.log(cName+".method1 error: getConnection returned null connection."); 113 throw new Exception (""); 114 } 115 } catch (Exception e4) { 116 Utility.log(cName+".method1 error: getConnection failed " 117 +e4.toString()); 118 throw e4; 119 } 120 } 121 122 125 public void closeUp(int w) { 126 try { 127 if (w>0) { 128 conn.close(ConnectionEvent.CONNECTION_ERROR_OCCURRED); 131 Utility.log(cName+".closeUp : closed physical connection"); 132 } else { 133 conn.close(); 136 Utility.log(cName+".closeUp : closed connection"); 137 } 138 } catch (Exception e) { 139 Utility.log(cName+".closeUp error: close handle/physical connection failed"); 140 } 141 } 142 145 public int getMCF_Pwriter() 146 { 147 int here=2; 148 mcf = cccf.getMcf(); try { 150 if (mcf.getLogWriter()==null) { Utility.log(cName+".getMCF_Pwriter No PrintWriter registered in "+ 152 "ManagedConnectionFactoryImpl"); 153 here=0; 154 } 155 else { 156 Utility.log(cName+".getMCF_Pwriter PrintWriter is o.k.in "+ 157 "ManagedConnectionFactoryImpl"); 158 here=1; 159 } 160 } catch (Exception e) { 161 Utility.log(cName+ 162 ".getMCF_Pwriter error: "+e.toString()); 163 } 164 return here; 165 } 166 public int getMC_Pwriter() 167 { 168 int here=2; 169 try { 170 ManagedConnectionImpl mc = conn.getMC(); 171 if (mc.getLogWriter()==null) { Utility.log(cName+ 173 ".getMC_Pwriter No PrintWriter registered in ManagedConnectionImpl"); 174 here=0; 175 } 176 else { 177 Utility.log(cName+ 178 ".getMC_Pwriter PrintWriter in ManagedConnectionImpl is o.k."); 179 here=1; 180 } 181 } catch (Exception e) { 182 Utility.log(cName+ 183 ".getMC_Pwriter error: "+e.toString()); 184 } 185 return here; 186 } 187 public String getResAuth() { 188 try { 189 ManagedConnectionImpl mc = conn.getMC(); 190 String ra = mc.res_auth; Utility.log(cName+".getResAuth " 192 +"<res-auth>"+ra+"</res-auth>"); 193 if (ra==null || ra.length()==0) 194 throw new Exception (""); 195 return ra; 196 } catch (Exception e) { 197 Utility.log(cName 198 +".getResAuth error: failed to find <res-auth> " 199 +"in ManagedConnectionImpl"); 200 return ""; 201 } 202 } 203 public String getSecurityPassword() { 204 crii = conn.crii; try { 206 ManagedConnectionImpl mc = conn.getMC(); 207 String pw = crii.getPassword(); 208 Utility.log(cName+".getSecurityPassword (" 209 +mc.res_auth+")password="+pw); 210 if (pw==null || pw.length()==0) 211 throw new Exception (""); 212 return pw; 213 } catch (Exception e) { 214 mcf = cccf.getMcf(); 215 String pw = mcf.defaultPassword; Utility.log(cName 217 +".getSecurityPassword error: failed to find ConnectionRequestInfoImpl " 218 +"instance containing password. Using default="+pw); 219 return pw; 220 } 221 } 222 public String getSecurityUserName() { 223 crii = conn.crii; try { 225 ManagedConnectionImpl mc = conn.getMC(); 226 String u = crii.getUserName(); 227 Utility.log(cName+".getSecurityUserName (" 228 +mcf.getRes_Auth()+")userName="+u); 229 if (u==null || u.length()==0) 230 throw new Exception (""); 231 return u; 232 } catch (Exception e) { 233 mcf = cccf.getMcf(); 234 String u = mcf.defaultUserName; Utility.log(cName 236 +".getSecurityUserName error: failed to find ConnectionRequestInfoImpl " 237 +"instance containing userName. Using default="+u); 238 return u; 239 } 240 } 241 } 242 243 | Popular Tags |