soap-ws获取wsdl中的所有的接口方法

示例wsdl文件如下,生成的过程可以参考https://www.cnblogs.com/chenyun-/p/11502446.html

 <definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://impl.chenyun.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://impl.chenyun.com/" name="WsImplService">
<types>
<xsd:schema>
<xsd:import namespace="http://impl.chenyun.com/" schemaLocation="http://localhost:8081/Webservice?xsd=1"/>
</xsd:schema>
</types>
<message name="sayname2">
<part name="parameters" element="tns:sayname2"/>
</message>
<message name="sayname2Response">
<part name="parameters" element="tns:sayname2Response"/>
</message>
<message name="sayname">
<part name="parameters" element="tns:sayname"/>
</message>
<message name="saynameResponse">
<part name="parameters" element="tns:saynameResponse"/>
</message>
<portType name="WsImpl">
<operation name="sayname2">
<input wsam:Action="http://impl.chenyun.com/WsImpl/sayname2Request" message="tns:sayname2"/>
<output wsam:Action="http://impl.chenyun.com/WsImpl/sayname2Response" message="tns:sayname2Response"/>
</operation>
<operation name="sayname">
<input wsam:Action="http://impl.chenyun.com/WsImpl/saynameRequest" message="tns:sayname"/>
<output wsam:Action="http://impl.chenyun.com/WsImpl/saynameResponse" message="tns:saynameResponse"/>
</operation>
</portType>
<binding name="WsImplPortBinding" type="tns:WsImpl">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="sayname2">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="sayname">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="WsImplService">
<port name="WsImplPort" binding="tns:WsImplPortBinding">
<soap:address location="http://localhost:8081/Webservice"/>
</port>
</service>
</definitions>

通过wsdl地址获取的所有方法,也就是operations,在wsdl文件中定义这些operation的地方是有两处,一处在portType节点,一处是在binding节点处,两处均可以获取到所有的方法,具体有什么差别暂时还没有发现,这里使用的是在binding节点处获取,在portType处获取暂时没有测试,后续可能会更新。

soap-ws的git地址:https://github.com/reficio/soap-ws

在Readme中可以找到Quick-start,根据里面的讲解,我们需要使用的部分需要添加一个依赖和一个仓库(添加仓库是因为还没有添加进maven的核心仓库,文档中有介绍)

pom.xml

 <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.chenyun</groupId>
<artifactId>webservice_test_v5</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>webservice_test_v5</name>
<description>Demo project for Spring Boot</description> <properties>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.reficio</groupId>
<artifactId>soap-builder</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies> <repositories>
<repository>
<id>reficio</id>
<url>http://repo.reficio.org/maven/</url>
</repository>
</repositories> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

至此,准备已经大概完成,下面是介绍核心代码:

getList.java

 /*
* @author:陈云
* @date:2019/9/10
* @description:返回接口列表
*/
package com.chenyun; import org.reficio.ws.builder.SoapBuilder;
import org.reficio.ws.builder.SoapOperation;
import org.reficio.ws.builder.core.Wsdl; import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List; public class getList {
/**
*
* @param wsdlUrl
* @return List<String>接口列表
*/
public static List<String> getBindingOperations(String wsdlUrl) {
List<String> operationList = new ArrayList();
List<SoapOperation> soapOperationList = new ArrayList();
//解析指定的wsdl文件,生成一个wsdl对象
Wsdl parser = Wsdl.parse(wsdlUrl);
//类Wsdl中提供了获取所有binding的方法getBindings()
List<QName> bindQnames = parser.getBindings();
//接口SoapBuilder,定义了获取operation的方法,获取的是binding节点的所有operation。
for (QName qName : bindQnames) {
SoapBuilder soapBuilder = parser.binding().localPart(qName.getLocalPart()).find();
soapOperationList.addAll(soapBuilder.getOperations());
}
for (SoapOperation soapOperation : soapOperationList) {
operationList.add(soapOperation.getOperationName());
}
return operationList;
}
}
WebserviceTestV5Application.java
package com.chenyun;

import org.apache.log4j.BasicConfigurator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import static com.chenyun.getList.getBindingOperations; @SpringBootApplication
public class WebserviceTestV5Application { public static void main(String[] args) {
SpringApplication.run(WebserviceTestV5Application.class, args);
//提供wsdl的值,调用getBindingOperations()
String wsdl = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl";
System.out.println("=====================================");
System.out.println("接口列表:");
for(int i=0;i<getBindingOperations(wsdl).size();i++){
System.out.println("接口" + i + ":"+ getBindingOperations(wsdl).get(i));
}
System.out.println("=====================================");
System.out.println("接口查询结束");
}
}

