1 4 package org.objectweb.jonas.jtests.beans.j2eeca; 5 6 import javax.ejb.CreateException ; 7 import javax.ejb.SessionBean ; 8 import javax.ejb.SessionContext ; 9 import javax.naming.InitialContext ; 10 import javax.resource.spi.ConnectionEvent ; 11 12 import org.objectweb.jonas.common.Log; 13 import org.objectweb.util.monolog.api.BasicLevel; 14 import org.objectweb.util.monolog.api.Logger; 15 16 import fictional.resourceadapter.CommonClient; 17 import fictional.resourceadapter.ConnectionImpl; 18 import fictional.resourceadapter.JtestResourceAdapter; 19 20 21 23 public class runtimeCASLR implements SessionBean { 24 25 static private Logger logger = null; 26 SessionContext ejbContext; 27 private JtestResourceAdapter mcf = null; private CommonClient cccf = null; private ConnectionImpl conn = null; 30 private CommonClient csp = null; InitialContext ic=null; 32 private String res_auth = ""; 33 String cName = "runtimeCASLR"; 34 35 39 40 public void setSessionContext(SessionContext ctx) { 41 if (logger == null) { 42 logger = Log.getLogger("org.objectweb.jonas.jtests.j2eeca"); 43 } 44 logger.log(BasicLevel.DEBUG, ""); 45 ejbContext = ctx; 46 } 47 48 49 public void ejbRemove() { 50 logger.log(BasicLevel.DEBUG, ""); 51 } 52 53 54 public void ejbCreate() throws CreateException { 55 logger.log(BasicLevel.DEBUG, ""); 56 } 57 58 public void ejbPassivate() { 59 logger.log(BasicLevel.DEBUG, ""); 60 } 61 62 public void ejbActivate() { 63 logger.log(BasicLevel.DEBUG, ""); 64 } 65 66 public void setResAuth(String ra) { 70 res_auth=ra; } 72 73 76 public void method1(String rar_jndi_name, String testName) 77 throws Exception 78 { 79 logger.log(BasicLevel.DEBUG, "============================ "+testName); 80 logger.log(BasicLevel.DEBUG, cName+".method1 : lookup "+rar_jndi_name); 81 try { 82 ic = new InitialContext (); 83 } catch (Exception e1) { 84 logger.log(BasicLevel.DEBUG, cName+".method1 error: InitialContext failed"); 85 throw e1; 86 } 87 try { 88 cccf = (CommonClient)ic.lookup(rar_jndi_name); 89 logger.log(BasicLevel.DEBUG, cName+".method1 : found "+rar_jndi_name); 90 } catch (Exception e2) { 91 logger.log(BasicLevel.DEBUG, cName+".method1 error: lookup failed for "+rar_jndi_name); 92 throw e2; 93 } 94 95 try { 101 csp = new CommonClient(); csp.setUserName("Fictional_User_Name"); 103 csp.setPassword("__Jtest_Pass_word__"); 104 logger.log(BasicLevel.DEBUG, cName 105 +".method1 : ConnectionSpec + Fictional_User_Name,__Jtest_Pass_word__"); 106 } catch (Exception e3) { 107 logger.log(BasicLevel.DEBUG, cName+".method1 : new connection spec failed"); 108 throw e3; 109 } 110 try { 111 conn = (ConnectionImpl)cccf.getConnection(); 112 if (conn==null) { 113 logger.log(BasicLevel.DEBUG, cName+".method1 error: getConnection returned null connection."); 114 throw new Exception (""); 115 } 116 } catch (Exception e4) { 117 logger.log(BasicLevel.DEBUG, cName+".method1 error: getConnection failed " 118 +e4.toString()); 119 throw e4; 120 } 121 } 122 123 126 public void closeUp(int w) { 127 try { 128 if (w>0) { 129 conn.close(ConnectionEvent.CONNECTION_ERROR_OCCURRED); 132 logger.log(BasicLevel.DEBUG, cName+".closeUp : closed physical connection"); 133 } else { 134 conn.close(); 137 logger.log(BasicLevel.DEBUG, cName+".closeUp : closed connection"); 138 } 139 } catch (Exception e) { 140 logger.log(BasicLevel.DEBUG, cName+".closeUp error: close handle/physical connection failed"); 141 } 142 } 143 146 public int getMCF_Pwriter() 147 { 148 int here=2; 149 JtestResourceAdapter mcf = (JtestResourceAdapter) cccf.getMcf(); try { 151 if (mcf.getLogWriter()==null) { logger.log(BasicLevel.DEBUG, cName+".getMCF_Pwriter No PrintWriter registered"); 153 here=0; 154 } 155 else { 156 logger.log(BasicLevel.DEBUG, cName+".getMCF_Pwriter PrintWriter is o.k."); 157 here=1; 158 } 159 } catch (Exception e) { 160 logger.log(BasicLevel.DEBUG, cName+ 161 ".getMCF_Pwriter error: "+e.toString()); 162 } 163 return here; 164 } 165 public int getMC_Pwriter() 166 { 167 int here=2; 168 ConnectionImpl conni = (ConnectionImpl)conn; 169 try { 170 JtestResourceAdapter mc = (JtestResourceAdapter)conni.getMC(); if (mc.getLogWriter()==null) { logger.log(BasicLevel.DEBUG, cName+ 173 ".getMC_Pwriter No PrintWriter registered in ManagedConnection"); 174 here=0; 175 } 176 else { 177 logger.log(BasicLevel.DEBUG, cName+ 178 ".getMC_Pwriter PrintWriter in ManagedConnection is o.k."); 179 here=1; 180 } 181 } catch (Exception e) { 182 logger.log(BasicLevel.DEBUG, cName+ 183 ".getMC_Pwriter error: "+e.toString()); 184 } 185 return here; 186 } 187 public String getResAuth() { 188 mcf = (JtestResourceAdapter) cccf.getMcf(); try { 190 String ra = mcf.getRes_Auth(); logger.log(BasicLevel.DEBUG, cName+".getResAuth " 193 +"<res-auth>"+ra+"</res-auth>"); 194 return ra; 195 } catch (Exception e) { 196 logger.log(BasicLevel.DEBUG, cName 197 +".getResAuth error: failed to find <res-auth> " 198 +"in ManagedConnectionFactory"); 199 return ""; 200 } 201 } 202 public String getSecurityPassword() { 203 mcf = (JtestResourceAdapter) cccf.getMcf(); try { 206 String pw = mcf.getPassword(); 208 logger.log(BasicLevel.DEBUG, cName+".getSecurityPassword (" 209 +mcf.getRes_Auth()+")password="+pw); 210 return pw; 211 } catch (Exception e) { 212 String pw = mcf.getPassword(); logger.log(BasicLevel.DEBUG, cName 214 +".getSecurityPassword error: failed to find ManagedConnectionFactory " 215 +"instance containing password. Using pw="+pw); 216 return pw; 217 } 218 } 219 public String getSecurityUserName() { 220 mcf = (JtestResourceAdapter) cccf.getMcf(); try { 223 String u = mcf.getUserName(); 225 logger.log(BasicLevel.DEBUG, cName+".getSecurityUserName (" 226 +mcf.getRes_Auth()+")userName="+u); 227 return u; 228 } catch (Exception e) { 229 String u = mcf.getUserName(); logger.log(BasicLevel.DEBUG, cName 231 +".getSecurityUserName error: failed to find ManagedConnectionFactory " 232 +"instance containing userName. Using="+u); 233 return u; 234 } 235 } 236 } 237 238 | Popular Tags |