Author |
Message
|
Takidoso |
Posted: Thu Mar 08, 2007 4:47 am Post subject: 2 bytes more send as expected [URGENT HELP NEEDED] |
|
|
Novice
Joined: 08 Mar 2007 Posts: 19 Location: Germany
|
Hello
I am a newbie to MQ-Series and hope this forum is the right address for my problem.
I have a programm that is supposed to write MQ-messages that look very much like xml data. The funny thing is that 2 bytes more then expected arrive to the Host the queue addresses to.
it lookes then like this:
00000000: 0C8D 3031 524F 5554 2020 2020 424E 4B46 '..01ROUT BNKF'
but the 2 bytes 0C8D are not expected and not wanted, since I dont write them conciously and the partner on the other side seem to have trouble with them.
I have also a little programm to get a mesage of teh very same queue that gets the message as I expect without those 2 bytes.
the code that puts the message looks like that
Code: |
public void put(String xml) throws IOException
{
putCounter++;
mqLogger.fine(xml);
mqLogger.fine(putCounter+". msg-length="+xml.length());
MQPutMessageOptions pmo = new MQPutMessageOptions();
//pmo.options = MQC.MQPMO_NONE;
MQMessage mBuf = new MQMessage();
mBuf.clearMessage();
mBuf.correlationId = MQC.MQCI_NONE; // this acts as filter when you browse the queue!
mBuf.messageId = MQC.MQMI_NONE; // if MQMI not set, so everyone can
mBuf.format = MQC.MQFMT_STRING;
// use the queue
mBuf.writeUTF(xml);
mqLogger.log(Level.FINE, "put message to request queue");
try
{
requestQueue.put(mBuf, pmo);
}
catch (MQException mqEx)
{
mqLogger.log(Level.SEVERE,
"Error during putting the message into the queue " + requestQueueName + " \n" + printMQEnvironment(), mqEx);
throw new IOException(mqEx.toString());
}
}
|
the code retaining the message looks like that:
Code: |
public String get() throws IOException
{
MQGetMessageOptions gmo = new MQGetMessageOptions();
// gmo.options = MQC.MQGMO_NONE;
MQMessage mBuf = new MQMessage();
mBuf.clearMessage();
mBuf.correlationId = MQC.MQCI_NONE; // this acts as filter when you
mBuf.messageId = MQC.MQMI_NONE; // if MQMI not set, so everyone can
try
{
replyQueue.get(mBuf, gmo);
mqLogger.fine(mBuf.toString());
}
catch (MQException mqEx)
{
if (mqEx.reasonCode != MQ_REASON_CODE_NO_MESSAGE_AVAILABLE)
{
mqLogger.log(Level.SEVERE, "Error during getting the message from the queue " + replyQueueName + " \n"
+ printMQEnvironment(), mqEx);
throw new IOException(mqEx.toString());
}
else
{
return null;
}
}
return mBuf.readUTF();
}
|
Well I have the suspect that the writeUTF(String) method writes those bytes and the reatUTF() might cut out those 2 bytes in start of the message content again.
Is my suspect right? but how should it be coded instead to ommit those 2 bytes? Or is there some configuration to be done to solve my problem?
thanks in advance
Takidoso |
|
Back to top |
|
 |
Vitor |
Posted: Thu Mar 08, 2007 4:53 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
I suspect the 2 bytes in question are the length field for the Unicode string. You should always use the writeUTF/readUTF as a pair. If your partner is using read rather than readUTF he'll pick them up in the way you describe.
You should write the message using the method that matches how he's reading it. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Takidoso |
Posted: Thu Mar 08, 2007 5:56 am Post subject: |
|
|
Novice
Joined: 08 Mar 2007 Posts: 19 Location: Germany
|
Hi Vitor,
yes,this was also my suspect, about the 2bytes.
I try it now using the writeChars(String) method
and the readLine() method. May be I am lucky and it works.
thanks for your suggestion
Takidoso |
|
Back to top |
|
 |
Takidoso |
Posted: Thu Mar 08, 2007 6:13 am Post subject: |
|
|
Novice
Joined: 08 Mar 2007 Posts: 19 Location: Germany
|
well that does not work either
the 2 bytes that where to much are gone now, but on the host the string is writen now in 2 bytes each character.
Can anybody tell me what write-method and read method I am suppossed to use, when the string are just to be in singel characters without any uniccode 2byte-header?
Is terhe a possibility to configer the MQ-Message so that it is working right? may be in assigning an 8-byte uniccode set?
Thanks a lot in advance
Takidoso |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Mar 08, 2007 6:20 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Don't use readUTF and writeUTF. Generally ever.
Just readString and writeString. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Takidoso |
Posted: Thu Mar 08, 2007 7:46 am Post subject: |
|
|
Novice
Joined: 08 Mar 2007 Posts: 19 Location: Germany
|
Hi jefflowrey,
thanks to your hint. I am also now trying that but I use still readLine, since my developing envrionment tells me that readString is depreicated.
I hope on the host ist still someone there who can tell me what the results are.
Takidoso |
|
Back to top |
|
 |
zpat |
Posted: Thu Mar 08, 2007 7:47 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
Byte Order Mark is the 2 bytes added at the start.
Using WriteString instead. |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Mar 08, 2007 4:14 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Takidoso wrote: |
well that does not work either
the 2 bytes that where to much are gone now, but on the host the string is writen now in 2 bytes each character.
Can anybody tell me what write-method and read method I am suppossed to use, when the string are just to be in singel characters without any uniccode 2byte-header?
Is terhe a possibility to configer the MQ-Message so that it is working right? may be in assigning an 8-byte uniccode set?
Thanks a lot in advance
Takidoso |
Well for the message to be read correctly make sure you are setting the format to MQFMT_STRING.
Now on the receiver side you will need the gmo option CONVERT.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|