Printing all the headers in a message using IBM® MQ classes for Java

In this example, an instance of MQHeaderIterator parses the headers in an MQMessage that has been received from a queue. The MQHeader objects returned from the nextHeader() method display their structure and contents when their toString method is invoked.

MQMessage message = ... // Message received from a queue.
MQHeaderIterator it = new MQHeaderIterator (message);

while (it.hasNext ())
	MQHeader header = it.nextHeader ();
	System.out.println ("Header type " + header.type () + ": " + header);