1 package example; 2 3 import java.util.logging.Level; 4 import java.util.logging.Logger; 5 6 import javax.ejb.EJBException; 7 import javax.ejb.MessageDrivenBean; 8 import javax.ejb.MessageDrivenContext; 9 10 import javax.jms.Message; 11 import javax.jms.MessageListener; 12 import javax.jms.TextMessage; 13 14 public class SimpleMessageBean implements MessageDrivenBean, MessageListener { 15 static protected final Logger log = 16 Logger.getLogger(SimpleMessageBean.class.getName()); 17 18 public void ejbCreate() 19 throws EJBException 20 { 21 log.fine("ejbCreate()"); 22 } 23 24 public void setMessageDrivenContext(MessageDrivenContext cxt) 25 throws EJBException 26 { 27 log.fine("setMessageDrivenContext()"); 28 } 29 30 public void onMessage(Message msg) 31 { 32 String text = null; 34 35 if (msg instanceof TextMessage) { 36 try { 37 text = ((TextMessage) msg).getText(); 38 } catch (Exception ex) { 39 log.log(Level.WARNING,null,ex); 40 } 41 } 42 else { 43 text = msg.toString(); 44 } 45 46 log.info("onMessage(): " + text); 47 } 48 49 public void ejbRemove() 50 throws EJBException 51 { 52 log.fine("ejbRemove()"); 53 } 54 } 55 56 | Popular Tags |