解析 WSDL 的简单方法

2023-12-25

我正在尝试解析 WSDL 以获取操作、端点和示例有效负载。用户输入的 WSDL。我找不到执行此操作的教程。

我只能找到生成我不需要的源代码的那些。我尝试过使用 XBeans,但显然我需要 Saxon。有没有一种简单的轻量级方法可以在没有 Saxon 的情况下做到这一点?

E.g.

   <?xml version="1.0"?>
  <definitions name="StockQuote"
  targetNamespace=
    "http://example.com/stockquote.wsdl"
  xmlns:tns="http://example.com/stockquote.wsdl"
  xmlns:xsd1="http://example.com/stockquote.xsd"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns="http://schemas.xmlsoap.org/wsdl/">
   <types>
   <schema targetNamespace=
     "http://example.com/stockquote.xsd"
     xmlns="http://www.w3.org/2000/10/XMLSchema">
      <element name="TradePriceRequest">
        <complexType>
           <all>
             <element name="tickerSymbol" 
               type="string"/>
           </all>
        </complexType>
      </element>
      <element name="TradePrice">
        <complexType>
          <all>
            <element name="price" type="float"/>
          </all>
        </complexType>
      </element>
   </schema>
   </types>
   <message name="GetLastTradePriceInput">
     <part name="body" element=
       "xsd1:TradePriceRequest"/>
   </message>
   <message name="GetLastTradePriceOutput">
     <part name="body" element="xsd1:TradePrice"/>
   </message>
   <portType name="StockQuotePortType">
     <operation name="GetLastTradePrice">
       <input message="tns:GetLastTradePriceInput"/>
       <output message="tns:GetLastTradePriceOutput"/>
     </operation>
   </portType>
     <binding name="StockQuoteSoapBinding"
       type="tns:StockQuotePortType">
       <soap:binding style="document"
         transport=
           "http://schemas.xmlsoap.org/soap/http"/>
     <operation name="GetLastTradePrice">
       <soap:operation
         soapAction=
           "http://example.com/GetLastTradePrice"/>
         <input>
           <soap:body use="literal"/>
         </input>
         <output>
           <soap:body use="literal"/>
         </output>
       </operation>
     </binding>
     <service name="StockQuoteService">
       <documentation>My first service</documentation>
       <port name="StockQuotePort" 
         binding="tns:StockQuoteBinding">
         <soap:address location=
           "http://example.com/stockquote"/>
       </port>
     </service>
    </definitions>

应该获取操作:GetLastTradePrice、GetLastTradePrice

端点:StockQuotePort

有效负载示例:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:stoc="http://example.com/stockquote.xsd">
   <soapenv:Header/>
   <soapenv:Body>
      <stoc:TradePriceRequest/>
   </soapenv:Body>
</soapenv:Envelope>

这就像 SoapUI 所做的那样。但我主要关心的是能够解析 WSDL。更多上下文是上传 WSDL,然后将结果显示在 GWT 应用程序中(文件上传必须转到 servlet)。所以我需要解析该文件并创建一个 GWT 能够理解的对象。


这看起来不错:http://www.membrane-soa.org/soa-model-doc/1.4/java-api/parse-wsdl-java-api.htm http://www.membrane-soa.org/soa-model-doc/1.4/java-api/parse-wsdl-java-api.htm

不过,我的第一次尝试并没有成功,所以我编写了一个方法,返回示例 wsdl 的建议结果 - 没有 J2SE6 之外的依赖项。

public String[] listOperations(String filename) throws FileNotFoundException, SAXException, IOException, ParserConfigurationException {
  Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new FileInputStream(filename));
  NodeList elements = d.getElementsByTagName("operation");
  ArrayList<String> operations = new ArrayList<String>();
  for (int i = 0; i < elements.getLength(); i++) {
    operations.add(elements.item(i).getAttributes().getNamedItem("name").getNodeValue());
  }
  return operations.toArray(new String[operations.size()]);
}

似乎您想要删除重复项,因为每个操作在 WSDL 中都列出了两次。使用 Set 很容易。上传了完整的 Eclipse 项目,在此处显示了独特和非独特的结果:https://github.com/sek/wsdlparser https://github.com/sek/wsdlparser

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

解析 WSDL 的简单方法 的相关文章

