Author |
Message
|
Long John Silver |
Posted: Mon Jun 14, 2010 2:44 am Post subject: How to print out an entire JMS message |
|
|
Newbie
Joined: 12 May 2010 Posts: 9
|
Hi all,
Maybe a newbye question.
In my application, for debug purposes, I have something like this:
Code: |
logger.dedub(jmsMessage.toString()); |
Actually whatever is the message size I don't get a fully printout of the message but just the header and the beginning of the body followed by some dots:
Code: |
6e616c53797374656d3e5046453c2f4f726967696e616c53797374656d3e0a202020202020202020
... |
Is there some quick way to obtain the toString() of the full body?
Thank you in advamce |
|
Back to top |
|
 |
sridhsri |
Posted: Mon Jun 14, 2010 12:08 pm Post subject: |
|
|
Master
Joined: 19 Jun 2008 Posts: 297
|
First you must determine the type of JMS Message (Text, Byte, Object, Stream or Map). For each type the method is different. The easiest is with TextMessage.
Code: |
TextMessage txt_msg = (TextMessage)jmsMessage;
System.out.println(txt_msg.getText());
|
|
|
Back to top |
|
 |
calanais |
Posted: Tue Jun 15, 2010 12:53 am Post subject: |
|
|
Apprentice
Joined: 12 Mar 2010 Posts: 32
|
Hi - could you confirm the class of the message you've got back.
msg.getClass().toString()
All WMQ JMS Messages should output full details on their toString methods not just the value you've got.
Matthew |
|
Back to top |
|
 |
Long John Silver |
Posted: Tue Jun 15, 2010 1:04 am Post subject: |
|
|
Newbie
Joined: 12 May 2010 Posts: 9
|
Thank you all.
My messages are of type BytesMessage.
I confirm that with WMQ 7 when I log the message trough the toString() method I get the full header and only the partial body as here:
Code: |
JMSMessage class: jms_bytes
JMSType: null
JMSDeliveryMode: 2
JMSExpiration: 1276305569502
JMSPriority: 4
JMSMessageID: ID:414d51204644452e51554555454d414e106ed54b03542320
JMSTimestamp: 1276089569502
JMSCorrelationID:
JMSDestination: queue://XXX/XXX
JMSReplyTo: null
JMSRedelivered: false
JMSXAppID: WebSphere MQ Client for Java
JMSXDeliveryCount: 1
JMSXUserID: mqm
JMS_IBM_Character_Set: UTF-8
JMS_IBM_Encoding: 273
JMS_IBM_Format:
JMS_IBM_MsgType: 8
JMS_IBM_PutApplType: 28
JMS_IBM_PutDate: 20100609
JMS_IBM_PutTime: 13192950
MIME: text/xml
3c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d225554462d38223f3e0a3c
6e73303a7365727669636520786d6c6e733a6e73303d22687474703a2f2f7777772e706172696d75
7475656c2e66722f706d752d6d6c2f504d552d4d4c2f76302e31223e0a202020203c6e616d653e49
4e464f2d5041523c2f6e616d653e0a202020203c6e73313a6d6573736167652d50415220786d6c6e
733a6e73313d22706d753a686f727365726163696e673a6d73673a7061723a763130223e0a202020
20202020203c6865616465723e0a2020202020202020202020203c56657273696f6e3e313c2f5665
7273696f6e3e0a2020202020202020202020203c4d65737361676549643e32303130303630393135
313731383139313c2f4d65737361676549643e0a2020202020202020202020203c446174653e3230
31302d30362d30392b30323a30303c2f446174653e0a2020202020202020202020203c4f72696769
6e616c53797374656d3e5046453c2f4f726967696e616c53797374656d3e0a202020202020202020
... |
So now I replaced the toString with:
int size = message.getBodyLength();
byte[] rawContent = new byte[size];
message.readBytes(rawContent);
Then a custom method to print out the array formatted in 16 columns in hex format.
Bye |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Jun 15, 2010 2:46 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Your content info says somewhere mime/text/xml...
BytesMessage because you may have a multipart message with binary content. However you could also try and transform the bytes into text allowing for the correct CCSID... and print that...
Up to you on how you want to handle it...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Long John Silver |
Posted: Tue Jun 15, 2010 7:16 am Post subject: |
|
|
Newbie
Joined: 12 May 2010 Posts: 9
|
fjb_saper wrote: |
Your content info says somewhere mime/text/xml...
BytesMessage because you may have a multipart message with binary content. However you could also try and transform the bytes into text allowing for the correct CCSID... and print that...
Up to you on how you want to handle it...  |
I got the task accomplished However I still do not understand why IBM implemented a partial toString() output...
Last but not the least
Is there a quick way to dump only the full header portion?
Thank you in advance |
|
Back to top |
|
 |
calanais |
Posted: Tue Jun 15, 2010 7:18 am Post subject: |
|
|
Apprentice
Joined: 12 Mar 2010 Posts: 32
|
Could you clarify in what why the output is 'partial' as the output above is the full header, and the full payload of the message? |
|
Back to top |
|
 |
Long John Silver |
Posted: Tue Jun 15, 2010 7:31 am Post subject: |
|
|
Newbie
Joined: 12 May 2010 Posts: 9
|
calanais wrote: |
Could you clarify in what why the output is 'partial' as the output above is the full header, and the full payload of the message? |
Hi canalis,
I receive a ByteMessage
Iwas doing just:
logger.debug(message.toStrig());
As you see in my previous post I get the full header and just the first 400 bytes of the message body followed by three dots (...) Usually my messages are 2kb long.
Right now to obtain the full body dump I read the message and I print out the bytes...
I'm wondering if there is a way to obtain only the header dump.
Bye |
|
Back to top |
|
 |
calanais |
Posted: Wed Jun 16, 2010 7:09 am Post subject: |
|
|
Apprentice
Joined: 12 Mar 2010 Posts: 32
|
The toString() method on WMQ JMS Message is really intended for use as a diagnostic guide.
Hence there is a limit to the amount of data that is written out; the idea is to give a indication of what is the message rather than being used for data processing.
The question to ask is what aspects of the header are important to you - and what it will be processed for.
Keep in mind as well the order and the format of the fields may change in the output between versions so watch out for parsing this string.
Matthew |
|
Back to top |
|
 |
Long John Silver |
Posted: Wed Jun 16, 2010 7:23 am Post subject: |
|
|
Newbie
Joined: 12 May 2010 Posts: 9
|
calanais wrote: |
The question to ask is what aspects of the header are important to you - and what it will be processed for.
Keep in mind as well the order and the format of the fields may change in the output between versions so watch out for parsing this string.
|
Right now I keep logging the header just in case of some debug during application test so it's useful having a log file to check.
Would be nice having a toString() only of the header portion.
Thanks |
|
Back to top |
|
 |
|