First, Soapin Axis2
In the first two days of the tutorial, we learned how to use AXIS2 to carry out complex data, simple data transmission.
As I said in the previous tutorial, in the world of Web service, everything is soap based, so today we will learn the soap features in Axis2.
Today's course will be completed with 3 examples:
1 The client communicates with the server using SOAP
2) service side will exception to the client in the form of SoapFault
3) using SWA (Soap with attachment) for attachment transfer
Second, client and server use SOAP for communication
Look at the following Web Service:
The following is the source of the service end
Org.sky.axis2.soap.SoapService
Package org.sky.axis2.soap;
Import Org.apache.axiom.om.OMAbstractFactory;
Import org.apache.axiom.om.OMElement;
Import Org.apache.axiom.om.OMFactory;
Import Org.apache.axiom.om.OMNamespace;
Import java.util.*;
public class Soapservice {
public static omelement requestsoap = null;
Public omelement request (Omelement soapbody) {
Requestsoap = Soapbody;
Iterator it = requestsoap.getchildelements ();
Omelement issuerelement = (omelement) it.next ();
Omelement serialelement = (omelement) it.next ();
Omelement revocationdateelement = (omelement) it.next ();
String issuer = Issuerelement.gettext ();
String serial = Serialelement.gettext ();
String revocationdate = Revocationdateelement.gettext ();
System.out.println ("issuer=====" + issuer);
System.out.println ("serial=====" + serial);
System.out.println ("revocationdate=====" + revocationdate);
Omfactory soapfactory = Omabstractfactory.getomfactory ();
Omnamespace omns = Soapfactory.createomnamespace (
"Http://soap.axis2.sky.org", "" ");
Omelement soapresponse = soapfactory.createomelement ("Soapresponse",
Omns);
omelement Soapissuer = soapfactory.createomelement ("Issuer", omns);
soapissuer.settext ("Issuer:" + issuer);
Soapresponse.addchild (soapissuer);
omelement soapserial = soapfactory.createomelement ("Serial", omns);
Soapserial.settext ("Serial:" + serial);
Soapresponse.addchild (soapserial);
omelement soaprevokedate = soapfactory.createomelement ("Revokedate",
omns);
Soaprevokedate.settext ("revocationdate:" + revocationdate);
Soapresponse.addchild (soaprevokedate);
soapresponse.build ();
return soapresponse;
}
}