java-工具-Webservice wsdl解析

简介: 原文链接:http://www.cnblogs.com/coshaho/p/5689738.html wsdl解析首先必然是理解第三方webservice的接口描述,也就是解析wsdl文件。

原文链接:http://www.cnblogs.com/coshaho/p/5689738.html
wsdl解析

首先必然是理解第三方webservice的接口描述,也就是解析wsdl文件。wsdl文件是webservice服务接口描述文档,一个wsdl文件可以包含多个接口,一个接口可以包含多个方法。

public class WsdlInfo 
{
    private String wsdlName;

    private List<InterfaceInfo> interfaces;

    /**
     * coshaho
     * @param path  wsdl地址
     * @throws Exception
     */
    public WsdlInfo(String path) throws Exception
    {
        WProject project = new WProject();
        WsdlInterface[] wsdlInterfaces = WsdlImporter.importWsdl( project, path );
        this.wsdlName = path;
        if(null != wsdlInterfaces)
        {    
            List<InterfaceInfo> interfaces = new ArrayList<InterfaceInfo>();
            for(WsdlInterface wsdlInterface : wsdlInterfaces)
            {
                InterfaceInfo interfaceInfo = new InterfaceInfo(wsdlInterface);
                interfaces.add(interfaceInfo);
            }
            this.interfaces = interfaces;
        }
    }

    public String getWsdlName() {
        return wsdlName;
    }

    public void setWsdlName(String wsdlName) {
        this.wsdlName = wsdlName;
    }

    public List<InterfaceInfo> getInterfaces() {
        return interfaces;
    }

    public void setInterfaces(List<InterfaceInfo> interfaces) {
        this.interfaces = interfaces;
    }
}
public class InterfaceInfo 
{
    private String interfaceName;

    private List<OperationInfo> operations;

    private String[] adrress;

    public InterfaceInfo(WsdlInterface wsdlInterface)
    {
        this.interfaceName = wsdlInterface.getName();

        this.adrress = wsdlInterface.getEndpoints();

        int operationNum = wsdlInterface.getOperationCount();
        List<OperationInfo> operations = new ArrayList<OperationInfo>();

        for(int i = 0; i < operationNum; i++)
        {
            WsdlOperation operation = ( WsdlOperation )wsdlInterface.getOperationAt( i );
            OperationInfo operationInfo = new OperationInfo(operation);
            operations.add(operationInfo);
        }

        this.operations = operations;
    }

    public String getInterfaceName() {
        return interfaceName;
    }

    public void setInterfaceName(String interfaceName) {
        this.interfaceName = interfaceName;
    }

    public List<OperationInfo> getOperations() {
        return operations;
    }

    public void setOperations(List<OperationInfo> operations) {
        this.operations = operations;
    }

    public String[] getAdrress() {
        return adrress;
    }

    public void setAdrress(String[] adrress) {
        this.adrress = adrress;
    }
}
public class OperationInfo 
{
    private String operationName;

    private String requestXml;

    private String responseXml;

    public OperationInfo(WsdlOperation operation)
    {
        operationName = operation.getName();
        requestXml = operation.createRequest( true );
        responseXml = operation.createResponse(true);    
    }

    public String getOperationName() {
        return operationName;
    }

    public void setOperationName(String operationName) {
        this.operationName = operationName;
    }

    public String getRequestXml() {
        return requestXml;
    }

    public void setRequestXml(String requestXml) {
        this.requestXml = requestXml;
    }

    public String getResponseXml() {
        return responseXml;
    }

    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?wsdl
Interface name is ChinaOpenFundWSSoap12
Interface address is http://webservice.webxml.com.cn/WebServices/ChinaOpenFundWS.asmx
operation name is getFundCodeNameDataSet
operation request is 
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 may enter ANY elements at this point-->
         </web:getFundCodeNameDataSetResult>
      </web:getFundCodeNameDataSetResponse>
   </soap:Body>
</soap:Envelope>
operation name is getFundCodeNameString
operation request is 
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 getOpenFundDataSet
operation request is 
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 may enter ANY elements at this point-->
         </web:getOpenFundDataSetResult>
      </web:getOpenFundDataSetResponse>
   </soap:Body>
</soap:Envelope>
目录
相关文章
|
4天前
|
存储 安全 算法
【常见集合】Java 常见集合重点解析
【常见集合】Java 常见集合重点解析
8 0
|
4天前
|
Java
探索Java世界的奇妙工具——运算符与表达式运算符
探索Java世界的奇妙工具——运算符与表达式运算符
9 0
|
3天前
|
缓存 算法 Java
数据结构~缓存淘汰算法--LRU算法(Java的俩种实现方式,万字解析
数据结构~缓存淘汰算法--LRU算法(Java的俩种实现方式,万字解析
|
3天前
|
缓存 IDE Java
Java一分钟之-Gradle:构建自动化工具
【5月更文挑战第16天】本文介绍了Gradle,一个基于Groovy的灵活构建工具,强调其优于Maven的灵活性和性能。文中通过示例展示了基本的`build.gradle`文件结构,并讨论了常见问题:版本冲突、缓存问题和构建速度慢,提供了相应的解决策略。此外,还提醒开发者注意插件ID、语法错误和源代码目录等易错点。掌握这些知识能提升开发效率,使构建过程更顺畅。
21 2
|
4天前
|
Java Maven 开发者
Java一分钟之-Maven项目管理工具使用
【5月更文挑战第15天】Maven是Java开发的项目管理工具,用于自动化构建、依赖管理和项目信息管理。通过POM模型管理项目,依赖中央仓库。基本目录包括`src/main/java`、`src/main/resources`、`src/test/java`和`src/test/resources`。常用命令有`clean`、`compile`、`test`、`package`和`install`。面对依赖冲突、找不到依赖或编译错误,可以调整`pom.xml`或`settings.xml`。理解Maven的工作原理和解决常见问题能提升开发效率。
17 0
|
4天前
|
Java 开发工具 Maven
java解析apk获取应用信息
请注意,你需要替换"path/to/your/apkfile.apk"为你的APK文件的实际路径。
11 0
|
4天前
|
人工智能 自然语言处理 机器人
销售利器大集结:13种智能销售工具全面解析
该文探讨了人工智能在销售领域的应用,测试了13款领先工具,如Zoho CRM、Email Subject Line Generator和ChatGPT Plus等,这些工具通过数据分析、自动化任务和智能交互提升销售效率。然而,使用AI也带来人机交互和数据安全的挑战。文章强调,结合人工智能和人类销售人员的优势是关键,同时应谨慎处理相关问题。
25 4
|
4天前
|
Java 程序员 API
Java 8新特性之Lambda表达式与Stream API的深度解析
【5月更文挑战第12天】本文将深入探讨Java 8中的两个重要新特性:Lambda表达式和Stream API。我们将从基本概念入手,逐步深入到实际应用场景,帮助读者更好地理解和掌握这两个新特性,提高Java编程效率。
43 2
|
4天前
|
XML JavaScript Java
详解Java解析XML的四种方法
详解Java解析XML的四种方法
16 1
|
4天前
|
Java
解析java中的数组
解析java中的数组
15 3

推荐镜像

更多