Axisを使う場合,アプリケーション独自のJavaBeansなど,JAX-RPCで定められていない型をサービスの引数や戻り値として使う場合には <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>
WebサービスのWSDLがあり,AxisのWSDL2Javaを使用してJavaの実装クラスを作成した場合には,WSDL2Javaが生成した <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型とのタイプマッピングが クライアント側の設定S2Axisを使うことで,Webサービスをコンポーネントとして使用することが出来ます. 動的呼び出しJavaインタフェースを使用してサービスを呼び出すには,diconファイルを次のように記述します. <!-- リモート呼び出しのインターセプタ -->
<component name="remoting" class="org.seasar.remoting.common.interceptor.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>
静的呼び出し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により生成されるクラスです.このクラスのメソッド クライアント/サーバ共通の設定
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 内容 | 意味 |
|---|---|
| (指定なし) | "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パッケージ
単純なクラスを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.common.interceptor.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の実装クラス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)メソッドが含まれることを確認することが出来ます.
このサンプルでは,サービスは引数および戻り値の型としてJavaBeansを使用しています.しかし,クライアント・サーバ側ともS2Axisが自動的にタイプマッピングを登録するため,特に何も指定しなくても動作します.
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属性の値を singletonやprototypeに変更すると,このサンプルは正しく動作しなくなります (テストケースであるクライアントが失敗します).
セッションスコープを使う場合,クライアント側ではセッショントラッキングを有効にする必要があります.
<?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.common.interceptor.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にすると,このサンプルは正しく動作しなくなります.
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>
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>
このサンプルでは,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は関与しません.単にデプロイするだけです.
このサンプルでは,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.common.interceptor.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によって行われます.