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 24 public class securedCASLR implements SessionBean { 25 26 static private Logger logger = null; 27 SessionContext ejbContext; 28 private JtestResourceAdapter mcf = null; private CommonClient cccf = null; private ConnectionImpl conn = null; 31 InitialContext ic=null; 32 private String res_auth = ""; 33 String cName = "securedCASLR"; 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, cName+".setSessionContext"); 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 69 public void closeUp(int w) { 70 try { 71 if (w>0) { 72 conn.close(ConnectionEvent.CONNECTION_ERROR_OCCURRED); 75 logger.log(BasicLevel.DEBUG, cName+".closeUp : closed physical connection"); 76 } else { 77 conn.close(); 80 logger.log(BasicLevel.DEBUG, cName+".closeUp : closed connection"); 81 } 82 } catch (Exception e) { 83 logger.log(BasicLevel.DEBUG, cName+".closeUp error: close handle/physical connection failed"); 84 } 85 } 86 public void setResAuth(String ra) { 87 res_auth=ra; } 89 public void setMatchNull(boolean b) { 90 mcf = (JtestResourceAdapter) cccf.getMcf(); mcf.setMatchNull(b); 92 } 93 97 100 public void method1(String rar_jndi_name, String testName) 101 throws Exception 102 { 103 logger.log(BasicLevel.DEBUG, "============================ "+testName); 104 try { 105 ic = new InitialContext (); 106 } catch (Exception e1) { 107 logger.log(BasicLevel.DEBUG, cName+".method1 error: InitialContext failed"); 108 throw e1; 109 } 110 try { 111 cccf = (CommonClient)ic.lookup(rar_jndi_name); 112 logger.log(BasicLevel.DEBUG, cName+".method1 : found "+rar_jndi_name); 113 } catch (Exception e2) { 114 logger.log(BasicLevel.DEBUG, cName+".method1 error: lookup failed for "+rar_jndi_name); 115 throw e2; 116 } 117 118 try { 124 conn = (ConnectionImpl)cccf.getConnection(); 125 logger.log(BasicLevel.DEBUG, cName+".method1 : getConnection() 'Container' conn="+conn); 126 127 if (conn==null) { 128 logger.log(BasicLevel.DEBUG, cName+".method1 error: getConnection returned null connection."); 129 throw new Exception (""); 130 } 131 } catch (Exception e4) { 132 logger.log(BasicLevel.DEBUG, cName+".method1 error: getConnection failed " 133 +e4.toString()); 134 throw e4; 135 } 136 } 137 138 public String getResAuth() { 139 mcf = (JtestResourceAdapter) cccf.getMcf(); try { 141 String ra = mcf.getRes_Auth(); logger.log(BasicLevel.DEBUG, cName+".getResAuth " 144 +"<res-auth>"+ra+"</res-auth>"); 145 return ra; 146 } catch (Exception e) { 147 logger.log(BasicLevel.DEBUG, cName 148 +".getResAuth error: failed to find <res-auth> " 149 +"in ManagedConnectionFactory"); 150 return ""; 151 } 152 } 153 public String getSecurityPassword() { 154 mcf = (JtestResourceAdapter) cccf.getMcf(); try { 157 String pw = mcf.getPassword(); 159 logger.log(BasicLevel.DEBUG, cName+".getSecurityPassword (" 160 +mcf.getRes_Auth()+")password="+pw); 161 return pw; 162 } catch (Exception e) { 163 String pw = mcf.getPassword(); logger.log(BasicLevel.DEBUG, cName 165 +".getSecurityPassword error: failed to find ManagedConnectionFactory " 166 +"instance containing password. Using pw="+pw); 167 return pw; 168 } 169 } 170 public String getSecurityUserName() { 171 mcf = (JtestResourceAdapter) cccf.getMcf(); try { 174 String u = mcf.getUserName(); 176 logger.log(BasicLevel.DEBUG, cName+".getSecurityUserName (" 177 +mcf.getRes_Auth()+")userName="+u); 178 return u; 179 } catch (Exception e) { 180 String u = mcf.getUserName(); logger.log(BasicLevel.DEBUG, cName 182 +".getSecurityUserName error: failed to find ManagedConnectionFactory " 183 +"instance containing userName. Using="+u); 184 return u; 185 } 186 } 187 188 } 189 190 | Popular Tags |