1 22 package org.jboss.ejb3.test.dd.mdb; 23 24 import javax.annotation.Resource; 25 import javax.ejb.MessageDrivenBean ; 26 import javax.ejb.MessageDrivenContext ; 27 import javax.ejb.EJBException ; 28 29 import javax.jms.MessageListener ; 30 import javax.jms.Message ; 31 import javax.naming.Context ; 32 import javax.naming.InitialContext ; 33 import javax.naming.NamingException ; 34 import javax.sql.DataSource ; 35 36 import org.jboss.logging.Logger; 37 import org.jboss.ejb3.Container; 38 import org.jboss.ejb3.test.dd.mdb.StatelessLocal; 39 import org.jboss.ejb3.test.dd.mdb.StatelessRemote; 40 41 50 51 public class QueueBean implements MessageDrivenBean , MessageListener 52 { 53 private static final Logger log = Logger.getLogger(QueueBean.class); 54 55 private MessageDrivenContext ctx = null; 56 57 StatelessRemote stateless; 58 StatelessLocal statelessLocal; 59 DataSource testDatasource; 60 61 public QueueBean() 62 { 63 64 } 65 66 @Resource 67 public void setMessageDrivenContext(MessageDrivenContext ctx) throws EJBException 68 { 69 this.ctx = ctx; 70 } 71 72 public void ejbCreate() 73 { 74 } 75 76 public void ejbRemove() 77 { 78 ctx = null; 79 } 80 81 public void onMessage(Message message) 82 { 83 log.debug("DEBUG: QueueBean got message" + message.toString()); 84 try 85 { 86 testInjections(); 87 TestStatusBean.addDestination(message.getJMSDestination()); 88 } 89 catch(Exception e) 90 { 91 e.printStackTrace(); 92 } 93 } 94 95 public void setStatelessLocal(StatelessLocal statelessLocal) 96 { 97 this.statelessLocal = statelessLocal; 98 } 99 100 private void testInjections() throws Exception 101 { 102 stateless.test(); 103 statelessLocal.testLocal(); 104 testDatasource.getConnection(); 105 106 Context initCtx = new InitialContext (); 107 Context myEnv = (Context ) initCtx.lookup(Container.ENC_CTX_NAME + "/env"); 108 Object obj = myEnv.lookup("res/aQueue"); 109 if ((obj instanceof javax.jms.Queue ) == false) 110 throw new NamingException ("res/aQueue is not a javax.jms.Queue"); 111 112 obj = myEnv.lookup("testDatasource"); 113 if ((obj instanceof javax.sql.DataSource ) == false) 114 throw new NamingException ("testDatasource is not a javax.sql.DataSource"); 115 } 116 } 118 | Popular Tags |