1 25 package org.objectweb.easybeans.tests.common.ejbs.mdb.beanmanaged.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.ejb.TransactionManagement ; 41 import javax.ejb.TransactionManagementType ; 42 import javax.jms.JMSException ; 43 import javax.jms.Message ; 44 import javax.jms.MessageListener ; 45 46 import org.objectweb.easybeans.log.JLog; 47 import org.objectweb.easybeans.log.JLogFactory; 48 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.BaseInsertOperation; 49 import org.objectweb.easybeans.tests.common.jms.JMSManager; 50 import org.objectweb.easybeans.tests.common.jms.MessageProperty; 51 52 57 @MessageDriven (messageListenerInterface = MessageListener .class, activationConfig = { 58 @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue"), 59 @ActivationConfigProperty (propertyName = "destination", propertyValue = JMSManager.DEFAULT_QUEUE), 60 @ActivationConfigProperty (propertyName = "messageSelector", 61 propertyValue = 62 "TYPE = 'org.objectweb.easybeans.tests.common.ejbs.mdb.beanmanaged.context.MDBBeanManagedContext'")}) 63 @TransactionManagement (TransactionManagementType.BEAN) 64 public class MDBBeanManagedContext extends BaseInsertOperation { 65 66 69 public static final String MESSAGE_TYPE = 70 "org.objectweb.easybeans.tests.common.ejbs.mdb.beanmanaged.context.MDBBeanManagedContext"; 71 72 75 @Resource 76 private MessageDrivenContext ctx; 77 78 81 private JLog logger = JLogFactory.getLog(MDBBeanManagedContext.class); 82 83 87 public void onMessage(final Message msg) { 88 String op = null; 89 90 try { 91 op = msg.getStringProperty(MessageProperty.OPERATION.toString()); 92 } catch (JMSException e) { 93 logger.debug("Error getting operation type: {0}", e); 94 } 95 96 if(ctx == null){ 97 logger.debug("The SessionContext reference is null."); 98 } else if (isEqual(GET_CALLER_PRINCIPAL, op)) { 99 100 102 } else if (isEqual(GET_ROLLBACK_ONLY, op)) { 103 try{ 104 ctx.getRollbackOnly(); 105 }catch(IllegalStateException e){ 106 log(MDBBeanManagedContext.class, ON_MESSAGE, MDBBeanManagedContext.class, GET_ROLLBACK_ONLY); 107 }catch (Exception e) { 108 logger.debug("Unexpected error.", e); 109 } 110 111 } else if (isEqual(SET_ROLLBACK_ONLY, op)) { 112 try{ 113 ctx.setRollbackOnly(); 114 }catch(IllegalStateException e){ 115 log(MDBBeanManagedContext.class, ON_MESSAGE, MDBBeanManagedContext.class, SET_ROLLBACK_ONLY); 116 } 117 118 }else if (isEqual(TIMER, op)){ 119 try { 120 checkInstance(ctx.getTimerService()); 121 log(MDBBeanManagedContext.class, ON_MESSAGE, MDBBeanManagedContext.class, TIMER); 122 } catch (Exception e) { 123 logger.debug("Unexpected error.", e); 124 } 125 126 }else if (isEqual(USER_TRANSACTION, op)) { 127 try { 128 checkInstance(ctx.getTimerService()); 129 log(MDBBeanManagedContext.class, ON_MESSAGE, MDBBeanManagedContext.class, USER_TRANSACTION); 130 } catch (Exception e) { 131 logger.debug("Unexpected error.", e); 132 } 133 } 134 } 135 } 136 | Popular Tags |