WebSphere WebSphere Application Server Version 6.1.x Feature Pack for Web Services Operating Systems: AIX, HP-UX, i5/OS, Linux, Solaris, Windows, z/OS

Working with the message context

This topic describes how to work with the message properties to affect the way a message is mediated.

Before you begin
Before you start this task, you should read about how information is carried in the mediation context in Mediation context information
About this task

Interface SIMessageContext has a superinterface MessageContext. Methods in MessageContext allow you to manage a set of message properties, which enable handlers in a handler chain to share processing-related state. Most importantly, you can get the value of a specific property from the MessageContext using the method getProperty, and you can set the name and value of a property associated with the MessageContext using the method setProperty. You can also view the names of the properties in this MessageContext and remove a property (that is, a name-value pair) from the MessageContext.

At mediation runtime, all of the user-defined properties that have been set during configuration for the current mediation (see Configuring mediation context properties) are applied to the MediationContext property set.

Procedure

  1. Locate the point in your mediation handler where you insert the functional mediation code, in the method handle (MessageContext context). As you are working with the MessageContext methods that give you access to message properties, you do not need to cast the interface to SIMessageContext unless you are also interested in the methods provided by SIMessageContext.
  2. Get the SIMessage from the MessageContext object. For example, SIMessage message = ((SIMessageContext)context).getSIMessage();
  3. Retrieve or set properties, using the MessageContext methods. For instance, if a property has been defined during configuration with the name streetName, the type String, and the value "Main Street" your code to retrieve and print the street name may look like this:
Example
public boolean handle(MessageContext context) throws MessageContextException {
	
			........			
		{
				/* Retrieve the street name property */
				String myStreetName;
				myStreetName = (String) getProperty(streetName);
				
				/* Display property value */
				System.out.println(myStreetName);
				
		}
}
Related concepts
Mediations
Mediation context information

Task topic

Terms of use | Feedback


Timestamp icon Last updated: 27 November 2008
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.pmc.wsfep.multiplatform.doc/tasks/tjy1503.html

Copyright IBM Corporation 2004, 2008. All Rights Reserved.
This information center is powered by Eclipse technology. (http://www.eclipse.org)