Author |
Message
|
Mirage |
Posted: Thu Dec 09, 2004 7:41 am Post subject: Java Custom Node: getting MsgID from MbElement |
|
|
 Apprentice
Joined: 30 Nov 2004 Posts: 44 Location: IL
|
Hi,
I'm working on reading the MsgID from the input message in my custom node. I've queried the input message and got MsgID as a MbElement object.
Code: |
MbElement msgIdElement = rootElement.getFirstElementByPath("/MQMD/MsgId"); |
I want to set this MsgId value into my MQ's MQMD java object for future reference and to compare the correlationId of another message.
Code: |
MQMD reqMQMD = new MQMD();
reqMQMD.messageId = [b]--------------[/b] |
Here is my problem, filling the dashes in the code. MQMD.messageId expects a byte array, where as MbElement.getValue() returns a Java Object.
How can I set the value of MsgId to MQMD's messageId ?
When I printout msgIdElement.getValue(), its printed in ASCII. Can I convert this object into a byte array and assign to MQMD.?
Thanks - RR. |
|
Back to top |
|
 |
JLRowe |
Posted: Thu Dec 09, 2004 7:49 am Post subject: |
|
|
 Yatiri
Joined: 25 May 2002 Posts: 664 Location: South East London
|
Cast to byte array:
Code: |
regMQMD.messageIf = (byte[])msgIdElement;
|
|
|
Back to top |
|
 |
Mirage |
Posted: Thu Dec 09, 2004 7:58 am Post subject: |
|
|
 Apprentice
Joined: 30 Nov 2004 Posts: 44 Location: IL
|
Thanks Timna.
I dont know why I could not think of such a simple cast. Sometimes it just doesnt work.  |
|
Back to top |
|
 |
Mirage |
Posted: Thu Dec 09, 2004 10:06 am Post subject: |
|
|
 Apprentice
Joined: 30 Nov 2004 Posts: 44 Location: IL
|
Hi ,
I changed the code to type cast to byte array and I'm storing the byte array in MQMD's messageId.
When I printout the values of these 2, there is a change in the value. I think the Message ID is getting changed when I type cast it. I'm not sure though.
Code: |
MbElement msgIdElement = rootElement.getFirstElementByPath("/MQMD/MsgId");
logger.println("MSG ID's Value "+msgIdElement.getValue());
byte msgIdArray [] = (byte [])msgIdElement.getValue();
logger.println("Byte Array msgIdArray's value"+msgIdArray);
MQMD reqMQMD = new MQMD();
reqMQMD.messageId = msgIdArray;
logger.println("Length of MQMD "+msgIdArray.length);
logger.println("Message ID from MQMD after converted "+reqMQMD.messageId); |
Here is the output for the print statements.
Quote: |
MSG ID's Value [B@f73672d
Byte Array msgIdArray's value[B@f62672d
Length of MQMD 24
Message ID from MQMD after converted [B@f62672d
|
Am I doing anything wrong in copying the values ? Please suggest.
Thanks - RR. |
|
Back to top |
|
 |
JLRowe |
Posted: Thu Dec 09, 2004 10:25 am Post subject: |
|
|
 Yatiri
Joined: 25 May 2002 Posts: 664 Location: South East London
|
The println's are giving you the address of the Object, not it's actual contents. String accepts a byte array as a constructor, and will convert the byte[] to a String.
Do this:
Code: |
System.out.println(new String(msgIdArray));
|
|
|
Back to top |
|
 |
Mirage |
Posted: Thu Dec 09, 2004 10:41 am Post subject: |
|
|
 Apprentice
Joined: 30 Nov 2004 Posts: 44 Location: IL
|
I changed it to
Code: |
new String(msgIdArray); |
and the print statement was
Quote: |
AMQ MSGBRK_QM ?¸A |
Which is somewhat similar to the view from RFHUtil but not same.
Instead of comparing with these special characters, is there a way to convert this 24 byte array to the hex format. That way I can easily compare them with RFHUtil.
Does MQMD.messageID also point to the same memory location ?. In the print statements both are looking same. |
|
Back to top |
|
 |
|