First, download the jar package
axis2-1.6.3 Download:
Download Address: http://axis.apache.org/axis2/java/core/download.cgi,
Download Axis2-1.6.3-bin.zip, this package contains all the Axis2 jar
spring3.1.4 download I'm going to cut the crap.
Second, create the integration project and release the test
1. In the well-built spring MVC framework, introduce the Axis2 jar
2. Create a Services folder under Web-inf, the name must be services, other unrecognized, in services must create another folder (name by the way, for example: MyService), create a folder under MyService, Name must be Meta-inf, under Meta-inf create Services.xml file and an empty servicedata.xml, this name is also unchanged.
The last path is the Web-inf/services/myservice/meta-inf/services.xml Services.xml code as follows:
<?xml version= "1.0" encoding= "UTF-8"?>
<!--access to the address that WebService's name--<service name=
" Testwsservice ">
<description>spring Integration Example </description>
<parameter name=" Serviceobjectsupplier ">
org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier
</parameter>
<!--Configure the bean configured in ApplicationContext, where the ID in the value domain bean is the same, or else the error cannot find the bean wrong
-- <parameter name= "Springbeanname" >testWSService</parameter>
<messageReceivers>
< Messagereceiver mep= "Http://www.w3.org/2004/08/wsdl/in-out"
class= " Org.apache.axis2.rpc.receivers.RPCMessageReceiver "/>
<messagereceiver mep=" http://www.w3.org/2004/08 /wsdl/in-only "
class=" Org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver "/>
</ Messagereceivers>
</service>
The final directory Web-inf/services/myservice/meta-inf/servicedata.xmlservicedata.xml code is as follows:
<?xml version= "1.0" encoding= "UTF-8"?>
<ServiceData>
</ServiceData>
Third, add the following information in Web. xml
<!--Axis2 WebService configuration information Start-up
<servlet>
<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>
<!--axis2 WebService configuration information Ends--
Iv. injecting a quoted service into the Applicationcontext.xml
<bean id= "Testwsservice" class= "Com.usi.jrtx.service.webservice.TestWSService" ></bean>
V.. testwsservice.java file
package Com.usi.jrtx.service.webservice;
Import java.util.List;
Import org.springframework.beans.factory.annotation.Autowired;
Import Com.github.miemiedev.mybatis.paginator.domain.Order;
Import Com.github.miemiedev.mybatis.paginator.domain.PageBounds;
Import Com.usi.jrtx.dao.account.AccountMapper;
Import Com.usi.jrtx.model.account.Account;
public class Testwsservice {@Autowired private accountmapper accountmapper;
/** * Calculate minus method D1-d2 */Public integer JIANFA (integer d1, integer d2) {return d1-d2; }/** * Compute addition */public integer JIAFA (integer d1, integer d2) {pagebounds pagebounds = new PageBounds (1,1000,orde
R.formstring ("Id.desc"));
Account account=new account ();
List<account> list=accountmapper.queryaccounts (account, pagebounds);
System.out.println ("Receiving D1:" +D1);
System.out.println ("Receiving D2:" +D2);
for (int i = 0; i < list.size (); i++) {System.out.println ("account Name:" +list.get (i). Getaccountname ());
} return D1+D2; }
}
Vi. Use of clients
Package com.usi.jrtx.webservice;
Import java.util.ArrayList;
Import java.util.List;
Import Java.util.Random;
Import Javax.xml.namespace.QName;
Import org.apache.axiom.om.OMElement;
Import Org.apache.axis2.AxisFault;
Import org.apache.axis2.addressing.EndpointReference;
Import org.apache.axis2.client.Options;
Import org.apache.axis2.rpc.client.RPCServiceClient;
Import com.usi.jrtx.model.soap.AccountVO81010;
Import Com.usi.jrtx.model.soap.ConsumeDetail;
Import com.usi.jrtx.model.soap.ConsumeVO88010;
Import Com.usi.jrwl.util.XMLDomUtil; public class WebServiceTest {/** * Test * @throws Exception */public static void my () throws Exception {String
url = "HTTP://192.168.20.34:8080/JRTXMANAGER/SERVICES/TESTWSSERVICE?WSDL";
try {//use RPC to call WebService rpcserviceclient serviceclient = new Rpcserviceclient ();
Specifies the URL to call WebService endpointreference Targetepr = new EndpointReference (URL);
Options options = Serviceclient.getoptions (); Determine the destination service address OPTIONS.SEtto (TARGETEPR);
Determine the Calling method Options.setaction ("Urn:jiafa");
Options.settimeoutinmilliseconds (60000);
QName QName = new QName ("http://webservice.service.jrtx.usi.com", "Jiafa");
Specifies the parameter value of the Jiafa method String requestcontent = "";
try {} catch (Exception e) {throw new Exception (E.getmessage (), E.getcause ());
} object[] Parameters = new object[] {5,9};
Class object specifying the data type of the GetPrice method return value class[] returntypes = new class[] {string.class};
Call a method to pass a parameter, invoke the service, get the service to return the result set omelement element = Serviceclient.invokeblocking (QName, parameters);
It is worth noting that the returned result is an XML string encapsulated by the Omelement object.
String result = Element.getfirstelement (). GetText ();
SYSTEM.OUT.PRINTLN (result);
} catch (Axisfault e) {e.printstacktrace ();
}} public static void Main (string[] args) throws Exception {my ();
}
}
Vii. Summary: It is that simple.