Author |
Message
|
sachin_gk |
Posted: Thu Oct 28, 2004 7:43 am Post subject: Problem reading messages from queue using readString/CONVERT |
|
|
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 |
|
 |
vennela |
Posted: Thu Oct 28, 2004 7:53 am Post subject: |
|
|
 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 |
|
 |
sachin_gk |
Posted: Thu Oct 28, 2004 8:24 am Post subject: |
|
|
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 |
|
 |
jefflowrey |
Posted: Thu Oct 28, 2004 8:26 am Post subject: |
|
|
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 |
|
 |
sachin_gk |
Posted: Thu Oct 28, 2004 8:32 am Post subject: |
|
|
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 |
|
 |
jefflowrey |
Posted: Thu Oct 28, 2004 9:02 am Post subject: |
|
|
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 |
|
 |
sachin_gk |
Posted: Thu Oct 28, 2004 10:00 am Post subject: |
|
|
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 |
|
 |
sachin_gk |
Posted: Thu Oct 28, 2004 10:03 am Post subject: |
|
|
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 |
|
 |
|