java-Tool-webservice WSDL parsing

Source: Internet
Author: User
Tags soap wsdl

WSDL parsing

The first step is to understand the interface description of the third-party webservice, which is parsing the WSDL file. A WSDL file is a WebService service Interface description document, a WSDL file can contain multiple interfaces, and an interface can contain multiple methods.

 Public  class wsdlinfo {    PrivateString Wsdlname;Privatelist<interfaceinfo> interfaces;/** * Coshaho * @param path WSDL address * @throws Exception */     Public Wsdlinfo(String Path)throwsException {Wproject Project =NewWproject (); wsdlinterface[] wsdlinterfaces = wsdlimporter.importwsdl (project, path); This. wsdlname = path;if(NULL! = wsdlinterfaces) {list<interfaceinfo> interfaces =NewArraylist<interfaceinfo> (); for(Wsdlinterface wsdlinterface:wsdlinterfaces) {Interfaceinfo Interfaceinfo =NewInterfaceinfo (Wsdlinterface);            Interfaces.add (Interfaceinfo); } This. interfaces = interfaces; }    } PublicStringGetwsdlname() {returnWsdlname; } Public void Setwsdlname(String wsdlname) { This. wsdlname = Wsdlname; } PublicList<interfaceinfo>getinterfaces() {returnInterfaces } Public void setinterfaces(List<interfaceinfo> interfaces) { This. interfaces = interfaces; }}
 Public classInterfaceinfo {PrivateString InterfaceName;PrivateList<operationinfo> operations;PrivateString[] adrress; Public Interfaceinfo(Wsdlinterface wsdlinterface) { This. InterfaceName = Wsdlinterface.getname (); This. adrress = Wsdlinterface.getendpoints ();intOperationnum = Wsdlinterface.getoperationcount (); list<operationinfo> operations =NewArraylist<operationinfo> (); for(inti =0; i < Operationnum;            i++) {wsdloperation operation = (wsdloperation) wsdlinterface.getoperationat (i); Operationinfo Operationinfo =NewOperationinfo (operation);        Operations.add (Operationinfo); } This. operations = operations; } PublicStringGetinterfacename() {returnInterfaceName; } Public void Setinterfacename(String InterfaceName) { This. InterfaceName = InterfaceName; } PublicList<operationinfo>getoperations() {returnOperations } Public void setoperations(List<operationinfo> Operations) { This. operations = operations; } PublicString[]getadrress() {returnadrress; } Public void setadrress(string[] adrress) { This. adrress = adrress; }}
 Public classOperationinfo {PrivateString OperationName;PrivateString RequestXML;PrivateString Responsexml; Public Operationinfo(Wsdloperation operation)        {OperationName = Operation.getname (); RequestXML = Operation.createrequest (true); Responsexml = Operation.createresponse (true); } PublicStringGetoperationname() {returnOperationName; } Public void Setoperationname(String OperationName) { This. OperationName = OperationName; } PublicStringGetrequestxml() {returnRequestXML; } Public void Setrequestxml(String RequestXML) { This. RequestXML = RequestXML; } PublicStringGetresponsexml() {returnResponsexml; } Public void Setresponsexml(String responsexml) { This. responsexml = Responsexml; }}
public class Wsdlparsetest {public static void main (string[] args) throws Exception {String URL ="HTTP://WEBSERVICE.WEBXML.COM.CN/WEBSERVICES/CHINAOPENFUNDWS.ASMX?WSDL";Wsdlinfo wsdlinfo = new Wsdlinfo (URL);System. out. println("WSDL URL is"+ Wsdlinfo. Getwsdlname());for (Interfaceinfo Interfaceinfo:wsdlinfo. Getinterfaces()) {System. out. println("Interface name is"+ Interfaceinfo. Getinterfacename());for (String Ads:interfaceinfo. Getadrress()) {System. out. println("Interface address is"+ ads);} for (Operationinfo Operation:interfaceinfo. GetOperations()) {System. out. println("Operation name is"+ Operation. Getoperationname());System. out. println("Operation request is");System. out. println("Operation request is"+ Operation. Getrequestxml());System. out. println("Operation response is");System. out. println(Operation. Getresponsexml());}        }    }}
WSDL URL is http://webservice.webxml.com.cn/WebServices/ChinaOpenFundWS.asmx?wsdlInterface name is Chinaopenfundwssoap12interface address is http://webservice.webxml.com.cn/WebServices/ Chinaopenfundws.asmxoperation name is getfundcodenamedatasetoperation request was Operation request is<soap:envelope xmlns:soap="Http://www.w3.org/2003/05/soap-envelope" xmlns: Web="http://WebXml.com.cn/">   <soap:header/>   <soap:body>      <web:getfundcodenamedataset/>   </soap:body></soap:envelope>Operation response is<soap:envelope xmlns:soap="Http://www.w3.org/2003/05/soap-envelope" xmlns: Web="http://WebXml.com.cn/" xmlns:xs="Http://www.w3.org/2001/XMLSchema">    <soap:header/>   <soap:body>      <web:getfundcodenamedatasetresponse>         <!--optional:-->         <web:getfundcodenamedatasetresult>            <xs:schema>               <!--ignoring type [{http://www.w3.org/2001/xmlschema}schema]-->            </Xs:schema>            <!-- you could enter any elements at this point-->         </web:getfundcodenamedatasetresult>      </web:getfundcodenamedatasetresponse>   </soap:body></soap:envelope>Operation name is getfundcodenamestringoperation request was Operation request is<soap:envelope xmlns:soap="Http://www.w3.org/2003/05/soap-envelope" xmlns: Web="http://WebXml.com.cn/">   <soap:header/>   <soap:body>      <web:getfundcodenamestring/>   </soap:body></soap:envelope>Operation response is<soap:envelope xmlns:soap="Http://www.w3.org/2003/05/soap-envelope" xmlns: Web="http://WebXml.com.cn/">   <soap:header/>   <soap:body>      <web:getfundcodenamestringresponse>         <!--optional:-->         <web:getfundcodenamestringresult>            <!--Zero or more repetitions:-->            <web:string>?</web:string>         </web:getfundcodenamestringresult>      </web:getfundcodenamestringresponse>   </soap:body></soap:envelope>Operation name is getopenfunddatasetoperation request was Operation request is<soap:envelope xmlns:soap="Http://www.w3.org/2003/05/soap-envelope" xmlns: Web="http://WebXml.com.cn/">   <soap:header/>   <soap:body>      <web:getopenfunddataset>         <!--optional:-->         <web:userid>?</Web:userid>      </web:getopenfunddataset>   </soap:body></soap:envelope>Operation response is<soap:envelope xmlns:soap="Http://www.w3.org/2003/05/soap-envelope" xmlns: Web="http://WebXml.com.cn/" xmlns:xs="Http://www.w3.org/2001/XMLSchema">    <soap:header/>   <soap:body>      <web:getopenfunddatasetresponse>         <!--optional:-->         <web:getopenfunddatasetresult>            <xs:schema>               <!--ignoring type [{http://www.w3.org/2001/xmlschema}schema]-->            </Xs:schema>            <!-- you could enter any elements at this point-->         </web:getopenfunddatasetresult>      </web:getopenfunddatasetresponse>   </soap:body></soap:envelope>

java-Tool-webservice WSDL parsing

Related Article

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.