WAS v8.5 > Develop applications > Develop Service integration > Programming mediationsWriting a routing mediation
Use this topic to create a mediation that chooses a particular forward route for a message.
For an introduction to using mediations with the service integration bus, see Learning about mediations. For details of how to install a mediation into WAS and associate it with a bus destination, see Work with mediations.
This topic assumes that you are familiar with using a Java EE session bean development environment such as the assembly tools or IBM Rational Application Developer. A routing mediation is a mediation application containing a routing handler. You associate a routing mediation with a service integration bus destination, and use the mediation to choose a particular route from a range of available routes. For example when we create a new outbound service configuration or modify an existing outbound service configuration we can apply a port selection mediation to choose a particular outbound port from the range of ports available to the outbound service.
To create a routing mediation, use a Java EE session bean development environment to complete the following steps:
- Create an empty mediation handler project. This creates the project, and creates the handler class that implements the handler interface. For detailed instructions on how to do this, see Writing the mediation handler.
- Use the mediation pane on the EJB descriptor to define the handler class as a mediation handler.
When we do this, we specify a name by which the mediation handler list is known. Make a note of this name, for later reference when we create the mediation in the bus.
- Add the routing function to the handler. Before beginning, review Add mediation function to handler code, in particular its subtopic Work with message context. Add import statements to your handler class, and modify the handle method by adding your routing code. Specify the routing destination by adding that destination to the front of the forward routing path list. The forward routing path list is available from the message context. For example:
import javax.xml.rpc.handler.MessageContext; import com.ibm.websphere.sib.mediation.handler.MediationHandler; import com.ibm.websphere.sib.mediation.handler.MessageContextException; import com.ibm.websphere.sib.mediation.messagecontext.SIMessageContext; import com.ibm.websphere.sib.SIMessage; import com.ibm.websphere.sib.SIDestinationAddress; import com.ibm.websphere.sib.SIDestinationAddressFactory; import java.util.List; public class RouteMediationHandler implements MediationHandler { public boolean handle(MessageContext ctx) throws MessageContextException { SIMessageContext siCtx = (SIMessageContext) ctx; SIMessage msg = siCtx.getSIMessage(); List frp = msg.getForwardRoutingPath(); try { SIDestinationAddress destination = SIDestinationAddressFactory .getInstance() .createSIDestinationAddress( "RoutingDestination", //this is the name of the target destination false); frp.add(0, destination); } catch (Exception e) { return false; } msg.setForwardRoutingPath(frp); return true; } }For more information about the service integration technologies classes, including the mediation handler and message context classes, see the Generated API documentation - Application programming interfaces .- Export the routing mediation enterprise application.
You are now ready to install your mediation into WAS and associate it with a bus destination, as described in Work with mediations.