Axis1.4之定制发布服务

将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:

 1 package com.grubby.webservice;
 2 
 3 public class HelloWSDD
 4 {
 5     public String getName(String name){
 6         return "your name:"+name;
 7     }
 8 
 9     public int getAge(int age){
10         return age+10;
11     }
12 }

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

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

1 <deployment name="test" xmlns="http://xml.apache.org/axis/wsdd/" 
2     xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
3 
4   <service name="HelloWSDD" provider="java:RPC">
5     <parameter name="className" value="com.grubby.webservice.HelloWSDD" />
6     <parameter name="allowedMethods" value="*" />
7   </service>
8 
9 </deployment>

接着启动tomcat,然后:

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

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 
 3 <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
 4  <globalConfiguration>
 5   <parameter name="sendMultiRefs" value="true"/>
 6   <parameter name="disablePrettyXML" value="true"/>
 7   <parameter name="adminPassword" value="admin"/>
 8   <parameter name="attachments.Directory" value="D:\apache-tomcat-6.0.44\webapps\axis\WEB-INF\attachments"/>
 9   <parameter name="dotNetSoapEncFix" value="true"/>
10   <parameter name="enableNamespacePrefixOptimization" value="false"/>
11   <parameter name="sendXMLDeclaration" value="true"/>
12   <parameter name="sendXsiTypes" value="true"/>
13   <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>
14   <requestFlow>
15    <handler type="java:org.apache.axis.handlers.JWSHandler">
16     <parameter name="scope" value="session"/>
17    </handler>
18    <handler type="java:org.apache.axis.handlers.JWSHandler">
19     <parameter name="scope" value="request"/>
20     <parameter name="extension" value=".jwr"/>
21    </handler>
22   </requestFlow>
23  </globalConfiguration>
24  <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/>
25  <handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/>
26  <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>
27  <service name="HelloWSDD" provider="java:RPC">
28   <parameter name="allowedMethods" value="*"/>
29   <parameter name="className" value="com.grubby.webservice.HelloWSDD"/>
30  </service>
31  <service name="AdminService" provider="java:MSG">
32   <parameter name="allowedMethods" value="AdminService"/>
33   <parameter name="enableRemoteAdmin" value="false"/>
34   <parameter name="className" value="org.apache.axis.utils.Admin"/>
35   <namespace>http://xml.apache.org/axis/wsdd/</namespace>
36  </service>
37  <service name="Version" provider="java:RPC">
38   <parameter name="allowedMethods" value="getVersion"/>
39   <parameter name="className" value="org.apache.axis.Version"/>
40  </service>
41  <transport name="http">
42   <requestFlow>
43    <handler type="URLMapper"/>
44    <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>
45   </requestFlow>
46   <parameter name="qs:list" value="org.apache.axis.transport.http.QSListHandler"/>
47   <parameter name="qs:wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>
48   <parameter name="qs.list" value="org.apache.axis.transport.http.QSListHandler"/>
49   <parameter name="qs.method" value="org.apache.axis.transport.http.QSMethodHandler"/>
50   <parameter name="qs:method" value="org.apache.axis.transport.http.QSMethodHandler"/>
51   <parameter name="qs.wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>
52  </transport>
53  <transport name="local">
54   <responseFlow>
55    <handler type="LocalResponder"/>
56   </responseFlow>
57  </transport>
58 </deployment>

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

点击HelloWSDD的wsdl链接:

 1 <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">
 2 <!--
 3 WSDL created by Apache Axis version: 1.4
 4 Built on Apr 22, 2006 (06:55:48 PDT)
 5 -->
 6 <wsdl:message name="getNameRequest">
 7 <wsdl:part name="in0" type="soapenc:string"/>
 8 </wsdl:message>
 9 <wsdl:message name="getNameResponse">
10 <wsdl:part name="getNameReturn" type="soapenc:string"/>
11 </wsdl:message>
12 <wsdl:message name="getAgeRequest">
13 <wsdl:part name="in0" type="xsd:int"/>
14 </wsdl:message>
15 <wsdl:message name="getAgeResponse">
16 <wsdl:part name="getAgeReturn" type="xsd:int"/>
17 </wsdl:message>
18 <wsdl:portType name="HelloWSDD">
19 <wsdl:operation name="getName" parameterOrder="in0">
20 <wsdl:input message="impl:getNameRequest" name="getNameRequest"/>
21 <wsdl:output message="impl:getNameResponse" name="getNameResponse"/>
22 </wsdl:operation>
23 <wsdl:operation name="getAge" parameterOrder="in0">
24 <wsdl:input message="impl:getAgeRequest" name="getAgeRequest"/>
25 <wsdl:output message="impl:getAgeResponse" name="getAgeResponse"/>
26 </wsdl:operation>
27 </wsdl:portType>
28 <wsdl:binding name="HelloWSDDSoapBinding" type="impl:HelloWSDD">
29 <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
30 <wsdl:operation name="getName">
31 <wsdlsoap:operation soapAction=""/>
32 <wsdl:input name="getNameRequest">
33 <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservice.grubby.com" use="encoded"/>
34 </wsdl:input>
35 <wsdl:output name="getNameResponse">
36 <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:8080/axis/services/HelloWSDD" use="encoded"/>
37 </wsdl:output>
38 </wsdl:operation>
39 <wsdl:operation name="getAge">
40 <wsdlsoap:operation soapAction=""/>
41 <wsdl:input name="getAgeRequest">
42 <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservice.grubby.com" use="encoded"/>
43 </wsdl:input>
44 <wsdl:output name="getAgeResponse">
45 <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:8080/axis/services/HelloWSDD" use="encoded"/>
46 </wsdl:output>
47 </wsdl:operation>
48 </wsdl:binding>
49 <wsdl:service name="HelloWSDDService">
50 <wsdl:port binding="impl:HelloWSDDSoapBinding" name="HelloWSDD">
51 <wsdlsoap:address location="http://localhost:8080/axis/services/HelloWSDD"/>
52 </wsdl:port>
53 </wsdl:service>
54 </wsdl:definitions>

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

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

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

 1 package com.grubby.webservice.client;
 2 
 3 import java.rmi.RemoteException;
 4 
 5 import javax.xml.namespace.QName;
 6 import javax.xml.rpc.ServiceException;
 7 
 8 import org.apache.axis.client.Call;
 9 import org.apache.axis.client.Service;
10 
11 public class Client {
12 
13     public static void main(String[] args) throws ServiceException, RemoteException {
14         
15         String url = "http://localhost:8080/axis/services/HelloWSDD";
16         Service service = new Service();
17         Call call = (Call) service.createCall();
18         call.setTargetEndpointAddress(url);
19         call.setOperationName(new QName(url,"getName"));
20         String result = (String) call.invoke(new Object[]{"Tom"});
21         System.out.println(result);
22         
23     }
24 }

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

 

posted on 2015-11-01 19:02  confirmCname  阅读(523)  评论(0编辑  收藏  举报

导航