Network Deployment (Distributed operating systems), v8.0 > Develop and deploying applications > Develop Service integration > Program mediations > Add mediation function to handler code


Work with message properties

We can work with the message properties to affect subsequent processing. Before you start this task, you should read about the properties that are 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.

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

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, by 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();
      }
    }

+

Search Tips   |   Advanced Search