IBM® WebSphere® Enterprise Service Bus (WebSphere ESB) exposes MQ headers in a mediation component as part of the Service Message Object (SMO) structure. Therefore, MQ headers can be manipulated, added, and removed using the transformation capabilities of the Websphere ESB mediation component. This article shows you how the MQ headers are exposed in the SMO, and how you can manipulate the MQ headers that appear in an outbound MQ message sent from an MQ import, including controlling the properties of the MQMD and adding an MQRFH2 header.
Products used in this article:
- WebSphere Integration Developer V6.1
- WebSphere ESB V6.1 Integrated Test Environment (included with WebSphere Integration Developer)
- WebSphere MQ V6.0.2.2
Overview of the MQHeader structure in the Service Message Object
It is important to understand how the MQ headers are exposed in the Service Message Object (SMO) and how this structure differs from the way the headers are structured on the wire by Websphere MQ.
The key difference is that in the SMO, the chain of headers is unraveled and the control information (encoding, CCSID, and format) describing each header is placed within that header's structure in the SMO. On the wire, by contrast, each header carries the control information of the next header or payload in the sequence. Therefore headers in the SMO can be manipulated more easily because they can be added and removed from the sequence without the need to modify control information in other headers. The control information associated with the payload of the MQ message is kept in the control structure at the top level of the MQHeader structure in the SMO.
Figure 1. Mapping of MQ headers to the System Message Object

Although all fields in the MQMD, RFH2, and RFH headers are exposed in the SMO with the exception of StrucID, Version, and StrucLength, not all fields will be propagated into the outbound MQ Message as they are overridden by system values.
Manipulating MQMD, MQControl, and MQRFH2 using an XSL transformation
The MQ headers exposed in the SMO can be manipulated by a number of the transformation primitives in a mediation module. This section will guide you through manipulating the MQMD, MQRFH2, and control information of the MQ message payload using the XSL transformation primitive.
In this example, the JMSTextBody business object and the MQ unstructured text data binding are being used, so the message payload will be treated a a single block of unstructured text. The example will focus on manipulating the headers and not the body.
First, create a library and mediation module that will contain the XSL transformation:
- Create a new Library called
MQHeaderExampleLibrary. - Open the dependencies on the library, and under Predefined Resources, tick the Schema for simple JMS Data Bindings and click Save. The JMS body types are now available.
- In the library, create a new interface called
MQHeaderExampleService. - Create a one-way operation named
writeMQNativeMessage. - Change the type of
input1to JMSTextBody and click Save to save the interface. - Create a new mediation module called
MQHeaderExample1. Ensure that Create mediation component is ticked and click Next. - Tick the MQHeaderExampleLibrary and click Finish.
- Add an import to the assembly diagram.
- Wire the mediation component to the import, and when asked to add a reference, select MQHeaderExampleService.
- Right-click on Import1 and select Generate Binding: Messaging Binding: MQ Binding.
- Specify the queue manager name, send destination, host name, server channel, and port of your WebSphere MQ installation.
- Under Data Configuration, click Browse.
- Select Show predefined data bindings.
- Select MQ unstructured text message and click OK, then click OK again.
- Right-click on the mediation component, select Add: Interface, select the MQHeaderExampleService, and click OK.
Your assembly should now look like this:
Figure 2. MQHeaderExample1 assembly

Next, create the mediation flow and add an XSL transformation primitive to do the MQ headers mapping:
- Double-click on the mediation component MQHeaderExample1 to generate an implementation.
- In the mediation flow editor, wire writeMQNativeMessage to writeMQNativeMessage to create a flow.
- In the Palette, select Transformation: XSL Transformation.
- Add the XSL transformation primitive to the canvas.
- Wire the input node to the input terminal of the XSL transformation.
- Wire the output terminal of the XSL transformation to the callout node.
Your mediation flow should now look like this:
Figure 3. MQHeaderExample1 mediation flow

Mapping MQ header fields in the XSL transformation
- Double-click the XSLTransformation1 primitive to open the New XML Mapping wizard.
- Click Next to accept the default mapping name and namespace.
- Select Message Root and set it to /headers from the drop down list.
- Click Finish to accept the default input and output message types.
The mapping editor will now open. Because a root of /headers was selected, only the header part of the SMO will be shown. On the left side of the editor are the input fields representing all the possible header structures that may be found in the SMO entering the XSL transformation primitive. Depending on the origin of the SMO message at this point, these headers may not all be present and may not contain values. On the right side of the editor are the output fields representing all the possible headers structures that can be set in the SMO by the XSL transformation.
- Right-click on the input SMOHeader, select Create Connection, and drag the wire to the output SMOHeader.
- Right-click on the output MQHeader, and select Create Transform.
Your mapping should now look like this:
Figure 4. XSLT Mapping /headers

