Seasar DI Container with AOP

概要

S2Axisを使うと,diconに記述したコンポーネントを簡単にWebサービスとして公開したり,Webサービスをコンポーネントとして簡単に利用することが出来るようになります.

Axisを単独で使う場合,Webサービスを実装したクラスのインスタンス管理は通常Axisが行います.ちょっとしたプロトタイプ程度ならそれでも十分ですが,ある程度大きな業務アプリケーションをWebサービスとして提供する場合には,S2が提供するDI (Dependency Injection) や宣言的トランザクションなどのAOP (Aspect Oriented Programming) 機能が必要になってきます.

S2Axisを使うことで,S2が提供するDIやAOPをフルに活用したコンポーネントをAxisにデプロイし,Webサービスとして公開することが可能になります.

セットアップ

前提条件

実行環境

S2Axisを実行するには,以下のものが必要です.

  • JDK (J2SE SDK) 1.4以降が必要です.S2Axis-V1.0.0-alpha3の開発とテストはJDK 1.4.2_06で行っています.ダウンロードはこちら
  • S2の2.1以降が必要です.S2Axis-V1.0.0-alpha3の開発とテストはS2.1.8で行っています (S2Axisに同梱されています).ダウンロードはこちら
  • S2Remotingの0.0.2以降が必要です.S2Axis-V1.0.0-alpha3の開発とテストはS2Remoting 0.0.3で行っています (S2Axisに同梱されています).ダウンロードはこちら
  • Axisの1.2以降が必要です.S2Axis-V1.0.0-alpha3の開発とテストはAxis 1.2RC2で行っています (S2Axisに同梱されています).ダウンロードはこちら
  • Servlet2.3以降をサポートしたWebコンテナが必要です.S2Axis-V1.0.0-alpha3の開発とテストは,Tomcat 5.0.28で行っています.ダウンロードはこちら

開発環境

S2Axisのディストリビューションは,他のS2関連プロダクトの多くと同様,Eclipse Javaプロジェクトをアーカイブしたものとなっています.

  • Eclipse3.0以降が必要です.S2Axis-V1.0.0-alpha3の開発とテストは,Eclipse3.0.1で行っています.ダウンロードはこちら

S2AxisExamplesのディストリビューションは,Sysdeo Tomcatプラグインを使用したEclipse Tomcatプロジェクトをアーカイブしたものとなっています.

  • Sysdeo Tomcatプラグインが必要です.S2AxisExamples-V1.0.0-alpha3の開発とテストは,Sysdeo TomcatプラグインV3で行っています.ダウンロードはこちら

ダウンロード

S2AxisおよびS2AxisExamplesはこちらからダウンロードすることが出来ます.

インストール

S2Axis

  • ダウンロードしたS2Axis-Vx.y.z.zipファイルを適当なディレクトリに解凍してください.
  • Eclipseを起動し,「ファイル」−「インポート」メニューを選択してください.
  • 「インポート」ウィザードで「既存プロジェクトをワークスペースへ」を選択し,「次へ」をクリックしてください.
  • 「参照」ボタンをクリックし,先に解凍したディレクトリに出来ているs2-axis-x.y.zディレクトリを選択し,「OK」ボタンをクリックします.
  • 「終了」ボタンをクリックします.

S2AxisExamples

  • ダウンロードしたS2AxisExamples-Vx.y.z.zipファイルを適当なディレクトリに解凍してください.
  • Eclipseを起動し,「ファイル」−「インポート」メニューを選択してください.
  • 「インポート」ウィザードで「既存プロジェクトをワークスペースへ」を選択し,「次へ」をクリックしてください.
  • 「参照」ボタンをクリックし,先に解凍したディレクトリに出来ているs2-axis-examples-x.y.zディレクトリを選択し,「OK」ボタンをクリックします.
  • 「終了」ボタンをクリックします.

サンプルの確認

