Network Deployment (Distributed operating systems), v8.0 > Develop and deploying applications > Develop Service integration > Program mediations
Write 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 that contains 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 you create a new outbound service configuration or modify an existing outbound service configuration you can apply a port selection mediation to choose a particular outbound port from the range of ports that are available to the outbound service.
To create a routing mediation, use a Java EE session bean development environment...
Procedure
- 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 Write the mediation handler.
- Use the mediation pane on the EJB descriptor to define the handler class as a mediation handler.
When you do this, you specify a name by which the mediation handler list is known. Make a note of this name, for later reference when you create the mediation in the bus.
- Add the routing function to the handler. Before you begin, 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.
What to do next
You are now ready to install your mediation into WAS and associate it with a bus destination, as described in Work with mediations.