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.
import com.ibm.mq.MQMessage; import com.ibm.mq.headers.MQHeader; import com.ibm.mq.headers.MQHeaderIterator; ... 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); }Parent topic: Handling IBM MQ message headers with IBM MQ classes for Java