インストールの確認のために,サンプルを実行してください.

  • s2-axis-examplesプロジェクトを右クリックし,「Tomcatプロジェクト」−「Tomcatのコンテキストを更新する」を選択します.
  • 「Tomcat」ダイアログに「操作が成功しました。」と表示されたことを確認して「OK」ボタンをクリックします.
  • ツールバーの「Tomcat起動」ボタンをクリックします.
  • 「コンソール」ビューに「情報: Server startup in 99999 ms」と表示されることを確認します.
  • ブラウザで以下のアドレスにアクセスしします(ホスト名やポート番号はお使いの環境に合わせてください).
http://localhost:8080/s2-axis-examples/services
  • 次のように画面が表示されればセットアップは成功です.

エラーが表示された場合には,Webコンテナの設定に問題があるかもしれません.エラーメッセージの内容を確認してください.

基本的な使い方

Webアプリケーションの設定

S2Axisを使用するには,AxisおよびS2をweb.xmlに設定する必要があります.AxisおよびS2の設定の詳細はそれぞれのドキュメントを参照してください.
S2AxisはS2コンテナの初期化時にコンポーネントをAxisに登録します.このため,S2よりも先にAxisが初期化されている必要があります.そのためには,Axisが提供するサーブレットのload-on-startupをS2よりも小さくします.

以下はS2AxisExamplesに含まれているweb.xmlです.このサンプルでは,Axisのload-on-startupを10,S2のload-on-startupを20に設定しています.

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/dtd/web-app_2_3.dtd"
>
<web-app>
  <display-name>S2AxisExamples</display-name>

  <filter>
    <filter-name>s2filter</filter-name>
    <filter-class>org.seasar.framework.container.filter.S2ContainerFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>s2filter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <listener>
    <listener-class>org.apache.axis.transport.http.AxisHTTPSessionListener</listener-class>
  </listener>

  <servlet>
    <servlet-name>AxisServlet</servlet-name>
    <display-name>Apache-Axis Servlet</display-name>
    <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
  </servlet>

  <servlet>
    <servlet-name>AdminServlet</servlet-name>
    <display-name>Axis Admin Servlet</display-name>
    <servlet-class>
        org.apache.axis.transport.http.AdminServlet
    </servlet-class>
    <load-on-startup>10</load-on-startup>
  </servlet>

  <servlet>
    <servlet-name>SOAPMonitorService</servlet-name>
    <display-name>SOAPMonitorService</display-name>
    <servlet-class>
        org.apache.axis.monitor.SOAPMonitorService
    </servlet-class>
    <init-param>
      <param-name>SOAPMonitorPort</param-name>
      <param-value>5001</param-value>
    </init-param>
    <load-on-startup>10</load-on-startup>
  </servlet>

  <servlet>
    <servlet-name>s2servlet</servlet-name>
    <display-name>s2servlet</display-name>
    <servlet-class>org.seasar.framework.container.servlet.S2ContainerServlet</servlet-class>
    <init-param>
      <param-name>configPath</param-name>
      <param-value>app.dicon</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>false</param-value>
    </init-param>
    <load-on-startup>20</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/servlet/AxisServlet</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>SOAPMonitorService</servlet-name>
    <url-pattern>/SOAPMonitor</url-pattern>
  </servlet-mapping>

  <!-- uncomment this if you want the admin servlet -->
  <!--
  <servlet-mapping>
    <servlet-name>AdminServlet</servlet-name>
    <url-pattern>/servlet/AdminServlet</url-pattern>
  </servlet-mapping>
  -->

  <servlet-mapping>
    <servlet-name>s2servlet</servlet-name>
    <url-pattern>/s2servlet</url-pattern>
  </servlet-mapping>

  <session-config>
    <!-- Default to 5 minute session timeouts -->
    <session-timeout>5</session-timeout>
  </session-config>

  <!-- currently the W3C havent settled on a media type for WSDL;
    http://www.w3.org/TR/2003/WD-wsdl12-20030303/#ietf-draft
    for now we go with the basic 'it's XML' response -->
  <mime-mapping>
    <extension>wsdl</extension>
    <mime-type>text/xml</mime-type>
  </mime-mapping>

  <mime-mapping>
    <extension>xsd</extension>
    <mime-type>text/xml</mime-type>
  </mime-mapping>

  <welcome-file-list id="WelcomeFileList">
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
</web-app>