- Double-click on the Inline Map box to open the MQHeader map.
- Right-click on the output md, and select Create Transform to create an Inline Map.
- Right-click on the Inline Map for header, and select Show in Properties.
- In the Cardinality section, set the Output array indices of header to
0.
Setting the cardinality of the header map to 0 means that this map will act on the first MQ header in the output array. You can create further transforms
wired to header, and for each one set the cardinality property to act on a different instance. In this way you can build up a sequence of different MQ headers in the output message.
- Double-click on the Inline Map box for md to open the MQMD map.
- Right-click on the output Expiry, and select Create Transform to create an Assign map. Set the value in the properties panel to
600(60 seconds). - Repeat the previous step, creating assignments for the following additional properties and values:
- Priority:
7 - Persistence:
0(Non-Persistent) - CorrelId:
4D5920434944(ASCII for "MY CID").
Your MQMD mapping should now look like this:
Figure 5. Mapping of MQMD

- Right-click anywhere in the Mapping Editor and select Up a level to return to the higher level mapping.
- Repeat the process of building an inline map for the control structure, setting assignments for the following properties:
- Encoding:
0 - CodedCharSetId:
819 - Format:
MQSTR - Repeat the process of building an inline map for the header structure, setting assignments for the following properties:
- Encoding:
0 - CodedCharSetId:
819 - Whilst still in the header map, create an Inline Map for rfh2.
- Inside the rfh2 map, create an Inline Map for folder with a Cardinality of
0. - In the folder map, set the Name property to
ExampleGroup, and create an Inline Map for property with a Cardinality of0. - Finally, in the property map, set assignments for the following properties:
- Name:
ExampleProperty - Type:
String - Value:
testValue - Save all changes.
Figure 6 shows the process of building up the multilevel mapping of the RFH2 header:
Figure 6. Mapping the RFH2 header

The mapping and the mediation module are now complete.
You can use the universal test client to test the module:
- Right-click on the MQHeaderExample1 mediation component and select Test component.
- In the Component Test Events view, enter any value for the value field of input1.
- Click on the Continue(run) button to start the test.
- In the Deployment Location window, select WebSphere ESB Server and click Finish.
The server will start and the application will be deployed and invoked. Once the component test is complete, you will see the invoke returned, as shown below:
Figure 7. Invoke Returned

- Using WebSphere MQ Explorer, right-click on the send queue and select Browse Messages.
- Double-click on the message and you will see the properties that were set in the mediation component:
Figure 8. MQMessage

