例: WS-Notification コンシューマーのサブスクリプション

提供されているコード例の抜粋に基づいて、パブリッシャー登録ロールを果たす JAX-RPC クライアントが、ブローカーにパブリッシャー (プロデューサー) アプリケーションを登録するためのコードを作成する場合は、このタスクを使用します。

このタスクについて

この例は 、Java™ API for XML-based remote procedure calls (JAX-RPC) API と、WSDL2Java ツール (WS-Notification サービス・ポイントの作成の結果として生成された Notification Broker WSDL に対し実行) および WebSphere® Application Server API および SPI を使用して生成されたコードと併せた使用を基にしています。

WebSphere Application Server では、WS-Notification サービスにはバージョン 6.1 およびバージョン 7.0 の 2 つの実装があります。この JAX-RPC 例は、バージョン 6.1 またはバージョン 7.0 WS-Notification サービス・ポイントと正常にやり取りすることができます。 ただし、WS-Notification をポリシー・セットと一緒に使用したい場合は (例えば、WS-ReliableMessaging による構成を可能にするため)、Java API for XML-based Web Services (JAX-WS) プログラミング・モデルを使用するように WS-Notification アプリケーションをエンコードする必要があります。なおかつ WS-Notification アプリケーションはバージョン 7.0 WS-Notification サービス・ポイントとやり取りする必要があります。 JAX-WS クライアント・アプリケーションをプログラミングした経験がない場合は、以下のトピックを参照してください。 Writing JAX-WS applications for WS-Notification という記事にも、JAX-WS サブスクライバー・クライアント・アプリケーションの例が記載されています。
ロー・サブスクリプション :

この例の最初のオプションのコード・ブロックは、ロー・サブスクリプション の作成方法を示しています。 この概念は、Web サービスの基本通知仕様のセクション 4.2 で定義されます。

通常のケースでは、ラップされたサブスクリプションによって、一致するイベント通知が使用可能になったときに NotificationConsumer の「通知」操作が駆動されます。 サブスクライバーがロー・サブスクリプションを作成する場合は、イベント通知のアプリケーション固有のコンテンツ (つまり、NotificationMessage エレメントのコンテンツ) のみがターゲット・コンシューマー・エンドポイントへ送信されます。 UseRaw (つまり、ロー・サブスクリプション要求) が指定されたサブスクライブ要求の ConsumerReference 内で指定された Web サービス・エンドポイントは、NotificationConsumer ポート・タイプを実装する必要がありません。「通知」操作がイベント通知の配信に使用されないためです。

このことは、コンシューマーは特定のトピックでパブリッシュされるアプリケーション・コンテンツのタイプごとに、操作を受け入れることができる必要があることを意味します。 このパターンによって、WS-Notification が、WS-Notification 認識ではないが、同じ情報を受信したい既存の Web サービス・アプリケーションのグループを起動することが可能になります。

JAX-WS はアクション・ベースのディスパッチをサポートし、JAX-WS ロー・コンシューマー・アプリケーションは、http://docs.oasis-open.org/wsn/bw-2/NotificationConsumer/Notify アクション URI を受け入れる必要があります。詳しくは、トラブルシューティングのヒントであるブローカー経由の通知のロー・コンシューマーである JAX-WS アプリケーションは、通知ブローカー SOAP アクションを認識しなければならないを参照してください。

パブリッシャー登録ロールを果たす JAX-RPC クライアントが、ブローカーにパブリッシャー (プロデューサー) アプリケーションを登録するためのコードを作成するには、以下のステップを実行します (詳しくは、コード例の抜粋を参照)。

手順

  1. JAX-RPC サービスを検索します。 JNDI 名は、Web サービス・クライアントの実装に固有のものです。
  2. 操作の呼び出しを行うポートのスタブを取得します。
  3. ConsumerReference を作成します。 これには、サブスクライブされているコンシューマー Web サービスのアドレス、または pull ポイントへの参照が含まれています。pull ポイント EPR を指定すると、コンシューマーは pull ベースの通知を使用することになります。
  4. フィルターを作成します。 これにより、コンシューマーをサブスクライブするトピックの名前が指定されます。
  5. トピック式を作成し、それをフィルターに追加します。 prefixMappings は、名前空間の接頭部と、それに対応する、式で使用される接頭部の名前空間の間のマッピングです。
  6. XPath 1.0 のメッセージ・コンテンツ・フィルターを作成します。 例えば、給与水準に基づいて、トピック内の使用可能なメッセージのサブセットを選択できます。メッセージ・コンテンツ・フィルターの使用例については、パブリケーションのメッセージ・コンテンツのフィルターを参照してください。
  7. InitialTerminationTime を作成します。 This is the time when you want the subscription to terminate. 例えば、今から 1 年後と設定することができます。
  8. ポリシー情報を作成します。
  9. オプション: コンシューマーが未加工スタイルの通知を受信することを示すポリシーを構成します。
  10. ブローカーから返される以下の複数の値を保持するためのホルダーを作成します。
    • サブスクリプション参照
    • ブローカーにおける現在時刻
    • サブスクリプションの終了時刻
    • 追加エレメント
  11. スタブで関連付けられているメソッドを呼び出して、サブスクライブ操作を呼び出します。
  12. 以下の戻り値を取得します。
    • 作成済みサブスクリプションのエンドポイント参照。 これは、サブスクリプションの一時停止など、サブスクリプションの今後の存続期間の管理に必要です。
    • ブローカーにおける現在時刻。
    • サブスクリプションの終了時刻。
    • その他の情報。

