利用wsdl4j解析WSDL文件

工具:wsdl4j1.6

解析wsdl文件是axis1.4的服务wsdl文件

wsdl文件:

<?xml version="1.0" encoding="UTF-8" ?>
-  <wsdl:definitions targetNamespace="http://localhost:8080/axis/services/SayHelloService
xmlns:apachesoap="http://xml.apache.org/xml-soap
xmlns:impl="http://localhost:8080/axis/services/SayHelloService
xmlns:intf="http://localhost:8080/axis/services/SayHelloService
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <!--

WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)

-->

- <wsdl:message name="sayHelloResponse">
  <wsdl:part name="sayHelloReturn" type="xsd:string" />
</wsdl:message>
- <wsdl:message name="sayHelloRequest">
  <wsdl:part name="name" type="xsd:string" />
</wsdl:message>
- <wsdl:portType name="SayHello">
- <wsdl:operation name="sayHello" parameterOrder="name">
  <wsdl:input message="impl:sayHelloRequest" name="sayHelloRequest" />
  <wsdl:output message="impl:sayHelloResponse" name="sayHelloResponse" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="SayHelloServiceSoapBinding" type="impl:SayHello">
  <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="sayHello">
  <wsdlsoap:operation soapAction="" />
- <wsdl:input name="sayHelloRequest">
  <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://hello.com" use="encoded" />
</wsdl:input>
- <wsdl:output name="sayHelloResponse">
  <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:8080/axis/services/SayHelloService" use="encoded" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
-  <wsdl:service name="SayHelloService">
 - <wsdl:port binding="impl:SayHelloServiceSoapBinding" name="SayHelloService"> 
  <wsdlsoap:address location="http://localhost:8080/axis/services/SayHelloService" />
</wsdl:port>
</wsdl:service>

</wsdl:definitions>

下面是两个程序wsdl4j编写:

程序1:

  1. package com.wxm;
  2. import javax.wsdl.*;
  3. import javax.wsdl.factory.*;
  4. import javax.wsdl.xml.*;
  5. public class ReadWsdl {
  6. public static void main(String[]args)
  7. {
  8. try{
  9. WSDLFactory factory=WSDLFactory.newInstance();
  10. WSDLReader reader=factory.newWSDLReader();
  11. reader.setFeature("javax.wsdl.verbose",true);
  12. reader.setFeature("javax.wsdl.importDocuments",true);
  13. Definition def=reader.readWSDL("http://localhost:8080/axis/services/SayHelloService?wsdl");
  14. WSDLWriter writer=factory.newWSDLWriter();
  15. writer.writeWSDL(def, System.out);
  16. }catch(WSDLException e){e.printStackTrace();}
  17. }
  18. }

程序2:

  1. package com.wxm;
  2. import javax.wsdl.*;
  3. import javax.wsdl.extensions.*;
  4. import javax.wsdl.factory.*;
  5. import javax.wsdl.xml.*;
  6. import javax.xml.namespace.QName;
  7. import java.util.*;
  8. import org.w3c.dom.*;
  9. public class NavigatingWSDL {
  10. public static void main(String[]args)
  11. {
  12. try{
  13. WSDLFactory factory=WSDLFactory.newInstance();
  14. WSDLReader reader=factory.newWSDLReader();
  15. reader.setFeature("javax.wsdl.verbose",true);
  16. reader.setFeature("javax.wsdl.importDocuments",true);
  17. Definition def=reader.readWSDL("http://localhost:8080/axis/services/SayHelloService?wsdl");
  18. //解析服务名
  19. System.out.println("----------");
  20. System.out.println("nService Name:");
  21. String tns="http://localhost:8080/axis/services/SayHelloService";
  22. Service service =def.getService(new QName(tns,"SayHelloService"));
  23. System.out.println(service.getQName().getLocalPart());
  24. //解析接口方法名
  25. System.out.println("nOperation Name:");
  26. Port port =service.getPort("SayHelloService");
  27. Binding binding=port.getBinding();
  28. PortType portType=binding.getPortType();
  29. List operations=portType.getOperations();
  30. Iterator operIter=operations.iterator();
  31. while(operIter.hasNext())
  32. {
  33. Operation operation=(Operation)operIter.next();
  34. if(!operation.isUndefined())
  35. {System.out.println(operation.getName()) ;}
  36. }
  37. //解析消息,输入输出
  38. System.out.println("nMessages:");
  39. Map messages=def.getMessages();
  40. Iterator msgIter=messages.values().iterator();
  41. while(msgIter.hasNext())
  42. {
  43. Message msg=(Message)msgIter.next();
  44. if(!msg.isUndefined())
  45. {
  46. System.out.println(msg.getQName().getLocalPart());
  47. Iterator partIter=msg.getParts().values().iterator();
  48. while(partIter.hasNext())
  49. {
  50. Part part=(Part) partIter.next();
  51. System.out.print("parameter name:"+part.getName()+"t");
  52. System.out.println("parameter type:"+part.getTypeName().getLocalPart());
  53. }
  54. }
  55. }
  56. //解析服务地址
  57. System.out.println("nService location:");
  58. List l=port.getExtensibilityElements();
  59. ExtensibilityElement element=(ExtensibilityElement) l.get(0);
  60. String s=element.toString();
  61. System.out.println(s.substring(s.indexOf("location")));
  62. System.out.println("---------");
  63. }catch(WSDLException e){e.printStackTrace();}
  64. }
  65. }

