This is a document for S2Axis-V1.0.1 . Documents for older versions of S2Axis are included in their respective distribution archive file.
S2Axis-Examples demostrates most basic features supported by S2Axis. Source is divided into server side and client side sources. Client source is created as JUnit (S2Unit) test case. Source codes files are in the following directories:
- Server side
org.seasar.axis.examples.exnn package in src/server directory
- Client side
org.seasar.axis.examples.exnn package in src/client directory
Sample to release a simple web service <?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="axis-service"/>
</component>
</components>
Client side is call dynamically.
<?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>
When implementation class is released, unnecessary methods may also become released. For example, interfaces that were not implemented or when several interfaces are implemented. In ex02, implemented class HelloImpl implements two interfaces, but setMessage(String) method in MessageSettable is not released as a web service. In this situation, Java interface to become available is made public. (If only one interface is implemented or if all implemented interfaces are to be released, it is not necessary to specify as in this sample.)
<?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="axis-service">
<component class="org.seasar.remoting.axis.server.ServiceDef">
<property name="serviceType">
@org.seasar.remoting.axis.examples.ex02.Hello@class
</property>
</component>
</meta>
<property name="message">"Hello"</property>
</component>
</components>
Comment out <property> element and restart the web container. WSDL for Hello should contain にsetServiceType(String) method.
In this sample, argument and return value data type of a service is a JavaBean. Nevertheless, type mapping are done automatically at both client side and server side.
Axis has a proprietary session scope service that uses HTTP session. When session scope service is used in S2Axis, service life cycle management is doen by 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="axis-service"/>
</component>
</components>
This sample will not properly work if value of instance attribute is changed tosingleton or prototype (client will error.)
When session scope is to be used, session tracking must be made effective at the client.
<?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>
The sample will not work properly if value of maintainSession attribute is set to false .
This is a sample created using WSDL2Java to generated Java stubs and a skelton. WSDD file generated by WSDL2Java is specified.
<?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="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>
On the client side, static stub generated from WSDL is called. <?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>
This sample, handler instance managed by S2 is used in service request chain and response chain.
<?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="axis-service">
"org/seasar/remoting/axis/examples/ex06/deploy.wsdd"
</meta>
</component>
<component name="fooRequestHandler"
class="org.seasar.remoting.axis.examples.ex06.LoggingHandler">
<meta name="axis-handler"/>
<property name="message">"Enter Foo"</property>
</component>
<component name="fooResponseHandler"
class="org.seasar.remoting.axis.examples.ex06.LoggingHandler">
<meta name="axis-handler"/>
<property name="message">"Exit Foo"</property>
</component>
</components>
To use this handler, request flow and response flow are inserted into WSDD generated by WSDL2Java.
<!-- 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>
When client software is executed, following message is displayed at the server. [DEBUG] http-8080-Processor24 org.seasar.remoting.axis.examples.ex06.LoggingHandler
Enter Foo
[DEBUG] http-8080-Processor24 org.seasar.remoting.axis.examples.ex06.LoggingHandler
Exit Foo
In this sample, EchoHandler , which comes as a sample in Axis, will be added in WSDD as a provider service and then deployed. <?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="axis-deploy
">"org/seasar/remoting/axis/examples/ex07/deploy.wsdd"
</meta>
</components>
The difference between ex05 is <components> element is used instead of <component> . WSDD that is deployed is as follows: <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>
S2 and S2Axis do not manage EchoHandler instance written in WSDD. They only take part in deployment.
In this sample, handler and WSDD file specified in dicon file will be deployed.
<?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="axis-handler"/>
</component>
<meta name="axis-deploy">
"org/seasar/remoting/axis/examples/ex08/deploy.wsdd"
</meta>
</components>
Deployed WSDD is as follows: <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>
Management of countHandler instance specified in WSDD is done by S2.
|