在消息头中设置路由地址
可以向以前存在的调解处理程序添加函数以在消息头中设置路由地址。
开始之前
关于此任务
要处理路由地址,您将使用 SIDestinationAddress 和 SIDestinationAddressFactory API。SIDestinationAddress 是一个表示服务集成总线的公共接口,它使您的调解能够访问目标的名称和总线名称。SIDestinationAddressFactory 使您能够创建新的 SIDestinationAddress 来表示服务集成总线目标。有关这些 API 的参考信息,请参阅SIDestinationAddress和SIDestinationAddressFactory。
过程
示例
/* A sample mediation that 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 that 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 you shouldn't need to enter this block
e.printStackTrace();
}
// allow original message to continue on its path
return true;
}