Handling IBM MQ message headers with IBM MQ classes for Java

Java classes are provided representing different types of message header. Two helper classes are also provided.

The MQHeader interface

Header objects are described by the MQHeader interface, which provides general-purpose methods for accessing header fields and for reading and writing message content. Each header type has its own class that implements the MQHeader interface and adds getter and setter methods for individual fields. For example, the MQRFH2 header type is represented by the MQRFH2 class; the MQDLH header type by the MQDLH class, and so on. The header classes perform any necessary data conversion automatically, and can read or write data in any specified numeric encoding or character set (CCSID).

Important: The MQRFH2 headers classes treat the message as a random access file, which means that the cursor must be positioned at the start of the message. Before using an internal message header class like MQRFH, MQRFH2, MQCIH, MQDEAD, MQIIH or MQXMIT, make sure that you update the message's cursor position to the correct location before passing the message to the class.

Helper classes

Two helper classes, MQHeaderIterator and MQHeaderList, assist with reading and decoding (parsing) the header content in messages:
  • The MQHeaderIterator class works like a java.util.Iterator. For as long as there are more headers in the message, the next() method returns true, and the nextHeader() or next() method returns the next header object.
  • The MQHeaderList works like a java.util.List. Like the MQHeaderIterator, it parses header content, but it also allows you to search for particular headers, add new headers, remove existing headers, update header fields and then write the header content back to a message. Alternatively, you can create an empty MQHeaderList, then populate it with header instances and write it to a message once or repeatedly.
The MQHeaderIterator and MQHeaderList classes use the information in the MQHeaderRegistry to know which IBM® MQ header classes are associated with particular message types and formats. The MQHeaderRegistry is configured with knowledge of all current IBM MQ formats and header types and their implementation classes, and you can also register your own header types.
Support is provided for the following commonly used Websphere MQ headers
  • MQRFH - Rules and formatting header
  • MQRFH2 - Like MQRFH, used to pass messages to and from a message broker belonging to IBM Integration Bus. Also used to contain message properties
  • MQCIH - CICS® Bridge
  • MQDLH - Dead letter header
  • MQIIH - IMS information header
  • MQRMH - reference message header
  • MQSAPH - SAP header
  • MQWIH - Work information header
  • MQXQH - Transmission Queue header
  • MQDH - Distribution header
  • MQEPH - Encapsulated PCF header
You can also define classes representing your own headers.

To use an MQHeaderIterator to get an RFH2 header, either set MQGMO_PROPERTIES_FORCE_MQRFH2 in the GetMessageOptions, or set the queue property PROPCTL to FORCE.