可以解析出wsdl文件的服务名,操作接口名,服务地址等

转:http://blog.sina.com.cn/s/blog_5ee36ce70100nk97.html

WSDL4J解析WSDL文件方法的更多相关文章

  1. c++ 读取并解析excel文件方法

    用Cocos开发模型特效工具编辑器,跨Mac和windows,当中有个需求是读取并解析excel文件,但网上的查找的例子几乎都只能是在windows下面使用,再或者是命令行脚本之类的.于是,自己写了一 ...

  2. 图解SOAPUI解析WSDL文件

    本文链接:https://blog.csdn.net/qq_16234613/article/details/53143279 新建项目 添加WSDL文件 查看方法 查看XML格式 运行测试  

  3. axis2--生成的wsdl文件方法的参数问题

    我是一个使用axis2的新手,发现一个问题: * axis2生成的wsdl文件中关于提供服务的方法,其参数名称丢失,会变成args0 * , 原因: axis2 无法从java字节码中获取关于方法签名 ...

  4. android解析xml文件方法之一-----DOM

    Hello.xml文件 <dict num="219" id="219" name="219"> <key>hell ...

  5. So easy Webservice 5.WSDL 文件说明

    WSDL – WebService Description Language – Web服务描述语言 通过XML形式说明服务在什么地方-地址. 通过XML形式说明服务提供什么样的方法 – 如何调用. ...

  6. Java中使用DOM4J来生成xml文件和解析xml文件

    一.前言 现在有不少需求,是需要我们解析xml文件中的数据,然后导入到数据库中,当然解析xml文件也有好多种方法,小编觉得还是DOM4J用的最多最广泛也最好理解的吧.小编也是最近需求里遇到了,就来整理 ...

  7. 学习 WebService 第二步:知识准备——WSDL文件解析

    原文地址:https://www.cnblogs.com/yzw23333/p/7245104.html Web service中一个 WSDL 对应一个 web service地址. 可以想象成一个 ...

  8. ACEXML解析XML文件——我是如何学习并在短时间内掌握一个库的使用方法的

    最近做的C++项目中需要使用xml文件保存一些信息,程序启动时会读取这些信息.最终经过主程的评测,决定使用ACEXML库来读取解析XML文件. 好吧,至于为什么选择ACEXML库,我就不说了.既然选择 ...

  9. 遍历文件 创建XML对象 方法 python解析XML文件 提取坐标计存入文件

    XML文件??? xml即可扩展标记语言,它可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言. 里面的标签都是可以随心所欲的按照他的命名规则来定义的,文件名为roi.xm ...

随机推荐

  1. Python列表,元组,字典,集合详细操作

    菜鸟学Python第五天 数据类型常用操作及内置方法 列表(list) ======================================基本使用====================== ...

  2. SVM 支持向量机算法介绍

    转自:https://zhuanlan.zhihu.com/p/21932911?refer=baina 参考:http://www.cnblogs.com/LeftNotEasy/archive/2 ...

  3. Action的实现方式

    [Pojo方式] 1.概述 Pojo(Plain Ordinary Java Object)称为简单Java类,其实就是一个JavaBean. 2.示例 /** * Pojo类方式实现Action * ...

  4. unittest断言方法的使用

    unittest框架的TestCase类提供以下方法用于测试结果的判断 方法 检查 版本 assertEqual(a, b) a ==b   assertNotEqual(a, b) a !=b   ...

  5. Webstrom卡顿问题解决

    1.设置node_modules 打开项目,新建node_modules空文件夹,然后右击选择Mark Directory as,选择Excluded. 2.设置ingore文件 files-> ...

  6. HDU 5016 Mart Master II

    Mart Master II Time Limit: 6000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ...

  7. Leetcode 336.回文对

    回文对 给定一组唯一的单词, 找出所有不同 的索引对(i, j),使得列表中的两个单词, words[i] + words[j] ,可拼接成回文串. 示例 1: 输入: ["abcd&quo ...

  8. shell文件包含

    像其他语言一样,Shell 也可以包含外部脚本,将外部脚本的内容合并到当前脚本. Shell 中包含脚本可以使用: . filename 或 source filename 两种方式的效果相同,简单起 ...

  9. 观光公交(codevs 1139)

    题目描述 Description 风景迷人的小城 Y 市,拥有n 个美丽的景点.由于慕名而来的游客越来越多,Y 市特意安排了一辆观光公交车,为游客提供更便捷的交通服务.观光公交车在第0 分钟出现在1号 ...

  10. Codeforces Round #291 (Div. 2) D. R2D2 and Droid Army [线段树+线性扫一遍]

    传送门 D. R2D2 and Droid Army time limit per test 2 seconds memory limit per test 256 megabytes input s ...