サーバ側の設定

s2-axis.diconファイルのインクルード

S2Axisを使用するサーバ側では,app.diconファイルの中でs2-axis.diconファイルをインクルードします.

<components>
    <include path="s2-axis.dicon"/>
    ・・・
</components>

s2-axis.dicons2-axis-x.y.z.jarの中に含まれているため,ロケーションを気にする必要はありません.

サービスのデプロイ

コンポーネントをWebサービスとしてAxisにデプロイするには,そのコンポーネントの<component>要素の子として<meta>要素を指定します.

    <component name="Echo" class="org.seasar.remoting.axis.examples.ex01.EchoImpl">
        <meta name="s2-axis:service"/>
    </component>

<meta>要素の内容を省略した場合 (および後述のServiceDefを指定した場合),<component>要素のname属性は必須です.公開されるサービスのURLは次のようになります.

  • context-path/services/name
  • context-path/services/namespace/name

<meta>要素の内容にorg.seasar.remoting.axis.server.ServiceDefを設定することにより,いくつかの設定を行うことが出来ます.

    <component name="Hello" class="org.seasar.remoting.axis.examples.ex02.HelloImpl">
        <meta name="s2-axis:service">
            <component class="org.seasar.remoting.axis.server.ServiceDef">
                <property name="serviceType">
                    @org.seasar.remoting.axis.examples.hello.Hello@class
                </property>
            </component>
        </meta>

        <property name="...">・・・</property>
    </component>

org.seasar.remoting.axis.server.ServiceDefには次のプロパティがあります.

プロパティ 説明
serviceType 公開するサービスの型を指定します.省略するとコンポーネントの型になります.実装ではなく,インタフェースを指定することで,不要なメソッドが公開されることを防ぐことが出来ます.
allowMethods 公開するメソッドを指定します.省略するとサービスの型が持つpublicなメソッドが全て公開されます (ただし,java.lang.Objectで定義されているメソッドは公開されません).
provider サービスプロバイダの種類を指定します.現在サポートされているのはRPCMsgだけです.省略するとRPCになります.

Axisを使う場合,アプリケーション独自のJavaBeansなど,JAX-RPCで定められていない型をサービスの引数や戻り値として使う場合にはSerializer / Deserializerを指定する必要があります.S2Axisでは,JavaBeansのSerializer / Deserializerを自動登録するので,特別なSerializer / Deserializerが必要な場合を除いて明示的に登録する必要はありません.
特別なSerializer / Deserializerを使う場合や,Java型のパッケージとXML型の名前空間の対応を指定したい場合には,タイプマッピングを登録します.
ServiceDefにはタイプマッピングを複数登録することが出来ます.

    <component name="Hello" class="org.seasar.remoting.axis.examples.ex02.HelloImpl">
        <meta name="s2-axis:service">
            <component class="org.seasar.remoting.axis.server.ServiceDef">
                <initMethod name="addTypeMapping">
                    <arg>
                        <component type="org.seasar.remoting.axis.server.TypeMappingDef">
                            <property name="...">・・・</property>
                        </component>
                    </arg>
                </initMethod>
            </component>
        </meta>

        <property name="...">・・・</property>
    </component>

org.seasar.remoting.axis.server.TypeMappingDefには次のプロパティがあります.

プロパティ 説明
type Java型のクラスを指定します.このプロパティは必須です.
namespaceURI XML型の名前空間URIを指定します.省略するとJava型の型のパッケージから導出されます.
namespacePrefix XML型の名前空間接頭辞を指定します.省略するとデフォルト名前空間になります.
localPart XML型のローカル名を指定します.省略するとJava型のクラス名が使われます.
serializer シリアライザファクトリを指定します.省略するとAxisのBeanSerialzierFactoryが使われます.
deserializer デシリアライザファクトリを指定します.省略するとAxisのBeanDeserialzierFactoryが使われます.
encodingStyle エンコーディングスタイルを指定します.省略するとencodedが使われます.

