1

I'm working on an EJB3 MDB that listen to a MQ queue in a distant server. All is working fine (MDB triggered when a message is put into the listenned queue) except the treatment done by the MDB. For information, i use WMQ resource adapter to map the queue.

Into the method 'onMessage' of the MDB, i try to cast the given message into the class 'com.ibm.jms.JMSBytesMessage', but i get a strange error message.

The code is the following one (simple for the example):

public void onMessage(Message theMessage) {
  ((JMSBytesMessage) theMessage).readBytes(myBytes);
}

And the exception message:

Exception while reading input request: com.ibm.jms.JMSBytesMessage incompatible with com.ibm.jms.JMSBytesMessage

Ok, the message received should be (and is) type 'com.ibm.jms.JMSBytesMessage', so why the application doesn't work ? Should it be possible that my JBoss server already use another version of the library 'com.ibm.mqjms.jar' (including the JMSBytesMessage class) and cause this kind of error ?

ps: i've deployed the application on a JBoss server version 4.2.3 under linux system. I've already make the application work on my local machine with same version of JBoss server but under window system (same configuration, same libraries, etc.)

Does someone have an idea about the reason of such error ?

Thanks in advance for any help.

Regards,

EDIT: SOLUTION: cast with javax.jms.BytesMessage instead of com.ibm.jms.JMSBytesMessage

MaDa
  • 10,511
  • 9
  • 46
  • 84
kij
  • 1,421
  • 1
  • 16
  • 40
  • 1
    Why are you casting it all? There's no point in using JMS if you're not going to stick to the interfaces that JMS provides. Can't you cast to `javax.jms.BytesMessage` instead? – skaffman Jan 25 '11 at 13:52
  • I tried to cast BytesMessage but the MDB have a strange behaviour (read message from input queue, but looks like rollback the message and read it again). But the neither the error message appears nor other treatment traces (so nothing is done in the MDB) : i tried to catch both 'Exception' and 'Error' types and display a trace but nothing is displayed in the logs. So for the moment, casting with javax.jms.BytesMessage doesn't work but i don't know why. But you're right, there is no need to cast with something else than javax.jms.BytesMesasge – kij Jan 25 '11 at 15:49
  • Finally it works fine casting to javax.jms.BytesMessage. Something is wrong later in my code. Thanks for your help – kij Jan 25 '11 at 16:11
  • Ok, it now works. Doesn't really know why it didn't work before... so now i use javax.jms.BytesMessage. Thanks for your help – kij Jan 26 '11 at 10:38

1 Answers1

3

Might as well reproduce my comment as answer:

Don't cast to the MQ-specific com.ibm.jms.JMSBytesMessage, cast to the JMS-standard javax.jms.BytesMessage. Coupling your code to the implementation-specific types is counter to what JMS tries to achieve.

skaffman
  • 398,947
  • 96
  • 818
  • 769