Sei sulla pagina 1di 10

Introduction 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. Part 1 in this three-part article series 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 series:

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.

Tuesday, August 30, 2011 Page 1 of 10

L&T Infotech Proprietary

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.

Fields that are not propagated to the outbound MQ message

MQMD: o BackoutCount o AccountingToken o PutDate o PutTime o Offset o OriginalLength

Fields that can be propagated to the outbound MQ message

MQMD fields that can be propagated by setting custom property MDCTX=SET_ALL_CONTEXT on JNDI queue definition (from V7 and later): o UserIdentifier o AppIdentityData o PutApplType o PutApplName o ApplOriginData

Tuesday, August 30, 2011 Page 2 of 10

L&T Infotech Proprietary

MQMD fields that can be propagated by editing Message configuration properties on MQ Import: o MsgID - Request Message ID options must be set to copy from SCA message. o MsgType - Set message type to MQMT_DATAGRAM or MQMT_REQUEST for request-response operation must be unticked. o ReplyToQ - Override reply to queue of request message must be unticked. o ReplyToQMgr - Override reply to queue of request message must be unticked.

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 as a single block of unstructured text. The example will focus on manipulating the headers and not the body. Building the module First, create a library and mediation module that will contain the XSL transformation:
1. Create a new Library called MQHeaderExampleLibrary. 2. 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. 3. In the library, create a new interface called MQHeaderExampleService. 4. Create a one-way operation named writeMQNativeMessage. 5. Change the type of input1 to JMSTextBody and click Save to save the interface. 6. Create a new mediation module called MQHeaderExample1. Ensure that Create mediation component is ticked and click Next. 7. Tick the MQHeaderExampleLibrary and click Finish. 8. Add an import to the assembly diagram. 9. Wire the mediation component to the import, and when asked to add a reference, select MQHeaderExampleService. 10. Right-click Import1 and select Generate Binding: Messaging Binding: MQ Binding. 11. Specify the queue manager name, send destination, host name, server channel, and port of your WebSphere MQ installation. 12. Under Data Configuration, click Browse. 13. Select Show predefined data bindings. 14. Select MQ unstructured text message and click OK, then click OK again. 15. Right-click the mediation component, select Add: Interface, select the MQHeaderExampleService, and click OK.

Tuesday, August 30, 2011 Page 3 of 10

L&T Infotech Proprietary

Your assembly should now look like Figure 2. Figure 2. MQHeaderExample1 assembly

Building the mediation flow Next, create the mediation flow and add an XSL transformation primitive to do the MQ headers mapping:
16. Double-click the mediation component MQHeaderExample1 to generate an implementation. 17. In the mediation flow editor, wire writeMQNativeMessage to writeMQNativeMessage to

create a flow.
18. In the Palette, select Transformation: XSL Transformation.

19. Add the XSL transformation primitive to the canvas. 20. Wire the input node to the input terminal of the XSL transformation. 21. Wire the output terminal of the XSL transformation to the callout node. Your mediation flow should now look like Figure 3.

Tuesday, August 30, 2011 Page 4 of 10

L&T Infotech Proprietary

Figure 3. MQHeaderExample1 mediation flow

Mapping MQ header fields in the XSL transformation


22. Double-click the XSLTransformation1 primitive to open the New XML Mapping wizard. 23. Click Next to accept the default mapping name and namespace. 24. Select Message Root and set it to /headers from the drop down list. 25. 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.
26. Right-click the input SMOHeader, select Create Connection, and drag the wire to the output

SMOHeader. 27. Right-click the output MQHeader and select Create Transform. Your mapping should now look like Figure 4.

Tuesday, August 30, 2011 Page 5 of 10

L&T Infotech Proprietary

Figure 4. XSLT Mapping /headers

28. Double-click the Inline Map box to open the MQHeader map. 29. Right-click the output md and select Create Transform to create an Inline Map. 30. Right-click the Inline Map for header and select Show in Properties. 31. 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.
32. Double-click the Inline Map box for md to open the MQMD map. 33. Right-click the output Expiry and select Create Transform to create an Assign map. Set the

value in the properties panel to 600 (60 seconds). 34. Repeat the previous step, creating assignments for the following additional properties and values: o Priority: 7 o Persistence: 0 (Non-Persistent) o CorrelId: 4D5920434944 (ASCII for "MY CID"). Your MQMD mapping should now look like Figure 5.

Tuesday, August 30, 2011 Page 6 of 10

L&T Infotech Proprietary

Figure 5. Mapping of MQMD

35. Right-click anywhere in the Mapping Editor and select Up a level to return to the higher level

mapping.
36. Repeat the process of building an inline map for the control structure, setting assignments for

the following properties: o Encoding: 0 o CodedCharSetId: 819 o Format: MQSTR 37. Repeat the process of building an inline map for the header structure, setting assignments for the following properties: o Encoding: 0 o CodedCharSetId: 819 38. While still in the header map, create an Inline Map for rfh2. 39. Inside the rfh2 map, create an Inline Map for folder with a Cardinality of 0. 40. In the folder map, set the Name property to ExampleGroup and create an Inline Map for property with a Cardinality of 0. 41. Finally, in the property map, set assignments for the following properties: o Name: ExampleProperty o Type: String o Value: testValue 42. Save all changes. Figure 6 shows the process of building up the multilevel mapping of the RFH2 header.

Tuesday, August 30, 2011 Page 7 of 10

L&T Infotech Proprietary

Figure 6. Mapping the RFH2 header

The mapping and the mediation module are now complete. Testing the module You can use the universal test client to test the module:
43. Right-click the MQHeaderExample1 mediation component and select Test component.

Tuesday, August 30, 2011 Page 8 of 10

L&T Infotech Proprietary

44. In the Component Test Events view, enter any value for the value field of input1.

45. Click the Continue(run) button to start the test. 46. 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 in Figure 7. Figure 7. Invoke Returned

29. Using WebSphere MQ Explorer, right-click the send queue and select Browse Messages. 30. Double-click the message and you will see the properties that were set in the mediation

component, as shown in Figure 8.

Tuesday, August 30, 2011 Page 9 of 10

L&T Infotech Proprietary

Figure 8. MQMessage

Congratulations, you have successfully created a mediation module that adds a MQHeader to a message.

Tuesday, August 30, 2011 Page 10 of 10

L&T Infotech Proprietary

Potrebbero piacerti anche