Axis1.4之定制发布服务

时间:2021-02-23 16:13:23

将axis1.4_home\webapps目录下的axis文件夹拷贝到tomcat_home\webapps目录下。然后在tomcat_home\webapps\axis\WEB-INF\lib下添加activation-1.1.1.jar和mail-1.4.jar。接着我们写一个带包结构的Java类HelloWSDD.java:

 package com.grubby.webservice;

 public class HelloWSDD
{
public String getName(String name){
return "your name:"+name;
} public int getAge(int age){
return age+10;
}
}

编译并将编译后带包结构的class文件拷贝到tomcat_home\webapps\axis\WEB-INF\classes目录下。

然后在tomcat_home\webapps\axis\WEB-INF目录下写一个deploy.wsdd文件,代码如下:

 <deployment name="test" xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <service name="HelloWSDD" provider="java:RPC">
<parameter name="className" value="com.grubby.webservice.HelloWSDD" />
<parameter name="allowedMethods" value="*" />
</service> </deployment>

接着启动tomcat,然后:

Axis1.4之定制发布服务

这样就在deploy.wsdd的同级目录下生成了一个叫server-config.wsdd的文件:

 <?xml version="1.0" encoding="UTF-8"?>

 <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<globalConfiguration>
<parameter name="sendMultiRefs" value="true"/>
<parameter name="disablePrettyXML" value="true"/>
<parameter name="adminPassword" value="admin"/>
<parameter name="attachments.Directory" value="D:\apache-tomcat-6.0.44\webapps\axis\WEB-INF\attachments"/>
<parameter name="dotNetSoapEncFix" value="true"/>
<parameter name="enableNamespacePrefixOptimization" value="false"/>
<parameter name="sendXMLDeclaration" value="true"/>
<parameter name="sendXsiTypes" value="true"/>
<parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>
<requestFlow>
<handler type="java:org.apache.axis.handlers.JWSHandler">
<parameter name="scope" value="session"/>
</handler>
<handler type="java:org.apache.axis.handlers.JWSHandler">
<parameter name="scope" value="request"/>
<parameter name="extension" value=".jwr"/>
</handler>
</requestFlow>
</globalConfiguration>
<handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/>
<handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/>
<handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>
<service name="HelloWSDD" provider="java:RPC">
<parameter name="allowedMethods" value="*"/>
<parameter name="className" value="com.grubby.webservice.HelloWSDD"/>
</service>
<service name="AdminService" provider="java:MSG">
<parameter name="allowedMethods" value="AdminService"/>
<parameter name="enableRemoteAdmin" value="false"/>
<parameter name="className" value="org.apache.axis.utils.Admin"/>
<namespace>http://xml.apache.org/axis/wsdd/</namespace>
</service>
<service name="Version" provider="java:RPC">
<parameter name="allowedMethods" value="getVersion"/>
<parameter name="className" value="org.apache.axis.Version"/>
</service>
<transport name="http">
<requestFlow>
<handler type="URLMapper"/>
<handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>
</requestFlow>
<parameter name="qs:list" value="org.apache.axis.transport.http.QSListHandler"/>
<parameter name="qs:wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>
<parameter name="qs.list" value="org.apache.axis.transport.http.QSListHandler"/>
<parameter name="qs.method" value="org.apache.axis.transport.http.QSMethodHandler"/>
<parameter name="qs:method" value="org.apache.axis.transport.http.QSMethodHandler"/>
<parameter name="qs.wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>
</transport>
<transport name="local">
<responseFlow>
<handler type="LocalResponder"/>
</responseFlow>
</transport>
</deployment>

我们在浏览器输入http://localhost:8080/axis/,回车得到页面,点击List链接得到:

Axis1.4之定制发布服务

点击HelloWSDD的wsdl链接:

 <wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://localhost:8080/axis/services/HelloWSDD" xmlns:intf="http://localhost:8080/axis/services/HelloWSDD" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://localhost:8080/axis/services/HelloWSDD">
<!--
WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)
-->
<wsdl:message name="getNameRequest">
<wsdl:part name="in0" type="soapenc:string"/>
</wsdl:message>
<wsdl:message name="getNameResponse">
<wsdl:part name="getNameReturn" type="soapenc:string"/>
</wsdl:message>
<wsdl:message name="getAgeRequest">
<wsdl:part name="in0" type="xsd:int"/>
</wsdl:message>
<wsdl:message name="getAgeResponse">
<wsdl:part name="getAgeReturn" type="xsd:int"/>
</wsdl:message>
<wsdl:portType name="HelloWSDD">
<wsdl:operation name="getName" parameterOrder="in0">
<wsdl:input message="impl:getNameRequest" name="getNameRequest"/>
<wsdl:output message="impl:getNameResponse" name="getNameResponse"/>
</wsdl:operation>
<wsdl:operation name="getAge" parameterOrder="in0">
<wsdl:input message="impl:getAgeRequest" name="getAgeRequest"/>
<wsdl:output message="impl:getAgeResponse" name="getAgeResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloWSDDSoapBinding" type="impl:HelloWSDD">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getName">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getNameRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservice.grubby.com" use="encoded"/>
</wsdl:input>
<wsdl:output name="getNameResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:8080/axis/services/HelloWSDD" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getAge">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getAgeRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservice.grubby.com" use="encoded"/>
</wsdl:input>
<wsdl:output name="getAgeResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:8080/axis/services/HelloWSDD" use="encoded"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloWSDDService">
<wsdl:port binding="impl:HelloWSDDSoapBinding" name="HelloWSDD">
<wsdlsoap:address location="http://localhost:8080/axis/services/HelloWSDD"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

此时浏览器地址栏变为:http://localhost:8080/axis/services/HelloWSDD?wsdl。

这就完成了发布。下面我们进行测试:

我们新建一个Java工程,加入axis1.4开发包下的jar到工程的类路径。然后写一个测试类Client.java:

 package com.grubby.webservice.client;

 import java.rmi.RemoteException;

 import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException; import org.apache.axis.client.Call;
import org.apache.axis.client.Service; public class Client { public static void main(String[] args) throws ServiceException, RemoteException { String url = "http://localhost:8080/axis/services/HelloWSDD";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(url);
call.setOperationName(new QName(url,"getName"));
String result = (String) call.invoke(new Object[]{"Tom"});
System.out.println(result); }
}

运行后控制台输出:your name:Tom