1 22 package org.jboss.ejb3.test.mdb; 23 24 import javax.ejb.ActivationConfigProperty ; 25 import javax.interceptor.AroundInvoke; 26 import javax.interceptor.InvocationContext; 27 import javax.ejb.MessageDriven ; 28 import javax.ejb.MessageDrivenContext ; 29 import javax.ejb.EJB ; 30 import javax.annotation.PostConstruct; 31 import javax.annotation.PreDestroy; 32 import javax.annotation.Resource; 33 import javax.jms.Message ; 34 import javax.jms.MessageListener ; 35 import javax.naming.InitialContext ; 36 37 import javax.annotation.security.RunAs; 38 39 import org.jboss.annotation.security.SecurityDomain; 40 import org.jboss.logging.Logger; 41 42 48 @MessageDriven (activationConfig = 49 { 50 @ActivationConfigProperty (propertyName="destinationType", propertyValue="javax.jms.Queue"), 51 @ActivationConfigProperty (propertyName="destination", propertyValue="queue/mdbtest") 52 }) 53 @RunAs("TestRole") 54 @SecurityDomain("other") 55 public class QueueTestMDB implements MessageListener 56 { 57 private static final Logger log = Logger.getLogger(QueueTestMDB.class); 58 59 @EJB (beanName="LocalStateless") 60 Stateless localStateless; 61 62 public int count = 0; 63 64 @Resource MessageDrivenContext ctx; 65 66 public void onMessage(Message recvMsg) 67 { 68 if (ctx == null) throw new RuntimeException ("FAILED ON CTX LOOKUP"); 69 ++count; 70 ++TestStatusBean.queueRan; 71 TestStatusBean.messageCount = count; 72 73 System.out.println("+++ QueueTestMDB onMessage " + TestStatusBean.queueRan + " " + count + " " + this); 74 75 testInjections(); 76 77 try { 78 InitialContext jndiContext = new InitialContext (); 79 Stateless stateless = (Stateless)jndiContext.lookup("Stateless"); 80 stateless.setState("Set"); 81 } catch (Exception e) 82 { 83 e.printStackTrace(); 84 } 85 System.out.println("--- QueueTestMDB onMessage " + TestStatusBean.queueRan + " " + count + " " + this); 86 87 } 88 89 protected void testInjections() 90 { 91 localStateless.setState("testing"); 92 } 93 94 @AroundInvoke 95 public Object intercept(InvocationContext ctx) throws Exception 96 { 97 TestStatusBean.interceptedQueue = true; 98 return ctx.proceed(); 99 } 100 101 @PostConstruct 102 public void postConstruct() 103 { 104 TestStatusBean.postConstruct = true; 105 } 106 107 @PreDestroy 108 public void preDestroy() 109 { 110 TestStatusBean.preDestroy = true; 111 } 112 } 113 | Popular Tags |