WebサービスのWSDLがあり,AxisのWSDL2Javaを使用してJavaの実装クラスを作成した場合には,WSDL2Javaが生成したdeploy.wsddを指定してサービスをデプロイすることが出来ます.

    <component name="Magazine" class="org.seasar.remoting.axis.examples.ex05.MagazineSoapBindingImpl">
        <meta name="s2-axis:service">"org/seasar/remoting/axis/examples/ex05/deploy.wsdd"</meta>

        ・・・
    </component>

この場合,WSDL2Javaを実行する際に指定されたJava型とXML型とのタイプマッピングがdeploy.wsddに含まれているので,必要なタイプマッピングが全てデプロイされます.

クライアント側の設定

S2Axisを使うことで,Webサービスをコンポーネントとして使用することが出来ます.

動的呼び出し

Javaインタフェースを使用してサービスを呼び出すには,diconファイルを次のように記述します.

    <!-- リモート呼び出しのインターセプタ -->
    <component name="remoting" class="org.seasar.remoting.client.interceptors.RemotingInterceptor"/>

    <!-- Axisサービス -->
    <component class="org.apache.axis.client.Service"/>

    <!-- Axisコネクタ -->
    <component name="connector" class="org.seasar.remoting.axis.connector.AxisConnector">
        <property name="baseURL">
            "http://localhost:8080/s2-axis-examples/services/"
        </property>
    </component>

    <!-- Webサービスのプロキシ -->
    <component name="Echo" class="org.seasar.remoting.axis.examples.ex01.Echo">
        <aspect>remoting</aspect>
    </component>

RemotingInterceptorはS2コンテナ全体で一つ必要です.Axisサービスは (通常) diconファイルごとに一つ必要です.AxisコネクタはエンドポイントのベースURLごとに一つ必要です.
呼び出すWebサービスごとにプロキシが必要です.<component>要素のclass属性にはJavaインタフェースを指定します.このコンポーネントにはRemotingInterceptorをアスペクトとして指定します.RemotingInterceptorは,このインタフェースのメソッド呼び出しを捕まえて,Webサービスのリモート呼び出しを実行します.その際,コンポーネントの名前 (<component>要素のname属性) がAxisコネクタのベースURLからの相対URLとしてWebサービスのURLとなります.

静的呼び出し

WSDLから生成されたスタブを使用してサービスを呼び出すには,diconファイルを次のように記述します.

    <component class="org.seasar.axis.examples.ex05.Magazine">
        <!-- locator.getMagazine() -->
        locator.getMagazine(
            new java.net.URL(locator.getMagazineAddress() +
                locator.getMagazineWSDDServiceName()))
    </component>

    <component name="locator" class="org.seasar.axis.examples.ex05.MagazineServiceLocator"/>

サービスロケータはWSDL2Javaにより生成されるクラスです.このクラスのメソッドgetXxx()によりサービスのJavaインタフェースを実装したスタブを取得することが出来ます.
本来はコメントになっている locator.getMagazine() でスタブを取得できるはずだと思うのですが,Axis 1.2RC2ではうまく取得できませんでした.明示的にURLを組み立てて指定するとスタブを取得することが出来ました.

クライアント/サーバ共通の設定

s2-axis.diconファイルのインクルード

以下の機能を使用する場合は,サーバ側だけでなくクライアント側でも,app.diconファイルの中でs2-axis.diconファイルをインクルードします.

<components>
    <include path="s2-axis.dicon"/>
    ・・・
</components>

s2-axis.dicons2-axis-x.y.z.jarの中に含まれているため,ロケーションを気にする必要はありません.

ハンドラのデプロイ

サービスだけでなく,ハンドラもS2でインスタンス管理することが出来ます.

    <component name="fooRequestHandler" class="org.seasar.remoting.axis.examples.ex06.LoggingHandler">
        <meta name="s2-axis:handler"/>

        ・・・
    </component>

<component>要素のname属性は必須です.ハンドラチェーンなどではこの名前を指定してハンドラを参照することが出来ます.

WSDDのデプロイ

