views:

303

answers:

1

I have a Java application that sets a listener on a queue, the onMessage(Message) gets a subclass of javax.jms.TextMessage, how can i make it get a subclass of javax.jms.BytesMessage

Note: I don't have access to the application that sends the messages.

+1  A: 

The message type is determined by the sender. If the sender can't change, the received message type can't change.

What's the ultimate goal? Can you change how the receiver processes the message to accomplish what you're trying to do? Having the String from a TextMessage, you could use String.getBytes() to get the byte array version of that String.

If you want to do anything much more exotic than that, wouldn't you need some cooperation from the sender anyway?

John M
String.getBytes() will return the platform default. If the bytes in the TextMessage is something other than the platform default, then the bytes will be garbled. Instead, use String.getBytes(String) where the parameter is the encoding of the Text message.
noahz