Configurando Endereços de Roteamento em um Cabeçalho da Mensagem
É possível incluir uma função em um manipulador de mediação preexistente para que ele configure endereços de roteamento no cabeçalho da mensagem.
Antes de Iniciar
Sobre Esta Tarefa
Para trabalhar com o roteamento de endereços, serão usadas as APIs SIDestinationAddress e SIDestinationAddressFactory. SIDestinationAddress é a interface pública que representa um barramento de integração de serviços e permite que a mediação acesse o nome do destino e o nome do barramento. SIDestinationAddressFactory permite criar um novo SIDestinationAddress, para representar um destino do barramento de integração de serviços. Para obter informações de referência sobre essas APIs, consulte SIDestinationAddress e SIDestinationAddressFactory.
Procedimento
Exemplo
/* 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;
}