任意のWSDDファイルをS2Axisでデプロイすることが出来ます.

<components>
    <meta name="s2-axis:deploy">"org/seasar/remoting/axis/examples/ex07/deploy.wsdd"</meta>
</components>

これは,AxisのAdminClientによるデプロイと同等ですが,S2の初期化時に自動的にデプロイされます.

Axisエンジンの指定

サービスやハンドラ,WSDDファイルをデプロイするAxisエンジンをdiconファイルごとに指定することが出来ます.

<components>
    <meta name="s2-axis:engine">"default-client"</meta>
</components>

<meta>要素の内容に指定した文字列より,次のようにAxisエンジンが決定されます.

内容 意味
(指定なし) "default"を指定した場合と同じです.
"default" S2コンテナにServletContextが設定されていれば"default-server",そうでなければ"default-client"を指定した場合と同じです.
"default-client" S2コンテナからjavax.xml.rpc.Serviceを実装したコンポーネント (サービスまたはサービスロケータ) を取得し,そのエンジンを使用します.
"default-server" ServletContextからAxisエンジンを取得します.
(その他) 指定された名前のコンポーネントをAxisエンジンとして使用します.

サンプル

S2Axis-Examplesには,S2Axisの基本的な機能を一通り使用したサンプルです.ソースはサーバ側とクライアント側に分かれており,クライアント側はJUnit (S2Unit) のテストケースとして作成されています.それぞれ,以下のソースフォルダにあります.

サーバ側
src/mainフォルダのorg.seasar.axis.examples.exnnパッケージ
クライアント側
src/testcaseフォルダのorg.seasar.axis.examples.exnnパッケージ

ex01 コンポーネントをWebサービスとして公開する

単純なクラスをWebサービスとして公開する例です.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
        "http://www.seasar.org/dtd/components21.dtd">
<components>
        <component name="Echo" class="org.seasar.remoting.axis.examples.ex01.EchoImpl">
                <meta name="s2-axis:service"/>
        </component>
</components>

クライアント側は動的呼び出しを使用しています.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
        "http://www.seasar.org/dtd/components21.dtd">
<components>
    <component name="remoting" class="org.seasar.remoting.client.interceptors.RemotingInterceptor"/>
    <component class="org.apache.axis.client.Service"/>

    <component name="connector" class="org.seasar.remoting.axis.connector.AxisConnector">
        <property name="baseURL">
            "http://localhost:8080/s2-axis-examples/services/"
        </property>
    </component>

    <component class="org.seasar.remoting.axis.examples.ex01.Echo">
        <aspect>remoting</aspect>
    </component>
</components>

ex02 実装ではなくインタフェースを公開する

実装クラスを公開すると,不要なメソッドまで公開されてしまいます.ex02の実装クラスHelloImplでは,setMessage(String)メソッドはWebサービスとして公開するものではありません (Helloインタフェースにはそのメソッドは定義されていません).
このような場合には,公開するJavaインタフェースを指定します.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
        "http://www.seasar.org/dtd/components21.dtd">
<components>
        <component name="Hello" class="org.seasar.remoting.axis.examples.ex02.HelloImpl">
                <meta name="s2-axis:service">
                        <component class="org.seasar.remoting.axis.server.ServiceDef">
                                <property name="serviceType">
                                    @org.seasar.remoting.axis.examples.hello.Hello@class
                                </property>
                        </component>
                </meta>
                <property name="message">"Hello"</property>
        </component>
</components>
<property>要素をコメントアウトしてWebコンテナを起動すると,HelloのWSDLにsetServiceType(String)メソッドが含まれることを確認することが出来ます.

ex03 自動タイプマッピングを使用する

このサンプルでは,サービスは引数および戻り値の型としてJavaBeansを使用しています.しかし,クライアント・サーバ側ともS2Axisが自動的にタイプマッピングを登録するため,特に何も指定しなくても動作します.

ex04 セッションスコープを使用する

Axisは独自の拡張機能としてHTTPセッションを使用したセッションスコープのサービスをサポートします.S2Axisでセッションスコープのサービスを使う場合には,サービスのライフサイクル管理はS2で行います.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
        "http://www.seasar.org/dtd/components21.dtd">
