The path to the architect 12th Day Axis2 Web Service (iii)

Source: Internet
Author: User
Tags addchild gettext soap

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;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.