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 » Problem reading messages from queue using readString/CONVERT

Post new topic  Reply to topic
 Problem reading messages from queue using readString/CONVERT « View previous topic :: View next topic » 
Author Message
sachin_gk
PostPosted: Thu Oct 28, 2004 7:43 am    Post subject: Problem reading messages from queue using readString/CONVERT Reply with quote

Newbie

Joined: 16 May 2001
Posts: 7

Hi

We have a requirement to read messages from queues with Data conversion using Java.

Initially we used the MQGMO_CONVERT option in the getmessageoptions. However we noticed that it gave errors while reading large messages. On examining the docs, we saw the following

***

MQC.MQGMO_CONVERT
Request the application data to be converted, to conform to the characterSet and encoding attributes of the MQMessage, before the data is copied into the message buffer. Because data conversion is also applied as the data is retrieved from the message buffer, applications do not usually set this option.
Using this option can cause problems when converting from single byte character sets to double byte character sets. Instead, do the conversion using the readString, readLine, and writeString methods after the message has been delivered.

****

So then we removed the CONVERT option in GMO and used the readString method to read the messages. However the readString takes a parameter length which has to be the number of characters. But MQ has no method to give you the number of characters in the message. All methods only return the number of bytes.

This lead to IOException in Java (ArrayOutOfBoundException, EOFException...).

Is there any simpler way to do that and ensure that we retreive the right data ?

Note - The application is Unix based with MQ 5.3 CSD04, JDK 1.3.1_04.

Regards
Sachin
Back to top
View user's profile Send private message
vennela
PostPosted: Thu Oct 28, 2004 7:53 am    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

Quote:

getMessageLength
public int getMessageLength


From the manual

That will give you the message lenght.

Sample code snippet
Code:



queue.get(inMsg, gmo);

int msgLength = inMsg.getMessageLength() ;

String msgTxt = inMsg.readString(msgLength);
Back to top
View user's profile Send private message Send e-mail Visit poster's website
sachin_gk
PostPosted: Thu Oct 28, 2004 8:24 am    Post subject: Reply with quote

Newbie

Joined: 16 May 2001
Posts: 7

But this too returns the number of bytes in the message

****
getMessageLength
public int getMessageLength

Throws IOException.

The number of bytes of message data in this MQMessage object.
****

The readString requires the number of characters in the message !!! Strange that there is no method for that
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu Oct 28, 2004 8:26 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

If you want to read the entire message, use readFully.

Or try setting the length to be read to 104857600.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
sachin_gk
PostPosted: Thu Oct 28, 2004 8:32 am    Post subject: Reply with quote

Newbie

Joined: 16 May 2001
Posts: 7

We also tried the readFully method.

To give further details, we used the following

Read message without CONVERT

Then, used the following to convert

byte[] tmpStr=new byte[mqMsg.getDataLength()];
mqMsg.readFully(tmpStr); // Extract msg data from MQMsg
msg = new String(tmpStr, "UTF-8");

This should have converted the message to UTF -8. But in case of special characters in the message, the message gets truncated during this step. So we end up losing most of the message and it fails in the other parts of the application for parsing.
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu Oct 28, 2004 9:02 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Why do you expect to be able to translate nonprintable special characters into useable string data?

If it's got "special characters" in it, that cause the message to be "truncated", then you need to treat it as bytes and work with it that way.

Once you have identified valid sections that do not have nonprintable special characters (particularly ones with hex value 0) then you can cast/convert those sections.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
sachin_gk
PostPosted: Thu Oct 28, 2004 10:00 am    Post subject: Reply with quote

Newbie

Joined: 16 May 2001
Posts: 7

When i saud, i meant characters which are not english language. Sorry if i was vague about it.

For eg - in the name JOSE the written as JOSé . In this case it cannot handle é.
Back to top
View user's profile Send private message
sachin_gk
PostPosted: Thu Oct 28, 2004 10:03 am    Post subject: Reply with quote

Newbie

Joined: 16 May 2001
Posts: 7

Apologies for the last post. It got submitted inadvertently

When i said special characters, i meant characters which are not english language. Sorry if i was vague about it.

For eg - in the name JOSE the written as JOSé . In this case it cannot handle é.
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 » Problem reading messages from queue using readString/CONVERT
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.