Analyzing an MQRFH2 header using IBM® MQ classes for Java

This example shows how to access a known field value in a named folder, using the MQRFH2 class.

The MQRFH2 class provides a number of ways to access not only the fields in the fixed part of the structure, but also the XML-encoded folder contents that are carried within the NameValueData field. This example shows how to access a known field value in a named folder - in this instance, the Rto field in the jms folder, which represents the reply queue name in an MQ JMS message.

MQRFH2 rfh = ...

String value = rfh.getStringFieldValue ("jms", "Rto");
To discover the contents of an MQRFH2 (as opposed to requesting specific fields directly), you can use the getFolders method to return a list of MQRFH2.Element, which represents the structure of a folder that could contain fields and other folders. Setting a field or folder to null removes it from the MQRFH2. When you manipulate the NameValueData folder contents in this way, the StrucLength field is automatically updated accordingly.