Monday, January 3, 2011

Develop Web Service With Axis2 #2 - Work on Skeleton Code

Prev >>> Develop Web Service With Axis2 #1 - Start From Generating WSDL File

1. generate skeleton code based on WSDL file

WSDL2Java Reference

go to %testaxis1_folder% to run this command:

wsdl2java -uri resource\UserServices.wsdl -ss -sd -d adb -S .\src
-R .\resource\META-INF -ssi -p com.test.axis.ws.skeleton
-ns2p http://bean.axis.test.com/xsd=com.test.axis.ws.bean.xsd,http://axis.test.com/ws=com.test.axis.ws.bean

then, you will find
* all generated skeleton source code under this package com.test.axis.ws
* ant build file auto generated
* resource\META-INFO\services.xml and resource\META-INF\UserServices.wsdl

2. put all axis2 related jar files into your project build path.

3. complete your business logic in the skeleton class.

4. run task 'jar.server[default]' in the auto-generated build.xml,
then you can get UserServices.aar under folder %testaxis1_folder%\build\lib

5. deploy the aar file.

5.1 download axis2 war distribution.
5.2 deploy the war file to tomcat.
5.3 copy the aar file to %tomcat%\webapps\axis2\WEB-INF\services
or unzip the aar file and put the whole unzipped folder to %tomcat%\webapps\axis2\WEB-INF\services

6. write a client to call or use a tools to call the first method,you will see this response.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
          <soapenv:Fault>
                  <faultcode>soapenv:Server</faultcode>
                  <faultstring>Please implement  com.test.axis.ws.skeleton.UserServicesSkeleton#getUserInfo</faultstring>
                  <detail />
          </soapenv:Fault>
     </soapenv:Body>
</soapenv:Envelope>

=====================================
Consideration:

a> POJO style web service
http://axis.apache.org/axis2/java/core/docs/pojoguide.html

If your web service is very simple, not necessary to consider customized soap headers and fault, message level security,etc. POJO style web service is a nice choice.

b> JAX-WS style web serivce
http://axis.apache.org/axis2/java/core/docs/jaxws-guide.html

Both Axis2 and Metro support jax-ws API,which use annotation-based model to develop web service.
It seems current Axis2 is not ready to support WS-Security fully for JAX-WS, so I leave it aside first.

c> Data Binding
http://axis.apache.org/axis2/java/core/docs/adb/adb-howto.html

ADB is the data binding approach Axis2 suggests. The other ways are xmlbeans,jixb and jaxbri.

The skeleton and stub code will be different if you select different data binding as they adopt different approach to convert XML data to an object, or vice verse.

No comments:

Post a Comment