Congratulations, you have successfully created a mediation module that adds a MQHeader to a message.
| Description | Name | Size | Download method |
|---|---|---|---|
| Project Interchange containing MQHeaderExample1PI | MQHeaderExample1PI.zip | 29KB | HTTP |
Information about download methods
- Getting started with WebSphere Enterprise Service Bus and WebSphere Integration Developer
This article introduces developers to the IBM WebSphere Enterprise Service Bus server and its accompanying tooling, WebSphere Integration Developer. - Developing custom mediations for WebSphere Enterprise Service Bus
This article introduces the use of custom mediations using the WebSphere Integration Developer V6 environment for WebSphere Enterprise Service Bus V6. - Invoke Web Services with WebSphere MQ and WebSphere ESB
This tutorial introduces the WebSphere ESB MQ bindings and uses a custom body data binding to read and write MQ messages. - Invoking a Web Service using a JMS client
This tutorial introduces the WebSphere ESB JMS bindings and shows how a JMS message can be used to invoke a Web Service. - WebSphere ESB developer resources page
Technical resources to help you use WebSphere ESB as a flexible connectivity infrastructure for integrating applications and services to support an SOA. - WebSphere ESB product page
Product descriptions, product news, training information, support information, and more. - WebSphere ESB information center
A single Web portal to all WebSphere ESB documentation, with conceptual, task, and reference information on installing, configuring, and using WebSphere ESB. - WebSphere ESB documentation library
WebSphere ESB product manuals. - WebSphere ESB FAQs
Basic questions and answers about the new WebSphere ESB product and its relationship to other WebSphere products. - WebSphere ESB support
A searchable database of support problems and their solutions, plus downloads, fixes, problem tracking, and more. - Redbook: Patterns: SOA Design Using WebSphere Message Broker and WebSphere ESB
Patterns for e-business are a group of proven, reusable assets that can be used to increase the speed of developing and deploying e-business applications. This Redbook shows you how to use WebSphere ESB together with WebSphere Message Broker to implement an ESB within an SOA. Includes scenario to demonstrate design, development, and deployment. - WebSphere Integration Developer developer resources page
Technical resources to help you use the WebSphere Integration Developer IDE to render your existing IT assets as service components, encouraging reuse and efficiency as you build SOA-based integration solutions across WebSphere Process Server, WebSphere ESB, and WebSphere Adapters. - WebSphere Integration Developer product page
Product descriptions, product news, training information, support information, and more. - WebSphere Integration Developer information center
A single Web portal to all WebSphere Integration Developer documentation, with conceptual, task, and reference information on installing, configuring, and using your WebSphere Integration Developer environment. - WebSphere Integration Developer information roadmap
Roadmap of articles and resources to help you with installation, migration, administration, development, troubleshooting, and understanding the underlying technology. - WebSphere Integration Developer documentation library
WebSphere Integration Developer product manuals. - WebSphere Integration Developer support
A searchable database of support problems and their solutions, plus downloads, fixes, problem tracking, and more. - WebSphere MQ developer resources page
Technical resources to help you design, develop, and deploy messaging middleware with WebSphere MQ to integrate applications, Web services, and transactions on almost any platform. - WebSphere MQ product page
Product descriptions, product news, training information, support information, and more. - WebSphere MQ V7 trial download
A no-charge trial download of WebSphere MQ V6. Includes limited online support for Windows® and Linux® installations at no charge during the trial period. - WebSphere MQ V6 information center
A single Web portal to all WebSphere MQ V6 documentation, with conceptual, task, and reference information on installing, configuring, and using your WebSphere MQ environment. - WebSphere MQ documentation library
WebSphere MQ product manuals. - WebSphere MQ support page
A searchable database of support problems and their solutions, plus downloads, fixes, problem tracking, and more. - WebSphere MQ public newsgroup
A non-IBM forum where you can get answers to your WebSphere MQ technical questions and share your WebSphere MQ knowledge with other users. - WebSphere MQ SupportPacs
Downloadable code, documentation, and performance reports for the WebSphere MQ family of products. - WebSphere SOA solutions developer resources page
Get technical resources for WebSphere SOA solutions. - developerWorks SOA and Web services zone
Technical resources for evaluating, planning, designing, and implementing solutions that involve SOA and Web services. - developerWorks WebSphere Business Integration zone
For developers, access to WebSphere Business Integration how-to articles, downloads, tutorials, education, product info, and more. - WebSphere Business Integration products page
For both business and technical users, a handy overview of all WebSphere Business Integration products - WebSphere forums
Product-specific forums where you can get answers to your technical questions and share your expertise with other WebSphere users. - Most popular WebSphere trial downloads
No-charge trial downloads for key WebSphere products. - Trial downloads for IBM software products
No-charge trial downloads for selected IBM® DB2®, Lotus®, Rational®, Tivoli®, and WebSphere® products. - Technical books from IBM Press
Convenient online ordering through Barnes & Noble. - developerWorks technical events and Webcasts
Free technical sessions by IBM experts that can accelerate your learning curve and help you succeed in your most difficult software projects. Sessions range from one-hour Webcasts to half-day and full-day live sessions in cities worldwide.

Philip Norton is a software engineer at IBM Hursley Lab. He works on the WebSphere ESB Development team. His expertise includes Java and JMS for Websphere MQ. He is a certified Java Programmer and he has a degree in Computer Science from Canterbury University.

Alex Wood works at IBM Hursley Lab in England as a software developer for the IBM WebSphere Business Integration suite of products. He has extensive experience in development on many of the WebSphere products, including WebSphere MQ, WebSphere Message Broker, WebSphere Enterprise Service Bus, and WebSphere Process Server. He received a BSc in Physics with Astrophysics from Birmingham University in the UK in 1998.
Comments (Undergoing maintenance)





