This is an example of development a web service using Axis2 + Tomcat.
Step 1. define you web service (WSDL) using Netbeans 6.x
Here I define 2 wsdl files, Proxy.wsdl, and Concat wsdl.
Concat has this interface some like: String concat(String str, int sleepSecond) {
sleep(sleepSecond); // sleep
return str+str; // return concat
}
Proxy will call concat, it has this interface some like: String Proxy(String address, String str, int sleepSecond) {
ConcatStub stub = new ConcatStub(address);
return stub(str,sleepSecond);
}
-- Put Proxy.wsdl here
bjbld10{/vobs/isg/wsgw/pxgw22/service/jspa/interfaces/wsdl}:cat Proxy.wsdl
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://proxy.service.hui.com" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:ns0="http://proxy.service.hui.com" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="unqualified" targetNamespace="http://proxy.service.hui.com" xmlns:ns="http://proxy.service.hui.com">
<xs:element name="proxyRequest">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="address" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="value" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="sleep" nillable="true" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="proxyResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="proxyResponse">
<wsdl:part name="parameters" element="ns0:proxyResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="proxyRequest">
<wsdl:part name="parameters" element="ns0:proxyRequest">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="ProxyPortType">
<wsdl:operation name="proxy">
<wsdl:input message="ns0:proxyRequest" wsaw:Action="urn:proxyRequest">
</wsdl:input>
<wsdl:output message="ns0:proxyResponse" wsaw:Action="urn:proxyResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ProxySOAP12Binding" type="ns0:ProxyPortType">
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="proxy">
<soap12:operation soapAction="urn:proxy" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="ProxySOAP11Binding" type="ns0:ProxyPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="proxy">
<soap:operation soapAction="urn:proxy" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="ProxyHttpBinding" type="ns0:ProxyPortType">
<http:binding verb="POST"/>
<wsdl:operation name="proxy">
<http:operation location="Proxy/proxy"/>
<wsdl:input>
<mime:content part="proxy" type="text/xml"/>
</wsdl:input>
<wsdl:output>
<mime:content part="proxy" type="text/xml"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Proxy">
<wsdl:port name="ProxySOAP11port_http" binding="ns0:ProxySOAP11Binding">
<soap:address location="http://localhost:8080/soap/Proxy"/>
</wsdl:port>
<wsdl:port name="ProxySOAP12port_http" binding="ns0:ProxySOAP12Binding">
<soap12:address location="http://localhost:8080/soap/Proxy"/>
</wsdl:port>
<wsdl:port name="ProxyHttpport" binding="ns0:ProxyHttpBinding">
<http:address location="http://localhost:8080/soap/Proxy"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
2.1 modify ConcatSkeleton.java
public com.hui.service.concat.ConcatResponse concat(
com.hui.service.concat.ConcatRequest concatRequest0) {
//TODO : fill this with the necessary business logic
com.hui.service.concat.ConcatResponse response =
new com.hui.service.concat.ConcatResponse();
String param = concatRequest0.getValue();
response.set_return(param+param);
int sleep = concatRequest0.getSleep();
try {
Thread.sleep(sleep*1000);
} catch (InterruptedException e) {
}
return response;
//throw new java.lang.UnsupportedOperationException("Please implement " +
// this.getClass().getName() + "#concat");
}
2.2 Modify ProxySkeleton.java
public com.hui.service.proxy.ProxyResponse proxy(
com.hui.service.proxy.ProxyRequest proxyRequest0) {
//TODO : fill this with the necessary business logic
String address = proxyRequest0.getAddress();
String value = proxyRequest0.getValue();
int sleep = proxyRequest0.getSleep();
com.hui.service.proxy.ConcatStub.ConcatRequest concatRequest =
new com.hui.service.proxy.ConcatStub.ConcatRequest();
com.hui.service.proxy.ConcatStub.ConcatResponse concatResponse =
new com.hui.service.proxy.ConcatStub.ConcatResponse();
concatRequest.setValue(value);
concatRequest.setSleep(sleep);
com.hui.service.proxy.ConcatStub stub = null;
try {
stub = new com.hui.service.proxy.ConcatStub(address);
} catch (org.apache.axis2.AxisFault e) {
//TODO : fill this with the necessary business logic
}
try {
concatResponse = stub.concat(concatRequest);
} catch (java.rmi.RemoteException e) {
//TODO : fill this with the necessary business logic
}
com.hui.service.proxy.ProxyResponse proxyResponse =
new com.hui.service.proxy.ProxyResponse();
proxyResponse.set_return(concatResponse.get_return());
return proxyResponse;
//throw new java.lang.UnsupportedOperationException("Please implement " +
// this.getClass().getName() + "#proxy");
}
2. Define buildwsdl.xml
#:cat buildwsdl.xml
<project basedir="." default="generate.all">
<property environment="env"/>
<property name="AXIS2_HOME" value="${env.AXIS2_HOME}"/>
<property name="build.dir" value="build"/>
<path id="java.class.path">
<fileset dir="${vendor.dir}/lib/apache">
<include name="*.jar"/>
</fileset>
<fileset dir="${vendor.dir}/lib/uddi4j">
<include name="*.jar"/>
</fileset>
</path>
<path id="axis2.classpath">
<fileset dir="${AXIS2_HOME}/lib">
<include name="*.jar"/>
</fileset>
</path>
<target name="init">
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.dir}/wsgen/proxy"/>
<mkdir dir="${build.dir}/wsgen/concat"/>
</target>
<!--proxy service-->
<target name="generate.service.proxy" depends="init">
<taskdef name="wsdl2java"
classname="org.apache.axis2.tool.ant.AntCodegenTask"
classpathref="axis2.classpath"/>
<wsdl2java wsdlFilename="${basedir}/interfaces/wsdl/Proxy.wsdl"
output="${build.dir}/wsgen/proxy"
packageName="com.hui.service.proxy"
language="java"
databindingName="adb"
synconly="true"
serverside="true"
serverSideInterface="true"
generateservicexml="true"/>
<copy file="${basedir}/interfaces/src/com/hui/service/proxy/ProxySkeleton.java"
toDir="${build.dir}/wsgen/proxy/src/com/hui/service/proxy"
overwrite="yes">
</copy>
<wsdl2java wsdlFilename="${basedir}/interfaces/wsdl/Concat.wsdl"
output="${build.dir}/wsgen/proxy"
packageName="com.hui.service.proxy"
databindingName="adb"
language="java"
synconly="true"/>
<ant dir="${build.dir}/wsgen/proxy" inheritAll="true"/>
<delete dir="${build.dir}/wsgen/proxy/test"/>
<copy file="${build.dir}/wsgen/proxy/build/lib/Proxy.aar"
todir="${lib.dir}"
overwrite="yes">
</copy>
</target>
<!--concat service-->
<target name="generate.service.concat" depends="init">
<taskdef name="wsdl2java"
classname="org.apache.axis2.tool.ant.AntCodegenTask"
classpathref="axis2.classpath"/>
<wsdl2java wsdlFilename="${basedir}/interfaces/wsdl/Concat.wsdl"
output="${build.dir}/wsgen/concat"
packageName="com.hui.service.concat"
language="java"
databindingName="adb"
synconly="true"
serverside="true"
serverSideInterface="true"
generateservicexml="true"/>
<copy file="${basedir}/interfaces/src/com/hui/service/concat/ConcatSkeleton.java"
toDir="${build.dir}/wsgen/concat/src/com/hui/service/concat"
overwrite="yes">
</copy>
<ant dir="${build.dir}/wsgen/concat" inheritAll="true"/>
<delete dir="${build.dir}/wsgen/concat/test"/>
<copy file="${build.dir}/wsgen/concat/build/lib/Concat.aar"
todir="${lib.dir}"
overwrite="yes">
</copy>
</target>
<target name="generate.all" depends="generate.service.proxy,generate.service.concat"/>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
</project>
3. install Tomcat
4. Install Axis2 into tomcat webapps
5. Put .aar file into tomcat axis2 service directory
$TOMCAT_HOME/webapps/axis2/WEB-INF/services
6. restart tomcat
7. Invoke a testing request from soapUI.
本文介绍如何利用Axis2和Tomcat部署WebService。通过定义WSDL文件并使用Netbeans进行辅助开发,实现了一个名为Concat的服务接口和一个代理服务Proxy。详细展示了修改服务骨架代码、配置构建脚本的过程,并提供了部署步骤。
690

被折叠的 条评论
为什么被折叠?



