1 22 package org.jboss.test.naming.ejb; 23 24 import javax.ejb.CreateException ; 25 import javax.ejb.EJBException ; 26 import javax.ejb.SessionBean ; 27 import javax.ejb.SessionContext ; 28 import javax.jms.JMSException ; 29 import javax.jms.Queue ; 30 import javax.jms.Topic ; 31 import javax.naming.Context ; 32 import javax.naming.InitialContext ; 33 import javax.naming.NamingException ; 34 35 import org.jboss.logging.Logger; 36 37 43 public class TestENCBean implements SessionBean 44 { 45 Logger log = Logger.getLogger(getClass()); 46 47 private SessionContext sessionContext; 48 49 public void ejbCreate() throws CreateException 50 { 51 } 52 53 public void ejbActivate() 55 { 56 } 57 58 public void ejbPassivate() 59 { 60 } 61 62 public void ejbRemove() 63 { 64 } 65 66 public void setSessionContext(SessionContext sessionContext) throws EJBException 67 { 68 this.sessionContext = sessionContext; 69 } 70 71 73 public long stressENC(long iterations) 74 { 75 long start = System.currentTimeMillis(); 76 for(int i = 0; i < iterations; i ++) 77 accessENC(); 78 long end = System.currentTimeMillis(); 79 return end - start; 80 } 81 82 public void accessENC() 83 { 84 try 85 { 86 Context initCtx = new InitialContext (); 88 Context myEnv = (Context ) initCtx.lookup("java:comp/env"); 89 Boolean hasFullENC = (Boolean ) myEnv.lookup("hasFullENC"); 90 log.debug("ThreadContext CL = " + Thread.currentThread().getContextClassLoader()); 91 log.debug("hasFullENC = " + hasFullENC); 92 if (hasFullENC.equals(Boolean.TRUE)) 93 { 94 testEnvEntries(initCtx, myEnv); 96 testEjbRefs(initCtx, myEnv); 97 testJdbcDataSource(initCtx, myEnv); 98 testMail(initCtx, myEnv); 99 testJMS(initCtx, myEnv); 100 testURL(initCtx, myEnv); 101 testResourceEnvEntries(initCtx, myEnv); 102 testMessageDestinationRefs(initCtx, myEnv); 103 } 104 else 105 { 106 try 108 { 109 Integer i = (Integer ) myEnv.lookup("Ints/i0"); 110 throw new EJBException ("Was able to find java:comp/env/Ints/i0 in bean with hasFullENC = false"); 111 } 112 catch (NamingException e) 113 { 114 } 116 } 117 } 118 catch (NamingException e) 119 { 120 log.debug("failed", e); 121 throw new EJBException (e.toString(true)); 122 } 123 catch (JMSException e) 124 { 125 log.debug("failed", e); 126 throw new EJBException (e); 127 } 128 } 129 130 private void testEnvEntries(Context initCtx, Context myEnv) throws NamingException 131 { 132 Integer i = (Integer ) myEnv.lookup("Ints/i0"); 134 log.debug("Ints/i0 = " + i); 135 i = (Integer ) initCtx.lookup("java:comp/env/Ints/i1"); 136 log.debug("Ints/i1 = " + i); 137 Float f = (Float ) myEnv.lookup("Floats/f0"); 138 log.debug("Floats/f0 = " + f); 139 f = (Float ) initCtx.lookup("java:comp/env/Floats/f1"); 140 log.debug("Floats/f1 = " + f); 141 String s = (String ) myEnv.lookup("Strings/s0"); 142 log.debug("Strings/s0 = " + s); 143 s = (String ) initCtx.lookup("java:comp/env/Strings/s1"); 144 log.debug("Strings/s1 = " + s); 145 Short s0 = (Short ) myEnv.lookup("Short/s0"); 146 log.debug("Short/s0 = " + s0); 147 Long l0 = (Long ) myEnv.lookup("Long/l0"); 148 log.debug("Long/s0 = " + l0); 149 Double d0 = (Double ) myEnv.lookup("Double/d0"); 150 log.debug("Double/s0 = " + d0); 151 Byte b0 = (Byte ) myEnv.lookup("Byte/b0"); 152 log.debug("Byte/b0 = " + b0); 153 Character c0 = (Character ) myEnv.lookup("Character/c0"); 154 log.debug("Character/c0 = " + c0); 155 } 156 157 private void testEjbRefs(Context initCtx, Context myEnv) throws NamingException 158 { 159 Object ejb = myEnv.lookup("ejb/bean0"); 161 if ((ejb instanceof javax.ejb.EJBHome ) == false) 162 throw new NamingException ("ejb/bean0 is not a javax.ejb.EJBHome"); 163 log.debug("ejb/bean0 = " + ejb); 164 ejb = initCtx.lookup("java:comp/env/ejb/bean1"); 165 log.debug("ejb/bean1 = " + ejb); 166 ejb = initCtx.lookup("java:comp/env/ejb/bean2"); 167 log.debug("ejb/bean2 = " + ejb); 168 ejb = null; 170 log.debug("ejb/remote-bean = " + ejb); 171 } 172 173 private void testJdbcDataSource(Context initCtx, Context myEnv) throws NamingException 174 { 175 Object obj = myEnv.lookup("jdbc/DefaultDS"); 177 if ((obj instanceof javax.sql.DataSource ) == false) 178 throw new NamingException ("jdbc/DefaultDS is not a javax.sql.DataSource"); 179 log.debug("jdbc/DefaultDS = " + obj); 180 } 181 182 private void testMail(Context initCtx, Context myEnv) throws NamingException 183 { 184 Object obj = myEnv.lookup("mail/DefaultMail"); 186 if ((obj instanceof javax.mail.Session ) == false) 187 throw new NamingException ("mail/DefaultMail is not a javax.mail.Session"); 188 log.debug("mail/DefaultMail = " + obj); 189 } 190 191 private void testJMS(Context initCtx, Context myEnv) throws NamingException 192 { 193 Object obj = myEnv.lookup("jms/QueFactory"); 195 if ((obj instanceof javax.jms.QueueConnectionFactory ) == false) 196 throw new NamingException ("mail/DefaultMail is not a javax.jms.QueueConnectionFactory"); 197 log.debug("jms/QueFactory = " + obj); 198 } 199 200 private void testURL(Context initCtx, Context myEnv) throws NamingException 201 { 202 Object obj = myEnv.lookup("url/JBossHomePage"); 204 if ((obj instanceof java.net.URL ) == false) 205 throw new NamingException ("url/JBossHomePage is not a java.net.URL"); 206 log.debug("url/SourceforgeHomePage = " + obj); 207 208 obj = myEnv.lookup("url/SourceforgeHomePage"); 209 if ((obj instanceof java.net.URL ) == false) 210 throw new NamingException ("url/SourceforgeHomePage is not a java.net.URL"); 211 log.debug("url/SourceforgeHomePage = " + obj); 212 213 obj = myEnv.lookup("url/IndirectURL"); 214 if ((obj instanceof java.net.URL ) == false) 215 throw new NamingException ("url/IndirectURL is not a java.net.URL"); 216 log.debug("url/IndirectURL = " + obj); 217 } 218 219 private void testResourceEnvEntries(Context initCtx, Context myEnv) throws NamingException 220 { 221 Object obj = myEnv.lookup("res/aQueue"); 222 if ((obj instanceof javax.jms.Queue ) == false) 223 throw new NamingException ("res/aQueue is not a javax.jms.Queue"); 224 log.debug("res/aQueue = " + obj); 225 } 226 227 private void testMessageDestinationRefs(Context initCtx, Context myEnv) throws NamingException , JMSException 228 { 229 Object obj = myEnv.lookup("mdr/ConsumesLink"); 230 log.debug("mdr/ConsumesLink = " + obj); 231 if ((obj instanceof Queue ) == false) 232 throw new RuntimeException ("mdr/ConsumesLink is not a javax.jms.Queue"); 233 Queue queue = (Queue ) obj; 234 if ("QUEUE.testQueue".equals(queue.getQueueName())) 235 throw new RuntimeException ("Excepted QUEUE.testQueue, got " + queue); 236 237 obj = myEnv.lookup("mdr/ProducesLink"); 238 log.debug("mdr/ProducesLink = " + obj); 239 if ((obj instanceof Topic ) == false) 240 throw new RuntimeException ("mdr/ProducesLink is not a javax.jms.Topic"); 241 Topic topic = (Topic ) obj; 242 if ("TOPIC.testTopic".equals(topic.getTopicName())) 243 throw new RuntimeException ("Excepted TOPIC.testTopic got " + topic); 244 245 obj = myEnv.lookup("mdr/ConsumesProducesJNDIName"); 246 log.debug("mdr/ConsumesProducesJNDIName = " + obj); 247 if ((obj instanceof Queue ) == false) 248 throw new RuntimeException ("mdr/ConsumesProducesJNDIName is not a javax.jms.Queue"); 249 queue = (Queue ) obj; 250 if ("QUEUE.A".equals(queue.getQueueName())) 251 throw new RuntimeException ("Excepted QUEUE.A, got " + queue); 252 } 253 254 } 255 | Popular Tags |