随机推荐

  • 如何从数据库中按类别显示数据?

    因此 我的网站允许用户创建联系人列表 现在我添加了用户命名的类别 我当前正在使用从 SQL 查询生成的关联数组的 while 循环来显示联系人列表 所以它看起来像这样 Contacts Contact 1 Contact 2 Contact
  • 错误:此类与关键项目ToolBar 的键值编码不兼容? [复制]

    这个问题在这里已经有答案了 嘿 我无法弄清楚我遇到的错误 我的应用程序正在运行 然后我不确定我做了什么 但它现在无法打开 而是收到此错误 Terminating app due to uncaught exception NSUnknown
  • 无法在 Docker-Driver Windows 10 上访问 Minikube(v1.18.1) Ingress

    我的问题与this https stackoverflow com questions 66275458 could not access kubernetes ingress in browser on windows home with
  • 使用 PHP(或其他语言)流式传输数据(例如音乐)

    多年来 我一直在研究如何从我的计算机创建音乐流 我见过一些程序 但我见过的任何有用的东西都仅限于 Windows 我使用 Mac 最终 我产生了兴趣how流工作 有什么办法可以创建我的own流 可能使用套接字函数PHP 有没有PHP图书馆为
  • 如何在nhibernate中使用PK删除对象?

    如何删除对象而不先从数据库中获取它 在另一个 ORM 中 我可以这样做 session Delete
  • mojolicious 引用的存储变量并不总是定义的

    我仍在学习 mojolicious 和 MVC 框架 所以这可能是一个问题 我认为这个问题是错误的 所以如果我愿意 请建议一种更好的方法来执行以下操作 我有一条路线 route param 其中 param 有时被定义 有时则没有 我尝试在
  • 为什么“--force-recreate”不重建我的 docker mysql 映像?

    我创建了一个 docker MySql 5 7 映像 然后想更改几个名称 我的 docker compose yml 文件最终像这样 version 3 3 services db image mysql 5 7 restart alway
  • 未找到 osx sys/io.h

    我想在 os x 下使用 cc 编译为 linux 开发的 c 程序 它包括标头 sys io h 编译的时候报错说找不到这个文件 os x下不是有sys io h头文件吗 任何帮助将非常感激 Thanks Include
  • 更改flutter应用程序图标的背景颜色

    我想将背景图标更改为 fe6017 I use flutter launcher icons set adaptive icon background fe6017 但这不起作用 我也尝试调整图像大小 但它总是收缩并放置white我的图像周
  • 如何使用JW Player播放rtmp流?

    我想知道如何使用 JW Player 流式传输 RTMP 我刚刚开始 嵌入没有帮助 因此如果有人可以分享适合他的代码 将会有所帮助 我们这里有一个指南 http www longtailvideo com support jw player
  • jqgrid 获取所有网格列名称

    有没有办法获取网格的所有列名称 您可以使用以下方式获取列名称 var columnNames list 0 p colNames or var columnNames list jqGrid getGridParam colNames 唯一
  • 给定日期范围内的每日活跃用户数

    我需要根据开始日期和结束日期查找每日活跃用户总数 报名表 id registration no start date end date 1 1000 2014 12 01 2014 12 03 2 1001 2014 12 01 2014
  • PHP 中的“贪婪标记解析”是什么?

    PHP 中的 贪婪标记解析 是什么 我在 Codeigniter 指南中找到了这一点 除非需要解析变量 否则始终使用单引号字符串 并且在确实需要解析变量的情况下 请使用大括号来防止贪婪标记解析 我的字符串 foo 带有良好解释的答案会有所帮
  • React 和 babel 中的可选链接运算符

    在我的项目中我配置 babel presets react es2015 stage 1 transform optional chaining plugins transform runtime 这是我的devDependencies i
  • 如何一次运行多种语言的 tesseract?

    我必须分析包含英语和日语文本的图像 当我默认运行 tesseract 时 l eng 一些日语字符丢失了 否则 如果我用日语运行 tesseract l jpn 一些英文字符丢失 例如电子邮件 如何运行一个同时识别英语和日语字符的进程 从
  • dlopen 与链接开销

    假设我有一个库 foo so 当构建我的二进制文件 需要这个库 时 我可以 1 链接 foo so 或者 2 在程序源代码中 dlopen 这个库 然后调用这个库提供的函数 当我从库中调用函数时 1 和 2 之间有性能差异吗 请注意 我知道
  • 为什么 VB 中的 lambda 表达式与 C# 中不同?

    我刚刚在 NHibernate 中遇到了一个错误 该错误恰好已经被提出 https nhibernate jira com browse NH 2763 https nhibernate jira com browse NH 2763 我不
  • 将 duff 的设备从 C 移植到 JavaScript

    我有这种 Duff 的 C 语言设备 它工作正常 将文本格式设置为金钱 include
  • 带有 IIS 的 Kestrel - 运行时缺少 libuv.dll

    我们正在设置一个现有的 Web API 服务器 以便与现有的 API 一起为站点提供服务 我一直在松散地关注本文 http miniml ist dotnet how to serve a static site plus a web ap
  • 解析 WSDL 的简单方法

    我正在尝试解析 WSDL 以获取操作 端点和示例有效负载 用户输入的 WSDL 我找不到执行此操作的教程 我只能找到生成我不需要的源代码的那些 我尝试过使用 XBeans 但显然我需要 Saxon 有没有一种简单的轻量级方法可以在没有 Sa