Convert JMS BytesMessage to String in java and use the same bytesmessage in another process
<p>My code is listening to an IBM MQ. Receives JMS BytesMessage, converts it to string in the receiver class and pass on the same JMS BytesMessage to another processor class. Processor class again converts it into String. Both receiver class and processor class use the same code like below to get the string from BytesMessage. I am getting the right string in the Receiver class but when trying to get the string from the BytesMessage in Processor class its returning empty string. Please advise what has to be done in addition to preserve the JMS BytesMessage so that it gets converted to String in the Processor class as well.</p>

<p>Code that sends message to processor:</p>

<pre><code>String strMessage = null;
strMessage = getStringFromMessage(Message message)
process(message)
</code></pre>

<p>Code used for String Conversion:</p>

<pre><code>if (message instanceof BytesMessage){
 BytesMessage byteMessage = (BytesMessage) message;
 byte[] byteData = null;
 byteData = new byte[(int) byteMessage.getBodyLength()];
 byteMessage.readBytes(byteData);
 stringMessage =  new String(byteData);
}
</code></pre>