メッセージ・ヘッダーのルーティング・アドレスの設定

メッセージ・ヘッダーにルーティング・アドレスを設定して、ファンクションを既存のメディエーション・ハンドラーに追加できます。

始める前に

このタスクを開始する前に、EJB プロジェクトに基本メディエーション・ハンドラーを作成してある必要があります (メディエーション・ハンドラーの作成を参照)。

このタスクについて

ルーティング・アドレスを使用する場合は、SIDestinationAddress および SIDestinationAddressFactory API を使用します。SIDestinationAddress は、 サービス統合バスを表すパブリック・インターフェースで、メディエーションに宛先名およびバス名へのアクセスを提供します。 SIDestinationAddressFactory を使用することで、サービス統合バス宛先を表す新規の SIDestinationAddress を作成することができます。 これらの API の参照情報については、SIDestinationAddressおよびSIDestinationAddressFactoryを参照してください。

手順

  1. メソッド handle (MessageContext context) 内で、ファンクション・メディエーション・コードを挿入するメディエーション・ハンドラー内のポイントを位置指定します。 インターフェースは MessageContext であり、MessageContext で提供されるメソッドに関与するのが自分のみでない限り、これを SIMessageContext にキャストする必要があります。
  2. SIMessage を MessageContext オブジェクトから取得します。 以下に例を示します。
    		SIMessage message = ((SIMessageContext)context).getSIMessage(); 
  3. 以下の基本ステップを使用して、メディエーション・ヘッダー機能を構築します。
    1. ランタイム環境へのハンドルを取得します。 以下に例を示します。
      .... SIMediationSession mediationSession = mediationContext.getSession(); 
    2. 複製されたオブジェクトで設定する転送ルーティング・パスを作成します。 例えば、Vector クラスを 使用して、オブジェクトの拡張可能配列を作成します。
    3. SIDestinationAddress インスタンスを作成するために使用する SIDestinationAddressFactory を 取得します。 以下に例を示します。
      SIDestinationAddressFactory destFactory = SIDestinationAddressFactory.getInstance();
    4. サービス統合バス宛先を表す新規の SIDestinationAddress を作成します。 以下に例を示します。
      SIDestinationAddress dest = destFactory.createSIDestinationAddress(remoteDestinationName(),false);
      このケースでは、2 番目のパラメーターであるブール値「false」は、 宛先はローカル・メッセージング・エンジンにローカライズされてはならないが、 サービス統合バス上のどこにあってもよいことを示します。
    5. Vector クラスの add メソッドを使用して、他の宛先名を配列に追加します。
    6. メッセージを複製し、複製されたメッセージの転送ルーティング・パスを変更します。 以下に例を示します。
      clonedMessage.setForwardRoutingPath(forwardRoutingPath);
    7. メッセージをサービス統合バスに送信するために、SIMediationSession インターフェースの send メソッドを使用して、 複製されたメッセージを送信します。 例えば、"clonedMessage" という名前の場合、以下のようになります。
      mediationSession.send(clonedMessage, false);
  4. true を返し、 MediationHandler インターフェースの handle メソッドに渡されたメッセージが、ハンドラー・チェーンに従って 継続するようにします。

転送ルーティング・パスを変更するための、完全なメディエーション機能コードは、以下の例のようになります。
/* 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;
	}

トピックのタイプを示すアイコン タスク・トピック



タイム・スタンプ・アイコン 最終更新: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tjy1505
ファイル名:tjy1505.html