利用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. 【css】修改placeholder 默认颜色

    html5为input添加了原生的占位符属性placeholder,高级浏览器都支持这个属性,例如: <input type="text" placeholder=" ...

  2. python-leepcode-作用解析 - 5-27

    30 找不同 给定两个字符串 s 和 t,它们只包含小写字母. 字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母. 请找出在 t 中被添加的字母. 示例: 输入: s = "a ...

  3. 我的Python分析成长之路10

    matplot数据可视化基础 制作提供信息的可视化(有时称作绘图)是数据分析中最重要任务之一. 1.图片(画布)与子图 plt.figure :创建一张空白的图片,可以指定图片的大小.像素. figu ...

  4. django 常见过滤器

      一.形式:小写 {{ name | lower }} 二.过滤器是可以嵌套的,字符串经过三个过滤器,第一个过滤器转换为小写,第二个过滤器输出首字母,第三个过滤器将首字母转换成大写 标签 {{ st ...

  5. 引用类型(JavaScript第5章)

    引用类型的值(对象)是引用类型的一个实例.在ECMScript中,引用类型是一种数据结构,用于将数据和功能组织在一起. 一.Object类型 创建Object实例的方式有两种.第一种是使用new操作符 ...

  6. Python flask+css+js+ajax 综合复习

    flask 基本语法结构 注:这里练习的时候把装饰器的@给忘记了,导致访问404 下面练习一下在前段向后端传递参数 get请求需要用   request.args.get('变量') 去接收, get ...

  7. js 格式化 时间插件

    // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...

  8. Matplotlib基础图形之散点图

    Matplotlib基础图形之散点图 散点图特点: 1.散点图显示两组数据的值,每个点的坐标位置由变量的值决定 2.由一组不连续的点组成,用于观察两种变量的相关性(正相关,负相关,不相关) 3.例如: ...

  9. heartbeat负载均衡详解

    heartbeat高可用软件http://www.linux-ha.org/wiki/Main_Page 1 heartbeat作用通过heartbeat将资源(IP)从一台已经故障的计算机快速转移到 ...

  10. redis2.3.7安装时出现undefined reference to `clock_gettime'

    (转自:http://blog.csdn.net/qq_28779503/article/details/54844988) undefined reference to `clock_gettime ...