ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » Getting error while reading message with MQMD Format blank

Post new topic  Reply to topic
 Getting error while reading message with MQMD Format blank « View previous topic :: View next topic » 
Author Message
tapak
PostPosted: Fri Aug 24, 2007 7:05 am    Post subject: Getting error while reading message with MQMD Format blank Reply with quote

Centurion

Joined: 26 Oct 2005
Posts: 149
Location: Hartford,CT

Whenever we try to read a native MQ message with MessageFormat field in MQMD Header is blank , IBM JMS API returns the object as Bytemessage even if the data in the message is string .

When we try to get the data from the Bytemessage object ,we are getting the following exception . Is there a reason this condition is not handled by MQ JMS to get valid data.? Or Is there any method I can use to get the data without throwing an exception.

As a work around ,we are catching the exception , java.io.StreamCorruptedException and converting the bytes to string.


1.
Code:

if (JMSMsg instanceof BytesMessage) {

                             BytesMessage bJMSMsg = (BytesMessage) JMSMsg;
                                                                             
                             String str = bJMSMsg.readUTF();

Code above throws following exception.
javax.jms.MessageEOFException: MQJMS0005: Unexpected end of stream has been reached when a StreamMessage or BytesMessage is being read
     at com.ibm.jms.JMSMessage.newMessageEOFException(JMSMessage.java:4629)
     at com.ibm.jms.JMSBytesMessage.readUnsignedShort(JMSBytesMessage.java:1033)
     at com.ibm.jms.JMSBytesMessage.readUTF(JMSBytesMessage.java:1097)


2.

Code:


if (JMSMsg instanceof BytesMessage) {

                             BytesMessage bJMSMsg = (BytesMessage) JMSMsg;
                             
                             byte[] array = new byte[(int) bJMSMsg.getBodyLength()];
                             bJMSMsg.readBytes(array);
                             if (array == null)
                                     return null;
                             ByteArrayInputStream inBytes = new ByteArrayInputStream(array);
                             

                             ObjectInputStream inStream = new ObjectInputStream(inBytes);
                             oMsg = inStream.readObject();

java.io.StreamCorruptedException: invalid stream header
     at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:737)
     at java.io.ObjectInputStream.<init>(ObjectInputStream.java:253)



[/code]
_________________
IBM Certified Solution Designer -- WebSphere MQ V5.3
IBM Certified Solution Designer -- WebSphere Business Integration - Message Broker V5
IBM Certified Specialist -- IBM WebSphere App Svr Advd Single Svr Ed. for Multiplatforms (Java)
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Fri Aug 24, 2007 7:18 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Don't use readUTF() unless you know that the sender of the message had used writeUTF().
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Fri Aug 24, 2007 8:22 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Don't assume that because you have a BytesMessage that you have a serialized java object... That should be an ObjectMessage....
So no you cannot deserialize a java object from a BytesMessage.

If you know however that the content is text, you can use the String constructor/method accepting a byte array...

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
tapak
PostPosted: Fri Aug 24, 2007 9:39 am    Post subject: Reply with quote

Centurion

Joined: 26 Oct 2005
Posts: 149
Location: Hartford,CT

Thanks very much for your inputs . Yes. write now I am trying to convert it to String using the String constructor. I am not sure if it is always a string . So basically I catch the exception and try to convert it to string.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Getting error while reading message with MQMD Format blank
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.