<components>
        <component name="Counter" class="org.seasar.axis.examples.ex04.CounterImpl"
            instance="session"
        >
                <meta name="s2axis:service"/>
        </component>
</components>

instance属性の値を singletonprototypeに変更すると,このサンプルは正しく動作しなくなります (テストケースであるクライアントが失敗します).

セッションスコープを使う場合,クライアント側ではセッショントラッキングを有効にする必要があります.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
        "http://www.seasar.org/dtd/components21.dtd">
<components>
    <component name="remoting" class="org.seasar.remoting.client.interceptors.RemotingInterceptor"/>
    <component class="org.apache.axis.client.Service">
        <property name="maintainSession">true</property>
    </component>

    <component name="connector" class="org.seasar.remoting.axis.connector.AxisConnector">
        <property name="baseURL">
            "http://localhost:8080/s2-axis-examples/services/"
        </property>
    </component>

    <component class="org.seasar.remoting.axis.examples.ex04.Counter">
        <aspect>remoting</aspect>
    </component>
</components>

maintainSessio属性の値を falseにすると,このサンプルは正しく動作しなくなります.

ex05 WSDLを使用する

WSDL2Javaを使ってJavaのスタブおよびスケルトンを生成した場合のサンプルです.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
        "http://www.seasar.org/dtd/components21.dtd">
<components>
        <component name="Magazine" class="org.seasar.remoting.axis.examples.ex05.MagazineSoapBindingImpl">
                <meta name="s2-axis:service">
                        "org/seasar/remoting/axis/examples/ex05/deploy.wsdd"
                </meta>

                <property name="title">"CanCam"</property>
                <initMethod name="addModel">
                        <arg>
                                <component class="org.seasar.remoting.axis.examples.ex05.Model">
                                        <property name="name">"Yuri Ebihara"</property>
                                        <property name="age">25</property>
                                </component>
                        </arg>
                </initMethod>
                <initMethod name="addModel">
                        <arg>
                                <component class="org.seasar.remoting.axis.examples.ex05.Model">
                                        <property name="name">"Naoko Tokuzawa"</property>
                                        <property name="age">20</property>
                                </component>
                        </arg>
                </initMethod>
                <initMethod name="addModel">
                        <arg>
                                <component class="org.seasar.remoting.axis.examples.ex05.Model">
                                        <property name="name">"Asami Usuda"</property>
                                        <property name="age">20</property>
                                </component>
                        </arg>
                </initMethod>
        </component>
</components>

クライアント側はWSDLから生成されたスタブを使用する静的呼び出しになっています.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
        "http://www.seasar.org/dtd/components21.dtd">
<components>
        <component name="locator" 
                class="org.seasar.remoting.axis.examples.ex05.MagazineServiceLocator"
        />

        <component class="org.seasar.remoting.axis.examples.ex05.Magazine">
                <!-- locator.getMagazine() -->
                locator.getMagazine(
                    new java.net.URL(locator.getMagazineAddress() + 
                        locator.getMagazineWSDDServiceName()))
        </component>
</components>

ex06 ハンドラのインスタンス管理をS2で行う

S2でインスタンス管理するハンドラをサービスのリクエストチェーンおよびレスポンスチェーンとして使用するサンプルです.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
        "http://www.seasar.org/dtd/components21.dtd">
<components>
        <component name="Foo" class="org.seasar.remoting.axis.examples.ex06.FooSoapBindingImpl">
                <meta name="s2axis:service">"org/seasar/remoting/axis/examples/ex06/deploy.wsdd"</meta>
        </component>

        <component name="fooRequestHandler" class="org.seasar.remoting.axis.examples.ex06.LoggingHandler">
                <meta name="s2-axis:handler"/>

                <property name="message">"Enter Foo"</property>
        </component>

        <component name="fooResponseHandler" class="org.seasar.remoting.axis.examples.ex06.LoggingHandler">
                <meta name="s2-axis:handler"/>

                <property name="message">"Exit Foo"</property>
        </component>
