Author |
Message
|
r2504 |
Posted: Wed May 25, 2005 12:12 am Post subject: UTFDataFormatException on get |
|
|
Novice
Joined: 05 Mar 2004 Posts: 22
|
Hi,
I have a message in a queue which is tagged as MQSTR, CCSID 1208 (UTF8) encoding 273. The test message contains "Héllo world." and shows correctly when looking at it via Websphere Explorer.
Whenever I read this via a Java program, I however get a java.io.UTFDataFormatException on the message.readUTF() method. The get method itself worked fine and confirms the tagging as described above.
Looking at MQmessage.databuffer... the e-accent shows as -61 -87 (while in correct UTF-8 hex this is C3 A9 as seen in Websphere MQ Explorer).
What am I doing wrong... why can't I read UTF-8 messages from a queue. |
|
Back to top |
|
 |
griffel |
Posted: Wed May 25, 2005 12:42 am Post subject: |
|
|
Novice
Joined: 22 Mar 2005 Posts: 23
|
What do you mean by "read this via a Java program"?
Do you use JMS stuff? If so, beware of using TextMessage
which do UTF8-conversion on their own. Try using a
BytesMessage. Just an idea. |
|
Back to top |
|
 |
r2504 |
Posted: Wed May 25, 2005 12:47 am Post subject: |
|
|
Novice
Joined: 05 Mar 2004 Posts: 22
|
No JMS... just plain MQ base Java programs.
Following is the piece of code...
Code: |
MQMessage message = new MQMessage();
message.characterSet = 1208;
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_WAIT;
gmo.waitInterval = MQC.MQWI_UNLIMITED;
queue.get(message, gmo);
Message = message.readUTF(); |
Since the message is tagged as MQSTR... it should do the conversion... but even then, Java is UTF-8, so I don't see the problem at all. |
|
Back to top |
|
 |
r2504 |
Posted: Wed May 25, 2005 3:04 am Post subject: |
|
|
Novice
Joined: 05 Mar 2004 Posts: 22
|
I solved this now by forcing a conversion to 1252 (Windows) ...
Code: |
MQMessage message = new MQMessage();
message.characterSet = 1252;
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = gmo.options + MQC.MQGMO_WAIT + MQC.MQGMO_CONVERT;
gmo.waitInterval = MQC.MQWI_UNLIMITED;
queue.get(message, gmo);
Message = message.readString(message.getMessageLength()); |
... but still don't understand why this is necessary. It also no longer allows me to use readUTF() as it still crashes in that case.
Is Windows XP having a problem with UTF-8 ? |
|
Back to top |
|
 |
bower5932 |
Posted: Wed May 25, 2005 6:08 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
I'd like to see the code that you use to actually put the message onto the queue and I'd also like to see the amqsbcg output of the message. The readUTF should be reading a string that is prefixed by a two byte length (which I think means the message isn't really in MQSTR format). |
|
Back to top |
|
 |
r2504 |
Posted: Wed May 25, 2005 7:05 am Post subject: |
|
|
Novice
Joined: 05 Mar 2004 Posts: 22
|
The code that puts the message on the queue is RPG code (runs on iSeries). Basically it sets MDCSI to 1208 and MDFMT to FMSTR and the buffer to the actual UTF-8 data (no prefix of length). |
|
Back to top |
|
 |
bower5932 |
Posted: Wed May 25, 2005 8:39 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
r2504 wrote: |
the buffer to the actual UTF-8 data (no prefix of length). |
If you aren't specifying the length, then you should avoid using the readUTF method since it is expecting the data in the format of length|data. This is probably causing your DataFormatException. |
|
Back to top |
|
 |
r2504 |
Posted: Wed May 25, 2005 9:53 am Post subject: |
|
|
Novice
Joined: 05 Mar 2004 Posts: 22
|
bower5932 wrote: |
If you aren't specifying the length, then you should avoid using the readUTF method since it is expecting the data in the format of length|data. This is probably causing your DataFormatException. |
I'll try to use the writeUTF() to see what it actually does generate since I don't have that method in RPG on iSeries. Anyway, this still leaves me with the question why it also doesn't work with readString()... unless I force a conversion to CCSID 1252. |
|
Back to top |
|
 |
|