例: Web サービス・デプロイメント記述子のハンドラー・クラスの構成
このシナリオでは、クライアントおよびサーバーのハンドラー・クラスを WebServicesSamples.ear という名前のサンプル・アプリケーションに追加する方法について説明します。ハンドラー・クラスは、処理すべき要求または応答が指定されると、メッセージを表示します。
クライアントのハンドラー・クラスのコードは、以下の例で示されます。
package samples;
public class ClientHandler implements javax.xml.rpc.handler.Handler {
public ClientHandler() { }
public boolean handleRequest(javax.xml.rpc.handler.MessageContext context) {
System.out.println("ClientHandler: In handleRequest");
return true; }
public boolean handleResponse(javax.xml.rpc.handler.MessageContext context) {
System.out.println("ClientHandler: In handleResponse");
return true; }
public boolean handleFault(javax.xml.rpc.handler.MessageContext context) {
System.out.println("ClientHandler: In handleFault");
return true; }
public void init(javax.xml.rpc.handler.HandlerInfo config) { }
public void destroy() { }
public javax.xml.namespace.QName[] getHeaders() {
return null; }
}
サーバー・ハンドラー・クラスのコードは、以下の例で示されます。
package sample;
public class ServerHandler implements javax.xml.rpc.handler.Handler {
public ServerHandler() { }
public boolean handleRequest(javax.xml.rpc.handler.MessageContext context) {
System.out.println("ServerHandler: In handleRequest");
return true; }
public boolean handleResponse(javax.xml.rpc.handler.MessageContext context) {
System.out.println("ServerHandler: In handleResponse");
return true; }
public boolean handleFault(javax.xml.rpc.handler.MessageContext context) {
System.out.println("ServerHandler: In handleFault");
return true; }
public void init(javax.xml.rpc.handler.HandlerInfo config) { }
public void destroy() { }
public javax.xml.namespace.QName[] getHeaders() {
return null; }
}
- これらのクラスを、以下のようにしてコンパイルする。
%JAVA_HOME%¥bin¥java -extdirs %WAS_EXT_DIRS% ClientHandler.java ServerHandler.java
$JAVA_HOME/bin/java -extdirs $WAS_EXT_DIRS ClientHandler.java ServerHandler.java
- アセンブリー・ツールを開き、以下の 2 つのサンプルのエンタープライズ・アーカイブ (EAR) ファイルをインポートする。
...¥installableApps¥WebServicesSamples.ear
.../installableApps/WebServicesSamples.ear
...¥installableApps¥ApplicationClients.ear
.../installableApps/ApplicationClients.ear
- コンパイルしたハンドラー・クラスを、サンプル・モジュール用のプロジェクトにインポートする。
- sample.ClientHandler を、AddressBookClient プロジェクトの appClientModule ディレクトリーにインポートする。
- sample.ServerHandler を、AddressBookW2JE プロジェクトの ejbModule ディレクトリーにインポートする。
- ハンドラー・クラス用のクライアント・デプロイメント記述子を構成する。
このトピックでは、ユーザー提供のハンドラー・クラス用のクライアント・デプロイメント記述子の構成方法を説明します。
- ハンドラー・クラス用の webservices.xml デプロイメント記述子を構成する。
このトピックでは、ユーザー提供のハンドラー・クラス用の webservices.xml デプロイメント記述子の構成方法を説明します。
- 変更内容を保存して EAR ファイルをエクスポートする。
- WebServicesSamples.ear アプリケーションがインストールされている場合は、 このアプリケーションをサーバーからアンインストールする。
- 新規の WebServicesSamples.ear アプリケーションをインストールする。
- サーバーを始動する。
- 以下のようにして、クライアントを実行する。
launchClient ApplicationClients.ear -CCjar=AddressBookClient.jar
クライアントが稼働する時のコンソール出力は以下の例のようになります。ハンドラーからのメッセージは、 太字で表示されています。
IBM WebSphere Application Server J2EE Application Client Tool Copyright IBM Corp., 1997-2003 WSCL0012I: Processing command line arguments. WSCL0013I: Initializing the J2EE Application Client Environment. WSCL0035I: Initialization of the J2EE Application Client Environment has completed. WSCL0014I: Invoking the Application Client class com.ibm.websphere.samples.webservices.addr.AddressBookClient >> Querying address for 'Purdue Boilermaker' using port AddressBookW2JE ClientHandler: In handleRequest ClientHandler: In handleResponse >> Response is: 1 University Drive West Lafayette, IN 47907 Phone: (765) 555-4900 >> Querying address for 'Purdue Boilermaker' using port AddressBookJ2WE ClientHandler: In handleRequest ClientHandler: In handleResponse >> Response is: 2 University Drive West Lafayette, IN 47907 Phone: (765) 555-4900 >> Querying address for 'Purdue Boilermaker' using port AddressBookJ2WB ClientHandler: In handleRequest ClientHandler: In handleResponse >> Response is: 3 University Drive West Lafayette, IN 47907 Phone: (765) 555-4900 >> Querying address for 'Purdue Boilermaker' using port AddressBookW2JB ClientHandler: In handleRequest ClientHandler: In handleResponse >> Response is: 4 University Drive West Lafayette, IN 47907 Phone: (765) 555-4900
クライアントでは、ハンドラー・クラスはポートごとではなくサービス参照ごとに構成されます。 AddressBook サンプルには 4 つのポートがありますが、サービス参照は 1 つしかありません。したがって、ClientHandler はすべてのポート上の要求と応答を処理します。
サーバー・ログ・ファイルを調べると、以下のデータがあります。
[9/24/03 16:39:22:661 CDT] 4deec1c6 WebGroup I SRVE0180I:
[HTTP router for AddressBookW2JE.jar] [/AddressBookW2JE] [Servlet.LOG]:
AddressBook: init
[9/24/03 16:39:23:161 CDT] 4deec1c6 SystemOut O ServerHandler: In handleRequest
[9/24/03 16:39:23:211 CDT] 4deec1c6 SystemOut O ServerHandler: In handleResponse
結果
ハンドラー・クラス用のデプロイメント記述子が構成されました。WebSphere® Application Server が着信 Web サービス要求を処理できるようにするには、デプロイメント記述子が必要です。
次の作業
構成した EAR ファイルをデプロイし、Web サービスに使用できるようにします。アプリケーションを試験して、WebSphere Application Server 環境内で稼働するか確認できます。