Author |
Message
|
pjramana |
Posted: Mon Mar 22, 2004 12:29 pm Post subject: Question about MQMessage.readString() |
|
|
Novice
Joined: 08 Mar 2004 Posts: 14
|
I am trying to print the message that i set in MQMessage object. And i am getting java.io.EOFException.
The code snipped looks like this.
String message = "SOME String that is 700+ chars in length";
sentMessage.writeString( message );
sentMessage.expiry = this.msgExpiryInterval;
sentMessage.replyToQueueName = this.replyToQueue;
.sentMessage.messageType = MQC.MQMT_REQUEST;
MQPutMessageOptions pmo = new MQPutMessageOptions();
pmo.options = MQC.MQPMO_NEW_CORREL_ID ;
System.out.println("Writing Message to Queue:"+ this.sentMessage.getMessageLength() +" ["+message.length());
[color=red]System.out.println("Writing Message to Queue:"+ this.sentMessage.readString(this.sentMessage.getMessageLength()));
[/color]
------------------------------------------------------------------------------
Exception details.
java.io.EOFException
at com.ibm.mq.MQMessage.readConvertedString(MQMessage.java:1943)
at com.ibm.mq.MQMessage.readString(MQMessage.java:960)
------------------------------------------------------------------------
Is there anything special i need to do to read the message from MQMessage. I am using "i18n.jar" in classpath.
Thanks,
Janaki. |
|
Back to top |
|
 |
pjramana |
Posted: Mon Mar 22, 2004 12:31 pm Post subject: |
|
|
Novice
Joined: 08 Mar 2004 Posts: 14
|
This is the line that is giving the problem.
System.out.println("Writing Message to Queue:"+ this.sentMessage.readString(this.sentMessage.getMessageLength())); //Last line in the code snippet. |
|
Back to top |
|
 |
vennela |
Posted: Mon Mar 22, 2004 12:38 pm Post subject: |
|
|
 Jedi Knight
Joined: 11 Aug 2002 Posts: 4055 Location: Hyderabad, India
|
Try something like this
Code: |
getOptions.options = MQC.MQGMO_NO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING + MQC.MQGMO_CONVERT;
_inQ.get(getMsg, getOptions);
byte[] b = new byte[getMsg.getMessageLength()];
getMsg.readFully(b);
replyMsg = new String(b); |
I copied the code from some other post. You may try searching the forum for readFully |
|
Back to top |
|
 |
clindsey |
Posted: Mon Mar 22, 2004 12:43 pm Post subject: |
|
|
Knight
Joined: 12 Jul 2002 Posts: 586 Location: Dallas, Tx
|
Try this.sentMessage.seek(0) to return back to the start of the stream before you do the readString.
Charlie |
|
Back to top |
|
 |
pjramana |
Posted: Mon Mar 22, 2004 12:57 pm Post subject: |
|
|
Novice
Joined: 08 Mar 2004 Posts: 14
|
this.sentMessage.seek(0) worked perfect.
was i getting that EOFException because of the message read pointer pointing at the end of the message?
I am curious to know the way that MQMessage works. If someone can post that info, that would be great.
Thanks charlie.
Janaki. |
|
Back to top |
|
 |
clindsey |
Posted: Mon Mar 22, 2004 6:01 pm Post subject: |
|
|
Knight
Joined: 12 Jul 2002 Posts: 586 Location: Dallas, Tx
|
Quote: |
was i getting that EOFException because of the message read pointer pointing at the end of the message
|
yes, exactly
Quote: |
I am curious to know the way that MQMessage works. If someone can post that info, that would be great
|
Janaki, I would say there are 2 pieces; one is the attributes of the message, like priority, expiry, format, etc. The second is the message buffer which is a java byte stream. The MQMessage class implements DataInput and DataOutput which includes many methods like readInt, writeLong, readFully, etc..... and throws all the exceptions of these implementations such as IOException and EOFException.
If you have already looked at the MQMessage documentation, go to the WebSphere MQ Using Java manual and you can see all the attributes and methods.
Charlie |
|
Back to top |
|
 |
|