+

Search Tips   |   Advanced Search

Work with message properties

We can work with the message properties to affect subsequent processing.

Before starting this task, we should read about the properties supported by the SIMessage interface in Message properties support for mediations.

There are two different types of message properties:

We 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.

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

Typically, we can work with message properties in the following way, when programming a mediation:


Tasks

  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 we should cast this to SIMessageContext unless we 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 might 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 might 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 might 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();
      }
    }