aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes how to check the type of JMS ObjectMessage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "how to check the type of JMS ObjectMessage " Watch "how to check the type of JMS ObjectMessage " New topic
Author

how to check the type of JMS ObjectMessage

Jack Bush
Ranch Hand

Joined: Oct 20, 2006
Posts: 235
Hi All,

I need advice on how to check the type of JMS ObjectMessage (e.g. Car/Truck/Van) in order to invoke appropriate persistent methods in a MDB. Below is the relevant code snippets I am referring to:


However, since I couldn't get line 3, 8 and 13 of jmsMessageProducer.createJMSMessageForjmsMyQueue correctly in order to setStringProperty() which resulted in the following NullPointerException occurring in jmsMessageConsumerMDB.onMessage shown in GF 2.1 server log:

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: [VehicleConsumer:jmsMessageConsumerMDB]: 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 $Proxy61.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.NullPointerException
at ejb.jmsMessageConsumerMDB.onMessage(jmsMessageConsumerMDB.java:6)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
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 $Proxy61.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@1bb453d
MQRA:OMR:run:Exhausted redeliveryAttempts-spec=ActvationSpec configuration=
DestinationType =javax.jms.Queue
Destination =vehicleQueue
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:runmrId=0:Acked Undeliverable-Msg=com.sun.messaging.jms.ra.DirectObjectPacket@1bb453d
MDB00037: [VehicleConsumer:jmsMessageConsumerMDB]: Message-driven bean invocation exception: [javax.ejb.EJBException]

I have been battling with this issue for quite sometime. Any suggestion on how to get the correct syntax/checks for line 3, 8 and 13 of jmsMessageProducer.createJMSMessageForjmsMyQueue would be much appreciated.

Thanks,

Jack
K Abhijit
Ranch Hand

Joined: Mar 03, 2008
Posts: 88
Jack:

there are 2 things:
1. why you are checking instance Of on objectMessage.Class ? any specific reason?

all your conditions if (objectMessage.getClass().isInstance("Car.class")) -->will always return false as you are freshly creating this object as
ObjectMessage objectMessage = session.createObjectMessage();

this has to be corrected..

2. Why are you not using instanceOf operator ?

you should use something like
if (messageData instanceOf Car ) {
4. objectMessage.setStringProperty("ObjectName", "Car");
5. objectMessage.setObject((Car)messageData);
6. }


let me know incase I'm missing anything here......


“The difference between 'involvement' and 'commitment' is like an eggs-and-ham breakfast: the chicken was 'involved' - the pig was 'committed'.”
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to check the type of JMS ObjectMessage