以下のコード例は、ブローカーでコンシューマー・アプリケーションをサブスクライブできるサブスクライバー・クライアント・アプリケーションを示しています。
// Look up the JAX-RPC service. The JNDI name is specific to your web services client implementation
InitialContext context = new InitialContext();
javax.xml.rpc.Service service = (javax.xml.rpc.Service) context.lookup(
    "java:comp/env/services/NotificationBroker");

// Get a stub for the port on which you want to invoke operations
NotificationBroker stub = (NotificationBroker) service.getPort(NotificationBroker.class);

// Create the ConsumerReference. This contains the address of the consumer Web service that is being
// subscribed, or alternatively is a reference to a pull point (see alternative below). Specifying a
// pull point EPR indicates that the consumer is to use pull-based notifications.
EndpointReference consumerEPR = 
    EndpointReferenceManager.createEndpointReference(new URI("http://myserver.mycom.com:9080/Consumer"));

/*
// Alternative ConsumerReference for pull-based notifications:

EndpointReference consumerEPR = pullPointEPR;

*/

// Create the Filter. This provides the name of the topic to which you want to subscribe the consumer
Filter filter = new Filter();

// Create a topic expression and add it to the filter. The prefixMappings are mappings between namespace 
// prefixes and their corresponding namespaces for prefixes used in the expression
Map prefixMappings = new HashMap();
prefixMappings.put("abc", "uri:example");
TopicExpression exp =
    new TopicExpression(TopicExpression.SIMPLE_TOPIC_EXPRESSION, "abc:ExampleTopic", prefixMappings);        
filter.addTopicExpression(exp);


//Create an XPath 1.0 message content filter
//This example selects a subset of the available messages in the topic, based upon salary level
String filterExpression = "/company/department/employee/salary > 10000";
URI xpathURI = new URI(http://www.w3.org/TR/1999/REC-xpath-19991116);

QueryExpression qexp = 
    new QueryExpression(xpathURI, filterExpression);

filter.addMessageContentExpression(qexp);

// Create the InitialTerminationTime. This is the time when you want the subscription to terminate.
// For example, set a time of 1 year in the future.
Calendar cal = Calendar.getInstance();
cal.add(Calendar.YEAR, 1);
AbsoluteOrRelativeTime initialTerminationTime = new AbsoluteOrRelativeTime(cal);

// Create the Policy information
SOAPElement[] policyElements = null;

/*
Optional
--------
The following lines show how to construct a policy indicating that the consumer is to 
receive raw style notifications:

    javax.xml.soap.SOAPFactory soapFactory = javax.xml.soap.SOAPFactory.newInstance();
    SOAPElement useRawElement = null;

    if (soapFactory instanceof IBMSOAPFactory) {
        // You can use the value add methods provided by the IBMSOAPFactory API to create the SOAPElement
        // from an XML string.
       String useRawElementXML = "<mno:UseRaw xmlns:mno=¥"http://docs.oasis-open.org/wsn/b-2¥"/>";
        useRawElement = ((IBMSOAPFactory) soapFactory).createElementFromXMLString(useRawElementXML);
    } else {
        useRawElement = soapFactory.createElement("UseRaw", "mno", "http://docs.oasis-open.org/wsn/b-2");
    }

    policyElements =  new SOAPElement[] { useRawElement };
*/

// Create holders to hold the multiple values returned from the broker:
// The subscription reference
EndpointReferenceTypeHolder subscriptionRefHolder = new EndpointReferenceTypeHolder();

// The current time at the broker
CalendarHolder currentTimeHolder = new CalendarHolder();

// The termination time for the subscription
CalendarHolder terminationTimeHolder = new CalendarHolder();

// Any additional elements
AnyArrayHolder anyOtherElements = new AnyArrayHolder();

// Invoke the Subscribe operation by calling the associated method on the stub
stub.subscribe(consumerEPR,
                       filter,
                       initialTerminationTime,
                       policyElements,
                       anyOtherElements,
                       subscriptionRefHolder,
                       currentTimeHolder,
                       terminationTimeHolder);

// Get the returned values:
// An endpoint reference for the subscription that has been created. It is required for
// subsequent lifetime management of the subscription, for example pausing the subscription
com.ibm.websphere.wsaddressing.EndpointReference subscriptionRef = subscriptionRefHolder.value;

// The current time at the broker
Calendar currentTime = currentTimeHolder.value;

// The termination time of the subscription
Calendar terminationTime = terminationTimeHolder.value;

// Any other information
SOAPElement[] otherElements = anyOtherElements.value;

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



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