This topic describes how to add function to a preexisting mediation handler to set routing addresses in the message header.
To work with routing addresses, you will use the SIDestinationAddress and SIDestinationAddressFactory APIs. The SIDestinationAddress is the public interface which represents an service integration bus, and gives your mediation access to the name of the destination and the bus name. SIDestinationAddressFactory enables you to create a new SIDestinationAddress to represent an service integration bus destination. For reference information about these APIs, see SIDestinationAddress and SIDestinationAddressFactory.
/* A sample mediation that simply clones a message * and sends the clone off to another destination */ public class RoutingMediationHandler implements MediationHandler { public String remoteDestinationName="newdest"; public boolean handle(MessageContext context) throws MessageContextException { SIMessage clonedMessage = null; SIMessageContext mediationContext = (SIMessageContext) context; SIMessage message = mediationContext.getSIMessage(); SIMediationSession mediationSession = mediationContext.getSession(); // Create a forward routing path which will be set on the cloned message Vector forwardRoutingPath = new Vector(); SIDestinationAddressFactory destFactory = SIDestinationAddressFactory.getInstance(); SIDestinationAddress dest = destFactory.createSIDestinationAddress(remoteDestinationName,false); forwardRoutingPath.add(dest); try { // Clone the message clonedMessage = (SIMessage) message.clone(); // Modify the forward routing path for the clone clonedMessage.setForwardRoutingPath(forwardRoutingPath); // Send the message to the next destination in the frp mediationSession.send(clonedMessage, false); } catch (SIMediationRoutingException e1) { e1.printStackTrace(); } catch (SIDestinationNotFoundException e1) { e1.printStackTrace(); } catch (SINotAuthorizedException e1) { e1.printStackTrace(); } catch (CloneNotSupportedException e) { // SIMessage should clone OK so we shouldn't really enter this block e.printStackTrace(); } // allow original message to continue on its path return true; }