</components>

このハンドラを使用するため,WSDL2Javaが生成したWSDDにリクエストフローおよびレスポンスフローの記述を追加しています.

<!-- Use this file to deploy some handlers/chains and services      -->
<!-- Two ways to do this:                                           -->
<!--   java org.apache.axis.client.AdminClient deploy.wsdd          -->
<!--      after the axis server is running                          -->
<!-- or                                                             -->
<!--   java org.apache.axis.utils.Admin client|server deploy.wsdd   -->
<!--      from the same directory that the Axis engine runs         -->

<deployment
    xmlns="http://xml.apache.org/axis/wsdd/"
    xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

  <!-- Services from FooService WSDL service -->

  <service name="Foo" provider="java:RPC" style="rpc" use="encoded">
      <parameter name="wsdlTargetNamespace" value="http://ex06.examples.axis.remoting.seasar.org"/>
      <parameter name="wsdlServiceElement" value="FooService"/>
      <parameter name="wsdlServicePort" value="Foo"/>
      <parameter name="className" value="org.seasar.remoting.axis.examples.ex06.FooSoapBindingImpl"/>
      <parameter name="wsdlPortType" value="Foo"/>
      <operation name="ping" qname="operNS:ping"
          xmlns:operNS="http://ex06.examples.axis.remoting.seasar.org" soapAction=""
      >
      </operation>
      <parameter name="allowedMethods" value="ping"/>

      <requestFlow>
          <handler type="fooRequestHandler"/>
      </requestFlow>
      <responseFlow>
          <handler type="fooResponseHandler"/>
      </responseFlow>
  </service>
</deployment>

ex07 WSDDをS2Axisでデプロイする

このサンプルでは,Axisが標準で提供するEchoHandlerをプロバイダとするサービスをWSDDに記述し,デプロイします.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
        "http://www.seasar.org/dtd/components21.dtd">
<components>
        <meta name="s2-axis:deploy">"org/seasar/remoting/axis/examples/ex07/deploy.wsdd"</meta>
</components>

デプロイされるWSDDは次のようになっています.

<deployment
    xmlns="http://xml.apache.org/axis/wsdd/"
    xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

    <service name="EchoHandler" provider="Handler" style="rpc" use="encoded">
        <parameter name="handlerClass" value="org.apache.axis.handlers.EchoHandler"/>
    </service>
</deployment>

WSDDに記述されているEchoHandlerのインスタンス管理にS2およびS2Axisは関与しません.単にデプロイするだけです.

ex08 クライアントにハンドラとWSDDをデプロイする

このサンプルでは,diconファイルに記述したハンドラおよび,WSDDファイルをデプロイします.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
        "http://www.seasar.org/dtd/components21.dtd">
<components>
    <include path="s2-axis.dicon"/>

    <component name="remoting" class="org.seasar.remoting.client.interceptors.RemotingInterceptor"/>

    <component class="org.apache.axis.client.Service"/>

    <component name="connector" class="org.seasar.remoting.axis.connector.AxisConnector">
        <property name="baseURL">
            "http://localhost:8080/s2-axis-examples/services/"
        </property>
    </component>

    <component class="org.seasar.remoting.axis.examples.ex01.Echo">
        <aspect>remoting</aspect>
    </component>
    
    <component name="countHandler" class="org.seasar.remoting.axis.examples.ex08.CountHandler">
        <meta name="s2-axis:handler"/>
    </component>

    <meta name="s2-axis:deploy">"org/seasar/remoting/axis/examples/ex08/deploy.wsdd"</meta>
</components>

デプロイされるWSDDは次のようになっています.

<deployment
    xmlns="http://xml.apache.org/axis/wsdd/"
    xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
    <globalConfiguration>
         <requestFlow>
             <handler type="countHandler"/>
         </requestFlow>
         <responseFlow>
             <handler type="countHandler"/>
         </responseFlow>
     </globalConfiguration>
</deployment>

WSDDに記述されているcountHandlerのインスタンス管理はS2によって行われます.