Author |
Message
|
Rohit_ |
Posted: Fri Nov 07, 2008 2:08 pm Post subject: payload from BytesMessage |
|
|
 Novice
Joined: 10 Jan 2008 Posts: 24
|
Hi Forum,
My application gets an message which is An instance of BytesMsssage.
How can I get the payload from this message ?
Code: |
if(msg instanceof BytesMessage){
BytesMessage bmsg = (BytesMessage)msg;
byte bytes[];
try
{
int len = (int) bmsg.getBodyLength();
bytes = new byte[(int) bmsg.getBodyLength()];
bmsg.readBytes(bytes);
payloadXML = new String(bytes);
}
|
Now I get the string but it also have header.I just need to get the XML(paylaod comes as XML)
And publishing message which contains XML, which is the beter way sending as TextMessage or BytesMessage ?
thanks in advance |
|
Back to top |
|
 |
atheek |
Posted: Fri Nov 07, 2008 2:52 pm Post subject: |
|
|
 Partisan
Joined: 01 Jun 2006 Posts: 327 Location: Sydney
|
What is the header you are getting? Can you post the xml with the header output by your program?
The best way to transfer xml messages should be as Text. One good reason is that character conversion can be done by MQ especially if messages are exchanged between different platforms eg, ebcidic to ascii and vice versa... |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Nov 07, 2008 10:43 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
atheek wrote: |
What is the header you are getting? Can you post the xml with the header output by your program?
The best way to transfer xml messages should be as Text. One good reason is that character conversion can be done by MQ especially if messages are exchanged between different platforms eg, ebcidic to ascii and vice versa... |
However we want to make sure that you are aware that due to soap multipart messages which can have binary attachments the default for SOAP over JMS is BytesMessage. The expectation is that the CCSID is set at 1208 and the xml part is UTF-8.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
mqjeff |
Posted: Sat Nov 08, 2008 11:44 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Does the "header" in the BytesMessage start with "MQHRF2"? |
|
Back to top |
|
 |
fjb_saper |
Posted: Sat Nov 08, 2008 7:13 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
mqjeff wrote: |
Does the "header" in the BytesMessage start with "MQHRF2"? |
Obviously in his code, he is dealing with JMS. You mean to say that the message would have 2 linked RFH headers on it?
It would rather expect a different one, like SAPH may be from MQ-Link for R3.... or a CICS or IMS header?  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Rohit_ |
Posted: Mon Nov 10, 2008 6:15 am Post subject: |
|
|
 Novice
Joined: 10 Jan 2008 Posts: 24
|
mqjeff wrote: |
Does the "header" in the BytesMessage start with "MQHRF2"? |
In header I get below properties :
^@RFH ^@^@^@^B^@^@^@?^@^@^A^Q^@^@^D?MQSTR ^@^@^@^@^@^@^D?^@^@^@ <mcd><Msd>jms
_text</Msd></mcd> |
|
Back to top |
|
 |
atheek |
Posted: Mon Nov 10, 2008 12:48 pm Post subject: |
|
|
 Partisan
Joined: 01 Jun 2006 Posts: 327 Location: Sydney
|
If the message had MQMD.Format = MQHRF2 and the format within the RFHeader is MQSTR, then the message will be cast to a JMS TextMessage. Looks like your jms application is receiving a message with the above conditions.So it will be if(msg instanceof TextMessage) part of the code that should get executed. And msg.getText() should get you the payloadXML.
Can you do a browse of the queue ( using amqsbcg) with messages pending in it and dump the output here.. |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Nov 10, 2008 2:34 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
I figure he might have chained RFH header or a malformed MQMD header with the RFH header...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Rohit_ |
Posted: Mon Nov 10, 2008 3:23 pm Post subject: |
|
|
 Novice
Joined: 10 Jan 2008 Posts: 24
|
atheek wrote: |
If the message had MQMD.Format = MQHRF2 and the format within the RFHeader is MQSTR, then the message will be cast to a JMS TextMessage. Looks like your jms application is receiving a message with the above conditions.So it will be if(msg instanceof TextMessage) part of the code that should get executed. And msg.getText() should get you the payloadXML.
Can you do a browse of the queue ( using amqsbcg) with messages pending in it and dump the output here.. |
I am getting data as bytes and am converting bytes to string .
I get this if I just print the msg :
Code: |
JMS Message class: jms_bytes
JMSType: null
JMSDeliveryMode: 2
JMSExpiration: 0
JMSPriority: 3
JMSMessageID: ID:464d42fe3fb918b83370fc4912fa2700095c48000000015a
JMSTimestamp: 1225980455610
JMSCorrelationID:null
JMSDestination: null
JMSReplyTo: null
JMSRedelivered: true
JMSXDeliveryCount:30
JMS_IBM_MsgType:8
JMS_IBM_Format:
JMS_IBM_Encoding:273
JMS_IBM_PutApplType:6
JMS_IBM_Character_Set:ISO8859_1
JMSXUserID:gms
JMS_IBM_PutTime:14073561
JMS_IBM_PutDate:20081106
|
|
|
Back to top |
|
 |
atheek |
Posted: Mon Nov 10, 2008 5:32 pm Post subject: |
|
|
 Partisan
Joined: 01 Jun 2006 Posts: 327 Location: Sydney
|
So your problem is a malformed MQMD header. Ask the sender appln to ensure they are properly formatting the message and the headers. If they are sending a message with RF headers, ask them to ensure that
they are setting MQMD.Format = MQHRF2
To double confirm do amqsbcg( this will be available in bin folder of <MQ Installation Home> directory)
type amqsbcg <queue name> <queue manager name> at a command prompt and dump the output |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Nov 10, 2008 5:43 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
fjb_saper wrote: |
I figure he might have chained RFH header or a malformed MQMD header with the RFH header...  |
No, you didn't. You figured he had a plaintext MQ message that he was trying to read as a JMS message....
 |
|
Back to top |
|
 |
manidreams |
Posted: Fri Apr 23, 2010 12:42 pm Post subject: |
|
|
Newbie
Joined: 12 Apr 2010 Posts: 6
|
Hi All,
I am also facing the same problem but not able to figure out the reason.I am using JMS method and posting a normal XML message.Please help in getting a normal XML message rather than a byte message. |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Apr 23, 2010 7:35 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
manidreams wrote: |
Hi All,
I am also facing the same problem but not able to figure out the reason.I am using JMS method and posting a normal XML message.Please help in getting a normal XML message rather than a byte message. |
Are you using JMS to base MQ? You may want to make sure you set the targetClient property of your JMS destination.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
manidreams |
Posted: Sat Apr 24, 2010 8:42 am Post subject: |
|
|
Newbie
Joined: 12 Apr 2010 Posts: 6
|
I am already setting the Target Client as MQ, earlier it was JMS but still getting the message in byte format. |
|
Back to top |
|
 |
fjb_saper |
Posted: Sat Apr 24, 2010 7:18 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
manidreams wrote: |
I am already setting the Target Client as MQ, earlier it was JMS but still getting the message in byte format. |
With Axis a JMS service call is a bytes message as it may be a MIME content.
Just retrieve the bytes with the accurate method and transform to text using the correct CCSID. This should give you a readable XML message.
You can also try parsing as a bitstream. Just make sure the CCSID corresponds to what the parser is given...
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|