I hate the tedious WebService framework configuration.
Especially the Axis series
Rage directly with the servlet to develop
It is also very simple, the key is to get to the request soap and response soap, you can use SOAPUI to generate
The use of SOAPUI here does not introduce
The key to generating the request soap and responding to soap is to parse soap.
Directly using the Java-provided API to parse
Parse Request Soap
The code is as follows:
Java code
Public class Syncnotifyspreqdecoder {
Private Static Logger Logger = Loggerfactory.getlogger (syncnotifyspreqdecoder. Class);
Public Static Syncnotifyspreq decode (InputStream in) {
Documentbuilderfactory domfac=documentbuilderfactory.newinstance ();
String Recordsequenceid = "0";
list<yingzhangreceiptbody> itemList = new arraylist<yingzhangreceiptbody> ();
Try {
Documentbuilder Dombuilder=domfac.newdocumentbuilder ();
Document Doc=dombuilder.parse (in);
Element root=doc.getdocumentelement ();
//Parse Recordsequenceid
NodeList recordsequenceidnodelist = Root.getelementsbytagname ("Recordsequenceid");
if (Recordsequenceidnodelist.getlength () >= 1) {
Recordsequenceid = Recordsequenceidnodelist.item (0). Gettextcontent ();
}
//Parse Item
NodeList itemnodelist = root.getelementsbytagname ("item");
for (int i = 0; i < itemnodelist.getlength (); i++) {
Node item = Itemnodelist.item (i);
String Useridtype = Getnodevalue (item, "Useridtype");
String userId = Getnodevalue (item, "UserId");
String Sp_productid = Getnodevalue (item, "Sp_productid");
String Updatetype = Getnodevalue (item, "Updatetype");
//useridtype fill 1 for mobile phone number; Useridtype 2 for pseudo code
if ( "1". Equals (Useridtype)) {
Yingzhangreceiptbody BODY = new yingzhangreceiptbody (Remove86 (userId), Sp_productid, Escapeservicecode ( Updatetype));
Itemlist.add (body);
}
}
} catch (Exception e) {
Logger.error (E.getmessage (), E);
}
return New Syncnotifyspreq (Recordsequenceid, itemList);
}
//Get node Value
Public Static String Getnodevalue (Node item, string nodeName) {
for (Node n=item.getfirstchild (); n! = null; n=n.getnextsibling ()) {
if (N.getnodetype () = = Node.element_node) {
if (N.getnodename (). Equals (NodeName)) {
return n.gettextcontent ();
}
}
}
return null;
}
}
public class syncnotifyspreqdecoder {private static logger logger = Loggerfactory.getlogger (Syncnotifyspreqdecoder.class);p Ublic static syncnotifyspreq decode ( Inputstream in) {documentbuilderfactory domfac=documentbuilderfactory.newinstance (); string recordsequenceid = "0"; List<yingzhangreceiptbody> itemlist = new arraylist<yingzhangreceiptbody> (); Try {documentbuilder dombuilder=domfac.newdocumentbuilder ();D ocument doc=dombuilder.parse (in); Element root=doc.getdocumentelement ();//parsing recordsequenceidnodelist recordsequenceidnodelist = root.getelementsbytagname ("Recordsequenceid"); if (Recordsequenceidnodelist.getlength () >= 1) {recordsequenceid = recordsequenceidnodelist.item (0). Gettextcontent ();} Parse Itemnodelist itemnodelist = root.getelementsbytagname ("item");for (int i = 0; i < itemnodelist.getlength (); i++) {node item = itemnodelist.item (i); String useridtype = getnodevalue (item, "Useridtype"); String userid = getnodevalue (item, "userId"); String sp_productid = getnodevalue (item, "Sp_productid"); String updatetype = getnodevalue (item, "Updatetype")//useridtype fill 1 for mobile phone number ; useridtype fill 2 as pseudo code if ( "1". Equals (Useridtype) ) {yingzhangreceiptbody body = New yingzhangreceiptbody (Remove86 (userId), sp_productid, escapeservicecode (Updatetype)); Itemlist.add (body);}}} catch (exception e) {logger.error (E.getmessage (), e);} Return new syncnotifyspreq (recordsequenceid, itemlist);} Get Node valuepublic static string getnodevalue (Node item, string nodename) {for (Node n=item.getfirstchild (); n != null; n=n.getnextsibling()) {if (N.getnodetype () == node.element_node) {if (N.getnodename (). Equals (NodeName)) {return N.gettextcontent ();}}} Return null;}}
Write Response Soap
Java code
Public class Syncnotifyspresencoder {
/**
* Return SOAP response
* @param recordsequenceid
* @param resultcode 0: success; 1. Failure
*/
Public Static String encode (string recordsequenceid, int resultcode) {
StringBuilder ret = new StringBuilder ("<soapenv:envelope xmlns:xsi=\" http://www.w3.org/2001/ Xmlschema-instance\ "xmlns:xsd=\" http://www.w3.org/2001/xmlschema\ "xmlns:soapenv=\" http://schemas.xmlsoap.org/ Soap/envelope/\ "xmlns:soap=\" http://soap.bossagent.vac.unicom.com\ ">");
Ret.append ("<soapenv:Header/>")
. Append ("<soapenv:Body>")
. Append ("<soap:orderrelationupdatenotifyresponse soapenv:encodingstyle=\" Http://schemas.xmlsoap.org/soap /encoding/\ ">")
. Append ("<orderrelationupdatenotifyreturn xsi:type=\" rsp:orderrelationupdatenotifyresponse\ "xmlns:rsp=\" Http://rsp.sync.soap.bossagent.vac.unicom.com\ ">")
. Append ("<recordsequenceid xsi:type=\" soapenc:string\ "xmlns:soapenc=\" http://schemas.xmlsoap.org/soap/ Encoding/\ ">")
. Append (Recordsequenceid)
. Append ("</recordSequenceId>")
. Append ("<resultcode xsi:type=\" xsd:int\ ">")
. Append (ResultCode)
. Append ("</resultCode>")
. Append ("</orderRelationUpdateNotifyReturn>")
. Append ("</soap:orderRelationUpdateNotifyResponse>")
. Append ("</soapenv:Body>")
. Append ("</soapenv:Envelope>");
return ret.tostring ();
}
}
Develop Web service without any framework