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. MySQL 5.7半同步复制技术

    一.复制架构衍生史 在谈这个特性之前,我们先来看看MySQL的复制架构衍生史. 在2000年,MySQL 3.23.15版本引入了Replication.Replication作为一种准实时同步方式, ...

  2. vue 源码解析computed

    计算属性 VS 侦听属性 Vue 的组件对象支持了计算属性 computed 和侦听属性 watch 2 个选项,很多同学不了解什么时候该用 computed 什么时候该用 watch.先不回答这个问 ...

  3. maven mvn 命令行 编译打包

    * 配置好jdk * 下载安装maven http://maven.apache.org/download.cgi apache-maven-3.3.3-bin.zip * 解压到G:\apache- ...

  4. Qt网络获取本机网络信息

    下面我们就讲解如何获取自己电脑的IP地址以及其他网络信息.这一节中,我们会涉及到网络模块(QtNetwork Module)中的QHostInfo ,QHostAddress ,QNetworkInt ...

  5. java不用中间变量交换两个值

    public void changeVal(){ int a = 2; int b = 3; System.out.println("交换前 a:"+a+",b:&quo ...

  6. [转]Nginx实现高并发的原理

    Nginx 首先要明白,Nginx 采用的是多进程(单线程) & 多路IO复用模型.使用了 I/O 多路复用技术的 Nginx,就成了”并发事件驱动“的服务器. 异步非阻塞(AIO)的详解ht ...

  7. Message NNNN not found; No message file for product=network, facility=TNS

    Message NNNN not found; No message file for product=network, facility=TNS Table of Contents 1. 错误信息 ...

  8. springmvc快速入门(注解版本)

    1)springmvc快速入门(传统版) 步一:创建springmvc-day02这么一个web应用 步二:导入springioc,springweb和springmvc相关的jar包 ------- ...

  9. 在Spring中配置jdbc为什么不能用${username}问题

    楼主在spring中配置jdbc时,引用的是dbcp.jar包,在dataSource.properties配置文件中,有mysql用户名,楼主自然的选择了使用username,密码是root, 然后 ...

  10. SLC cache功能

    由于TLC需要多次编程,且未全部编程时wordLine处于不稳定状态,所以一般都会划出一部分区域作为SLC cache使用 SLC cache主要功能是,SSD接收到写命令后,先将数据写入SLC ca ...