users@glassfish.java.net

MDB00037: Message-driven bean invocation exception: [javax.ejb.EJBException

From: <glassfish_at_javadesktop.org>
Date: Sun, 21 Feb 2010 18:14:19 PST

Hi Forum members,

I have encountered the following error in Glassfish v2.1 server log when trying to retrieve Customer object from a JMS message queue:

MQRA:OMR:run:Caught Exception from onMessage():Redelivering:message-driven bean method public abstract void javax.jms.MessageListener.onMessage(javax.jms.Message) system exception
MDB00037: [FundsBean:JmsCustomerMDB]: Message-driven bean invocation exception: [javax.ejb.EJBException]
javax.ejb.EJBException
        at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:3894)
        at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:3794)
        at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:3596)
        at com.sun.ejb.containers.MessageBeanContainer.afterMessageDeliveryInternal(MessageBeanContainer.java:1226)
        at com.sun.ejb.containers.MessageBeanContainer.afterMessageDelivery(MessageBeanContainer.java:1197)
        at com.sun.ejb.containers.MessageBeanListenerImpl.afterMessageDelivery(MessageBeanListenerImpl.java:79)
        at com.sun.enterprise.connectors.inflow.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:139)
        at $Proxy47.afterDelivery(Unknown Source)
        at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:324)
        at com.sun.enterprise.connectors.work.OneWork.doWork(OneWork.java:76)
        at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
Caused by: java.lang.ClassCastException: com.sun.messaging.jms.ra.DirectObjectPacket cannot be cast to domain.Customer
        at ejb.JmsCustomerMDB.onMessage(JmsCustomerMDB.java:30)
        at sun.reflect.GeneratedMethodAccessor90.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1011)
        at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:175)
        at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2920)
        at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4011)
        at com.sun.ejb.containers.MessageBeanContainer.deliverMessage(MessageBeanContainer.java:1111)
        at com.sun.ejb.containers.MessageBeanListenerImpl.deliverMessage(MessageBeanListenerImpl.java:74)
        at com.sun.enterprise.connectors.inflow.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:179)
        at $Proxy47.onMessage(Unknown Source)
        at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:258)
        ... 2 more
MQRA:OMR:run:Caught Exception from onMessage():Redelivering:message-driven bean method public abstract void javax.jms.MessageListener.onMessage(javax.jms.Message) system exception
MQRA:OMR:run:Exhausted redeliveryAttempts-msg=com.sun.messaging.jms.ra.DirectObjectPacket_at_6d3233
MQRA:OMR:run:Exhausted redeliveryAttempts-spec=ActvationSpec configuration=
        DestinationType =javax.jms.Queue
        Destination =myQueue
        MessageSelector =null
        AcknowledgeMode =Auto-acknowledge
        SubscriptionDurability =NonDurable
        ClientId =null
        SubscriptionName =null
        EndpointPoolMaxSize =32
        EndpointPoolSteadySize =0
        EndpointPoolResizeCount =8
        EndpointPoolResizeTimeout =600
        EndpointExceptionRedeliveryAttempts =1
        EndpointExceptionRedeliveryInterval =500
        SendUndeliverableMsgsToDMQ =true
        GroupName =null
        RAUID =null
        InClusteredContainer =false
        MdbName =null
        UserName =null
        EnableDirect =true
        AddressList (in effect) =localhost:7676
MQRA:OMR:run:Message returned & marked for routing to the DMQ
MQRA:OMR:run:omrId=2:Acked Undeliverable-Msg=com.sun.messaging.jms.ra.DirectObjectPacket_at_6d3233


Below are snippets of the Java EE 5 codes intended to send a Customer object to a JMS queue for a received MDB to add into the database:

@Stateless
public class CustomerBean implements CustomerLocal { # only declared Local interface
    
    @PersistenceContext(unitName="FundsDB-PU") private EntityManager manager;
    
    public void createCustomer(Customer Customer)
    {
        manager.persist(Customer);
    }
....
}
-----------------------------------------------------------------------------------------------------------------------
@MessageDriven(mappedName = "jms/myQueue", activationConfig = {
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
    })

public class JmsCustomerMDB implements MessageListener {

    @EJB
    private CustomerLocal Customerbean;

    public JmsCustomerMDB() {
    }

    public void onMessage(Message message) {
        ObjectMessage objectMessage = (ObjectMessage) message;
        System.out.println(((Customer)objectMessage).getCustomerName());
        Customerbean.createCustomer((Customer)objectMessage);
    ....
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    public Message createJMSMessageForjmsMyQueue(Session session, Object messageData) throws JMSException {
        ObjectMessage objectMessage = session.createObjectMessage();
        objectMessage.setObject((Customer)messageData);
        return objectMessage;
    }
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    public void sendJMSMessageToMyQueue(Object messageData) throws JMSException {
        connection = myQueueConnectionFactory.createConnection();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer messageProducer = session.createProducer(myQueue);
        messageProducer.send(createJMSMessageForjmsMyQueue(session, messageData));
    }
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class JMSCustomerApplicationClient {

    @Resource(mappedName = "jms/myQueue")
    private static Queue myQueue;
    @Resource(mappedName = "jms/myQueueConnectionFactory")
    private static ConnectionFactory myQueueConnectionFactory;

    public static void main(String[] args)
    {
        Customer customer = new Customer();
        customer.setName("Joe Blah");
        new JMSCustomerApplicationClient().sendJMSMessageToMyQueue(customer);
    }
        ----------------------------------------------------------------------------------------------------------------------------------------------------------
        public Message createJMSMessageForjmsMyQueue(Session session, Object messageData) throws JMSException {
        ObjectMessage objectMessage = session.createObjectMessage();
        objectMessage.setObject((Customer)messageData);
        return objectMessage;
    }
        ----------------------------------------------------------------------------------------------------------------------------------------------------------
    public void sendJMSMessageToMyQueue(Object messageData) throws JMSException {
            connection = myQueueConnectionFactory.createConnection();
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            MessageProducer messageProducer = session.createProducer(myQueue);
            messageProducer.send(createJMSMessageForjmsMyQueue(session, messageData));
    }
}

Any ideas on what is wrong with it? Is there anyway to check the number of messages in the queue?

I also like to declare both declare both CustomerLocal.java & CustomerRemote.java to provide flexibility to access CustomerBean.java from local & remote but Netbeans insisted that the 2 can only exist with different methods in it.

Thanks,

Jack
[Message sent by forum member 'htran_888' (htran_888_at_yahoo.com.au)]

http://forums.java.net/jive/thread.jspa?messageID=387913