메시지 헤더에 라우팅 주소 설정
기존 중개 핸들러에 기능을 추가하여 메시지 헤더에 라우팅 주소를 설정할 수 있습니다.
시작하기 전에
이 태스크 정보
라우팅 주소에 대해 작업하려면 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;
}