1 25 package org.objectweb.easybeans.tests.common.ejbs.mdb.containermanaged.context; 26 27 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType.ON_MESSAGE; 28 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.GET_CALLER_PRINCIPAL; 29 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.GET_ROLLBACK_ONLY; 30 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.SET_ROLLBACK_ONLY; 31 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.TIMER; 32 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.USER_TRANSACTION; 33 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.isEqual; 34 import static org.objectweb.easybeans.tests.common.resources.TimerServiceTester.checkInstance; 35 36 import javax.annotation.Resource; 37 import javax.ejb.ActivationConfigProperty ; 38 import javax.ejb.MessageDriven ; 39 import javax.ejb.MessageDrivenContext ; 40 import javax.jms.JMSException ; 41 import javax.jms.Message ; 42 import javax.jms.MessageListener ; 43 44 import org.objectweb.easybeans.log.JLog; 45 import org.objectweb.easybeans.log.JLogFactory; 46 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.BaseInsertOperation; 47 import org.objectweb.easybeans.tests.common.jms.JMSManager; 48 import org.objectweb.easybeans.tests.common.jms.MessageProperty; 49 50 55 @MessageDriven (messageListenerInterface = MessageListener .class, activationConfig = { 56 @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue"), 57 @ActivationConfigProperty (propertyName = "destination", propertyValue = JMSManager.DEFAULT_QUEUE), 58 @ActivationConfigProperty (propertyName = "messageSelector", propertyValue = "TYPE = 'org.objectweb.easybeans.tests." 59 + "common.ejbs.mdb.containermanaged.context.MDBContext'")}) 60 public class MDBContext extends BaseInsertOperation { 61 62 65 public static final String MESSAGE_TYPE = "org.objectweb.easybeans.tests.common.ejbs.mdb.containermanaged.context.MDBContext"; 66 67 70 @Resource 71 private MessageDrivenContext ctx; 72 73 76 private JLog logger = JLogFactory.getLog(MDBContext.class); 77 78 82 public void onMessage(final Message msg) { 83 String op = null; 84 85 try { 86 op = msg.getStringProperty(MessageProperty.OPERATION.toString()); 87 } catch (JMSException e) { 88 logger.debug("Error getting operation type: {0}", e); 89 } 90 91 if(ctx == null){ 92 logger.debug("The SessionContext reference is null."); 93 }else if (isEqual(GET_CALLER_PRINCIPAL, op)) { 94 95 97 } else if (isEqual(GET_ROLLBACK_ONLY, op) | isEqual(SET_ROLLBACK_ONLY, op)) { 98 ctx.setRollbackOnly(); 99 if (ctx.getRollbackOnly()) { 100 log(MDBContext.class, ON_MESSAGE, MDBContext.class, GET_ROLLBACK_ONLY); 101 } 102 103 } else if (isEqual(TIMER, op)) { 104 try { 105 checkInstance(ctx.getTimerService()); 106 log(MDBContext.class, ON_MESSAGE, MDBContext.class, TIMER); 107 } catch (Exception e) { 108 e.printStackTrace(); 109 } 110 } else if (isEqual(USER_TRANSACTION, op)) { 111 try { 112 ctx.getUserTransaction(); 113 } catch (IllegalStateException e) { 114 log(MDBContext.class, ON_MESSAGE, MDBContext.class, USER_TRANSACTION); 115 } 116 } 117 118 } 119 120 } 121 | Popular Tags |