1 22 package org.jboss.tutorial.interceptor.bean; 23 24 import javax.interceptor.InvocationContext; 25 import javax.jms.JMSException ; 26 import javax.jms.Message ; 27 import javax.jms.Queue ; 28 import javax.jms.QueueConnection ; 29 import javax.jms.QueueConnectionFactory ; 30 import javax.jms.QueueSender ; 31 import javax.jms.QueueSession ; 32 import javax.jms.Session ; 33 34 39 public class AccountsCancelInterceptor extends AccountsInterceptor 40 { 41 QueueConnectionFactory cf; 42 43 Queue queue; 44 45 QueueConnection conn; 46 47 public Object sendCancelMessage(InvocationContext ctx) throws Exception 48 { 49 QueueSession session = null; 50 try 51 { 52 System.out.println("*** AccountsCancelInterceptor intercepting " + ctx.getMethod().getName()); 53 System.out.println("*** AccountsConfirmInterceptor - notifying accounts dept"); 54 session = getConnection().createQueueSession(false, Session.AUTO_ACKNOWLEDGE); 55 Message msg = session.createTextMessage("Cancelling order " + ctx.getParameters()[0]); 56 QueueSender sender = session.createSender(queue); 57 sender.send(msg); 58 59 return ctx.proceed(); 60 } 61 catch(Exception e) 62 { 63 throw new RuntimeException (e); 64 } 65 finally 66 { 67 try{session.close();}catch(Exception e) {} 68 System.out.println("*** AccountsCancelInterceptor exiting"); 69 } 70 } 71 72 QueueConnection getConnection() throws JMSException 73 { 74 if (conn == null) 75 { 76 synchronized(cf) 77 { 78 if (conn == null) 79 { 80 conn = cf.createQueueConnection(); 81 } 82 } 83 } 84 85 return conn; 86 } 87 } 88 | Popular Tags |