例: WS-Notification メッセージの公開

提供されているコード例の抜粋に基づいて、通知メッセージをブローカーにパブリッシュできるパブリッシャー・クライアント・アプリケーションのコードを作成する場合は、このタスクを使用します。

このタスクについて

この例は 、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 パブリッシャー・クライアント・アプリケーションの例が記載されています。

通知メッセージをブローカーにパブリッシュできるパブリッシャー・クライアント・アプリケーションのコードを作成するには、以下のステップを実行します (詳しくは、コード例の抜粋を参照)。

手順

  1. JAX-RPC サービスを検索します。 JNDI 名は、ご使用の Web サービス・クライアントの実装環境に固有のものです。
  2. 操作の呼び出しを行うポートのスタブを取得します。
  3. 通知メッセージのメッセージ・コンテンツを作成します。
  4. そのコンテンツから通知メッセージを作成します。
  5. トピック式を通知メッセージに追加します。トピック式は、メッセージが対応する 1 つまたは複数のトピックを示す必要があります。
  6. オプションの情報があれば、作成します。
  7. オプション: ブローカーでパブリッシャー・クライアント・アプリケーションを登録する必要がある場合は、要求を特定のパブリッシャー登録に関連付けます。 registrationEPR は、RegisterPublisher 操作の呼び出しに関連してブローカーによって返される ConsumerReference EndpointReference です。
  8. スタブで関連付けられているメソッドを呼び出して、通知操作を呼び出します。

以下のコード例は、通知メッセージをブローカーにパブリッシュできるパブリッシャー・クライアント・アプリケーションを示しています。

// 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 message contents for a notification message
SOAPElement messageContents = null;
javax.xml.soap.SOAPFactory soapFactory = javax.xml.soap.SOAPFactory.newInstance();
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 messageContentsXML = "<xyz:MyData xmlns:xyz=¥"uri:mynamespace¥">Some data</xyz:MyData>";        
    messageContents = ((IBMSOAPFactory) soapFactory).createElementFromXMLString(messageContentsXML);
} else {
    // Build up the SOAPElement using the standard javax.xml.soap APIs
    messageContents = soapFactory.createElement("MyData", "xyz", "uri:mynamespace");
    messageContents.addTextNode("Some data");
}

// Create a notification message from the contents
NotificationMessage message = new NotificationMessage(messageContents);               

// Add a topic expression to the notification message indicating to which topic or topics the
// message corresponds
Map prefixMappings = new HashMap();
prefixMappings.put("abc", "uri:example");
TopicExpression exp = 
    new TopicExpression(TopicExpression.SIMPLE_TOPIC_EXPRESSION, "abc:ExampleTopic", prefixMappings);        
message.setTopic(exp);

// Create any optional information
SOAPElement[] optionalInformation =  new SOAPElement[] {};
        
/*
Optional
--------
The following line will cause the request to be associated with a particular publisher registration.
You must do this if the broker requires publishers to register. The registrationEPR is the
ConsumerReference EndpointReference returned by the broker in relation to an invocation of the 
RegisterPublisher operation.
        
    ((Stub) stub)._setProperty(WSAConstants.WSADDRESSING_DESTINATION_EPR, consumerReferenceEPR);
*/

// Invoke the Notify operation by calling the associated method on the stub
stub.notify(new NotificationMessage[] { message }, optionalInformation);

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



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