If the message is written to MQ through Java, and then read the message through Java, using the Mqmessage Read Message method readUTF () to read, it will not error, can read it normally. If you insert a test message in MQ Explorer or through a remote team to the current MQ server through a different MQ server, it is wrong to read through Java, I suspect there are two:
1. What is the encoding of messages placed through the MQ Explorer? Do I need to specify the encoding of the read message when I read the message? I entered the code in Java 1381, and read it is also 1381
2, I now Java this side of the MQ Lib is removed from the WEBSPHERE6, because the MQ7 in the jar pack always reported some class does not exist, now the MQ service is V7, do not know whether it is related.
Personal feelings The first reason is the most likely, but do not know what the default MQ font is?
The command display qmgr can see that the default character set for the current MQ is 1381, and other places that the default character set is 1381 when MQ is installed on Windows, but when I read through the Java program, the CCSID is set to 1381. Also read the following error is always reported:
Java.io.EOFException
At java.io.DataInputStream.readFully (Unknown Source)
At Java.io.DataInputStream.readUTF (Unknown Source)
At Java.io.DataInputStream.readUTF (Unknown Source)
At Com.ibm.mq.MQMessage.readUTF (mqmessage.java:1229)
At Test. Messagebymq.getmessage (messagebymq.java:123)
At Test. Messagebymq.main (messagebymq.java:146)
I put the message through Java to set the CCSID is also 1381 but can read it correctly, but here do not understand why not read it,
Is this the third reason mentioned above, my jar package is V6, MQ is V7?
Basic solution:
The original method of reading the message is: readUTF ()
However, this approach does not give an error when other applications use writeUTF to write messages, which is the current Java program I mentioned above can read the messages written in the program.
However, the test message put in by MQ Explorer is not in the format of UTF, so the error is that the format of reading the message from MQ must be compatible with the format of the message, otherwise the message will be read.
Later try to use the ReadLine way to read, can read it normally, but if the writing is XML such a message, the use of ReadLine will not, after trying to readstringofcharlength method, The message written by the client application through the Writebytes method can be read normally, and the test packets placed through the MQ client can be read normally.
The problem took me all day and finally I could put it off for the time being.
Read the following code:
...
Mqmessage retrieve = new Mqmessage ();
String message=retrieve.readstringofcharlength (32000). Trim ();
...
Error and resolution when reading a message from MQ via Java