Working with the message properties

This topic describes how to work with the message properties to affect subsequent processing.

Before you begin

Before you start this task, you should read about the properties that are supported by the SIMessage interface in Message properties support for mediations.

About this task

There are two different types of message properties:
  • System properties (including JMS headers, JMSX properties, and JMS_IBM_properties)
  • User properties.

You can work with message properties to affect which messages a later mediation should process, or to affect processing by a downstream application or mediation. The rule set in the selector field during mediation configuration tests values in the message properties.

You can access, modify and clear properties using the SIMessage interface (see SIMessage.) There are three different sets of methods:

  • These properties operate on system properties, plus user properties if the name is qualified with a prefix user.:
    • getMessageProperty
    • setMessageProperty
    • deleteMessageProperty
    • clearMessageProperties
  • These properties operate on user properties only, without the need for the prefix user.:
    • getUserProperty
    • setUserProperty
    • deletUserProperty
    • clearUserProperties
  • getUserPropertyNames returns a list of the names of the user properties in the message.
Typically, you can work with message properties in the following way, when programming a mediation:

Procedure

  1. Locate the point in your mediation handler where you insert the functional mediation code, in the method handle (MessageContext context). The interface is MessageContext, and you should cast this to SIMessageContext unless you are only interested in the methods provided by MessageContext.
  2. Get the SIMessage from the MessageContext object. For example, SIMessage message = ((SIMessageContext)context).getSIMessage();
  3. Build your mediation header function in a similar way to these examples, using the reference information in Message properties support for mediations to help:
    1. Get a user property of the message. For instance, String task = (String)msg1.getUserProperty("task");. In this case, the task string may refer to an operation that the mediation should perform.
    2. Set a user property, where message Properties are stored as name-value pairs. The setUserProperty method may only be used to set user properties, so the name passed into the method should not include the "user." prefix. For example, msg1.setUserProperty("background","green");
    3. Delete a user property from the message. For instance, msg1.deleteUserProperty("task");

Example

Mediation function code to work with message properties may look similar to the code snippet in this example:

    String task = (String)msg1.getUserProperty("task");
    if (task != null) {
      if (task.equals("addColor")) {
        msg1.setMessageProperty(SIProperties.JMS_IBM_Format, "colorful");
        msg1.setUserProperty("background","green");
        msg1.setUserProperty("foreground","purple");
        msg1.setUserProperty("depth",new Integer(3));
        msg1.deleteUserProperty("task");
      }
      else {
        msg1.clearUserProperties();
      }
    }     



In this information ...


IBM Redbooks, demos, education, and more

(Index)

Use IBM Suggests to retrieve related content from ibm.com and beyond, identified for your convenience.

This feature requires Internet access.

Task topic Task topic    

Terms and conditions for information centers | Feedback

Last updatedLast updated: Aug 31, 2013 4:28:44 AM CDT
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=pix&product=was-nd-mp&topic=tjy1504
File name: tjy1504.html