1 22 package org.jboss.ejb3.test.consumer; 23 24 import javax.interceptor.AroundInvoke; 25 import javax.interceptor.InvocationContext; 26 import javax.annotation.PostConstruct; 27 import javax.annotation.PreDestroy; 28 import javax.jms.Message ; 29 import javax.naming.Context ; 30 import javax.naming.InitialContext ; 31 import javax.naming.NamingException ; 32 import javax.sql.DataSource ; 33 34 import org.jboss.ejb3.Container; 35 import org.jboss.logging.Logger; 36 37 41 public class DeploymentDescriptorQueueTestConsumer implements DeploymentDescriptorQueueTestRemote, DeploymentDescriptorQueueTestXA, DeploymentDescriptorQueueTestLocal 42 { 43 private static final Logger log = Logger.getLogger(DeploymentDescriptorQueueTestConsumer.class); 44 45 Message currentMessage; 46 47 private Message setterMessage; 48 49 StatelessRemote stateless; 50 StatelessLocal statelessLocal; 51 DataSource testDatasource; 52 53 public void setStatelessLocal(StatelessLocal statelessLocal) 54 { 55 this.statelessLocal = statelessLocal; 56 } 57 58 void setMessage(Message msg) 59 { 60 setterMessage = msg; 61 } 62 63 private void testInjections() throws Exception 64 { 65 stateless.test(); 66 statelessLocal.testLocal(); 67 testDatasource.getConnection(); 68 69 Context initCtx = new InitialContext (); 70 Context myEnv = (Context) initCtx.lookup(Container.ENC_CTX_NAME + "/env"); 71 Object obj = myEnv.lookup("res/aQueue"); 72 if ((obj instanceof javax.jms.Queue ) == false) 73 throw new NamingException ("res/aQueue is not a javax.jms.Queue"); 74 } 75 76 public void method1(String msg, int num) throws Exception 77 { 78 testInjections(); 79 80 TestStatusBean.queueRan = "method1"; 81 TestStatusBean.fieldMessage = currentMessage != null; 82 TestStatusBean.setterMessage = setterMessage != null; 83 84 System.out.println("method1(" + msg + ", " + num + ")"); 85 } 86 87 public void method2(String msg, float num) 88 { 89 TestStatusBean.queueRan = "method2"; 90 91 TestStatusBean.fieldMessage = currentMessage != null; 92 TestStatusBean.setterMessage = setterMessage != null; 93 94 System.out.println("method2(" + msg + ", " + num + ")"); 95 } 96 97 @AroundInvoke 98 public Object intercept(InvocationContext ctx) throws Exception 99 { 100 System.out.println("**** intercepted ****" + ctx.getMethod().getName()); 101 TestStatusBean.interceptedQueue = ctx.getMethod().getName(); 102 return ctx.proceed(); 103 } 104 105 @PostConstruct 106 public void postConstruct() 107 { 108 TestStatusBean.postConstruct = true; 109 } 110 111 @PreDestroy 112 public void preDestroy() 113 { 114 TestStatusBean.preDestroy = true; 115 } 116 } 117 | Popular Tags |