Using the message context to transform messages

If you develop transformations for inbound messages, you can define a namespace in the *.xsl file for the com.ibm.ia.connectivity.MessageContextProvider class to use the message context when transforming the inbound message into an event. You can use the predefined namespace prefix, or your can define a new classifier namespace prefix.

About this task

The message context functions are not available when transforming an outbound message. For more information about the inbound message context to classifier transformation, see MessageContextProvider.

Note: Note: Do not use these methods for client applications or agent implementations. If you call these methods outside of the context of a classifier or transformation operation, you get a RuntimeException.

You can use the predefined namespace prefix, context, to address the functions defined by the MessageContext interface in the classifier expression. For example, the message classifier in the following inbound binding definition uses the context namespace to match messages that arrive with the JMSType value PurchaseEvent:

PurchaseEvent:
define inbound binding 'binding1' 
    using 
        message format application/xml , 
        protocol JMS , 
    classifying messages : 
        if matches "context:getJMSType() == 'PurchaseEvent'" 
            transform using "transformPurchaseEvent.xsl" 
        else discard message ,
    accepting events : 
        - purchase event .

The context prefix is predefined, but you can override it by defining a new classifier namespace prefix. The namespace used to access the message context functions from a classifier expression is: com.ibm.ia.connectivity.context.MessageContextProvider.

The following procedure is an example of how to generate a <timestamp> element that contains the ISO 8601 value of the message timestamp.

Procedure

  1. Open the xsl file.
  2. Define a namespace prefix, context, in the <xsl:stylesheet> element.
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         xmlns:context="com.ibm.ia.connectivity.context.MessageContextProvider"
         exclude-result-prefixes="context"
         ... >
  3. Use the function context:getMessageTimestampISO8601(zoneId) when generating the <timestamp> element in the template.
    <timestamp><xsl:value-of select="context:getMessageTimestampISO8601('UTC')"></timestamp>
  4. Save your work.