spring + axis2 开发webservice

项目包结构:jar包之类的直接copy进去,重复的去掉。
spring + axis2 开发webservice - java_jian - java_jian的博客

service.xml的配置(注意结构)
<?xml version="1.0" encoding="UTF-8"?>
<serviceGroup>   
    <service name="AllWebService">   
        <description>logisticsAllWebServiceInterface:Spring POJO Axis2 Service Sample</description>   
         <parameter name="ServiceClass">com.zsxh.logistics.service.webservice.AllService</parameter>   //接口类
        <parameter name="ServiceObjectSupplier">   
            org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier    
        </parameter>   
         <parameter name="SpringBeanName">allWebService</parameter>    // spring管理的类的id。
        <messageReceivers>   
            <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"   
                class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />   
        </messageReceivers>   
    </service>   
</serviceGroup> 

 axis2-web文件夹下面listServices.jsp

<%@     
page contentType="text/html;charset=UTF-8" language="java"     
%><%@    
page import="org.apache.axis2.Constants,    
            org.apache.axis2.description.AxisOperation,    
            org.apache.axis2.description.AxisService,    
            java.util.Collection,    
            java.util.HashMap,    
            java.util.Iterator"     
%><html>    
<head><title>List Services</title>    
<style>    
h2{margin:20 0 5 0;}    
ul{margin-top:5;}    
</style>    
</head>    
<body>    
<h1>Available services</h1>    
<%    
    HashMap serviceMap = (HashMap) request.getSession().getAttribute(Constants.SERVICE_MAP);            
    Collection servicecol = serviceMap.values();    
    if(servicecol.size()==0){%>Available services is Empty.<%}    
    for (Iterator iterator = servicecol.iterator(); iterator.hasNext();) {    
        AxisService axisService = (AxisService) iterator.next();    
        Iterator opItr = axisService.getOperations();    
        String serviceName = axisService.getName();    
%>    
   
<h2><font color="blue"><a href="<%=serviceName %>?wsdl" target="_blank"><%=serviceName%></a></font></h2>    
<i>Available Operations</i>    
<ul>    
<%    
while (opItr.hasNext()) {    
    AxisOperation axisOperation = (AxisOperation) opItr.next();    
    %><li><%=axisOperation.getName().getLocalPart()%></li><%    
}    
%>    
</ul>    
<%    
    }    
%>    
</body>    
</html>

web。xml增加
<!-- axis2 servlet begin -->
<servlet>
   <display-name>Apache-Axis2</display-name>
        <servlet-name>AxisServlet</servlet-name>
        <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
访问:http://***:**/**/services/listServices能看到你的项目中有什么webservice接口。

String address = "http://localhost:8888/logistics/services/AllWebService";
EndpointReference target = new EndpointReference(address);
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
options.setTo(target);
// 扫描流水号
// QName opGetWeather = new QName("http://****","cgInfo");
//
// Object[] opGetWeatherArgs = new Object[]{"c001g00120100728100001"};
// Class[] returnType = new Class[]{CGInfo.class};
// Object[] response = serviceClient.invokeBlocking(opGetWeather, opGetWeatherArgs, returnType);
// CGInfo ret = (CGInfo) response[0];
// if(ret == null){
// System.out.println(" has no record");
// }else{
// System.out.println(ret.getClient());
// System.out.println(ret.getGoodsName());
// System.out.println(ret.getSpec());
// System.out.println(ret.getBatchNum());
// System.out.println(ret.getOddNum());
// }
如何调用webservice接口做测试。

你可能感兴趣的:(apache,spring,xml,servlet,webservice)