运行主函数即可获取到结果。

soap-ws获取ws中的所有的接口方法的更多相关文章

  1. 使用JavaScript获取URL中的参数(两种方法)

    本文给大家分享两种方法使用js获取url中的参数,其中方法二是使用的正则表达式方法,大家可以根据需要选择比较好的方法,废话不多说了,直接看详细介绍吧. 方法一: //取url参数 var type = ...

  2. 用JS获取地址栏中的参数的简易方法

    这个方法用起来超级简单,传入参数即可直接获取地址栏中的参数 代码如下 function GetQueryString(name) { var reg = new RegExp("(^|&am ...

  3. JS获取URL中参数值的4种方法

    方法一:正则法 function getQueryString(name) { var reg = new RegExp('(^|&)' + name + '=([^&]*)(& ...

  4. java爬虫系列第三讲-获取页面中绝对路径的各种方法

    在使用webmgiac的过程中,很多时候我们需要抓取连接的绝对路径,总结了几种方法,示例代码放在最后. 以和讯网的一个页面为例: xpath方式获取 log.info("{}", ...

  5. scala中获取Map中key和value的方法

    val scores=Map("Alice"->10,"Bob"->3,"Cindy"->8) // 获取所有的key v ...

  6. shell脚本获取文件中key/value的小方法

    方法有N种,awk.sad.grep.cut... 以上几种方式不写了,就写两个不太常用到的. 废话少说,直接上代码: cat a.txt aa.gif=aaaa.gif bb.gif=bbbb.gi ...

  7. Javascript获取数组中的最大值和最小值方法汇总

    方法一 sort()方法 b-a从大到小,a-b从小到大 var max2 = arr.sort(function(a,b){ return b-a; })[0]; console.log(max2) ...

  8. vue2 在mounted函数无法获取prop中的变量的解决方法

    props: { example: { type: Object, default() { }, }, }, watch: { example: function(newVal,oldVal){ // ...

  9. ArcGIS Engine中如何获取Map中已经选择的要素呢

    1.使用IEnumFeturea对象获取map中的FeatureSelection,该方法可以获取所有图层的选择要素.IMap中的FeatureSelection可不是IFeatureSelectio ...

随机推荐

  1. Spring AMQP 发送消息到 RabbitMQ 收到 x-queue-type 错误

    在使用 Spring AMQP 发送消息到 RabbitMQ 的时候收到错误信息: inequivalent arg 'x-queue-type' for queue 'com.ossez.real. ...

  2. 正则匹配href标签内容

    完整a标签 <a.+?href=\"(.+?)\".*>(.+)</a> 单独href : <a.+?href=\"(.+?)\" ...

  3. google中select添加onclick

    有下拉跳转框如下所示: <select name="page" size="1" > <option onclick="refurb ...

  4. 【maven】【spring boot】【单元测试】 使用controller 执行单元测试类

    存在这样一个场景: 当项目启动时间过长,又没办法缩短的时候,写单元测试就是一个十分耗时的工作, 这工作不在于使用编写代码,而在于每次run junit test 都需要完整启动一次项目,白白浪费宝贵的 ...

  5. Nginx之进程间的通信机制(共享内存、原子操作)

    1. 概述 Linux 提供了多种进程间传递消息的方式,如共享内存.套接字.管道.消息队列.信号等,而 Nginx 框架使用了 3 种传递消息的传递方式:共享内存.套接字.信号. 在进程间访问共享资源 ...

  6. SpringJunitTest

    1.用MockBean和assert,而不是输出 import org.springframework.boot.test.mock.mockito.MockBean;MockBean import ...

  7. [BTS] BizTalk WCF-SQL Adapter 高级应用

    9102年岁尾,41岁的我居然还在搞 BizTalk,感觉就是一种悲伤. 国内用户少之又少,能坚持一直在使用的“忠实”用户那就更少了. 不是它不好用,而是微软全线转向云服务,这个产品也已经快10年没有 ...

  8. git基本操作命令和安装

    git客户端下载及安装 git.png git官方下载链接 1. 添加到桌面 添加到桌面.png (1)图标组件(Addition icons) : 选择是否创建桌面快捷方式. (2)桌面浏览(Win ...

  9. HSBToolBox

    HSBToolBox.exe Unzip all files to the folder where Hearthbuddy.exeThen just run HSBToolBox.exe [asse ...

  10. VS2015编译cef3-2357

    1.会遇到把警告当错误的情况 按照如下设置即可 2. 错误 C2334 “:”的前面有意外标记:跳过明显的函数体 (编译源文件 E:\cef_binary_3.2357.1271.g8e0674e_w ...