WSDL解析
背景
前面我们介绍过利用javassist动态生成webservice,这种方式可以使得我们系统通过页面配置动态发布webservice服务,做到0代码开发发布北向接口。进一步思考,我们如何0代码开发调用第三方webservice服务呢?
wsdl解析
首先必然是理解第三方webservice的接口描述,也就是解析wsdl文件。wsdl文件是webservice服务接口描述文档,一个wsdl文件可以包含多个接口,一个接口可以包含多个方法。

实际上,wsdl解析是十分困难的工作,网上也没有找到有效的解决办法,最终通过阅读SoapUI源码,找到了完美的解析方法。
代码
/**
* WsdlInfo.java Create on 2013-5-4 下午12:56:14
*
* 类功能说明: wsdl解析入口
*
* Copyright: Copyright(c) 2013
* Company: COSHAHO
* @Version 1.0
* @Author 何科序
*/
public class WsdlInfo
{
private String wsdlName; private List<InterfaceInfo> interfaces; /**
* coshaho
* @param path wsdl地址
* @throws Exception
*/
public WsdlInfo(String path) throws Exception
{
WsdlProject project = new WsdlProject();
WsdlInterface[] wsdlInterfaces = WsdlImporter.importWsdl( project, path );
this.wsdlName = path;
if(null != wsdlInterfaces)
{
List<InterfaceInfo> interfaces = new ArrayList<InterfaceInfo>();
for(WsdlInterface wsdlInterface : wsdlInterfaces)
{
InterfaceInfo interfaceInfo = new InterfaceInfo(wsdlInterface);
interfaces.add(interfaceInfo);
}
this.interfaces = interfaces;
}
} public String getWsdlName() {
return wsdlName;
} public void setWsdlName(String wsdlName) {
this.wsdlName = wsdlName;
} public List<InterfaceInfo> getInterfaces() {
return interfaces;
} public void setInterfaces(List<InterfaceInfo> interfaces) {
this.interfaces = interfaces;
}
}
/**
*
* InterfaceInfo.java Create on 2016年7月20日 下午9:03:21
*
* 类功能说明: 接口信息
*
* Copyright: Copyright(c) 2013
* Company: COSHAHO
* @Version 1.0
* @Author 何科序
*/
public class InterfaceInfo
{
private String interfaceName; private List<OperationInfo> operations; private String[] adrress; public InterfaceInfo(WsdlInterface wsdlInterface)
{
this.interfaceName = wsdlInterface.getName(); this.adrress = wsdlInterface.getEndpoints(); int operationNum = wsdlInterface.getOperationCount();
List<OperationInfo> operations = new ArrayList<OperationInfo>(); for(int i = 0; i < operationNum; i++)
{
WsdlOperation operation = ( WsdlOperation )wsdlInterface.getOperationAt( i );
OperationInfo operationInfo = new OperationInfo(operation);
operations.add(operationInfo);
} this.operations = operations;
} public String getInterfaceName() {
return interfaceName;
} public void setInterfaceName(String interfaceName) {
this.interfaceName = interfaceName;
} public List<OperationInfo> getOperations() {
return operations;
} public void setOperations(List<OperationInfo> operations) {
this.operations = operations;
} public String[] getAdrress() {
return adrress;
} public void setAdrress(String[] adrress) {
this.adrress = adrress;
}
}
/**
*
* OperationInfo.java Create on 2016年7月20日 下午9:03:42
*
* 类功能说明: 方法信息
*
* Copyright: Copyright(c) 2013
* Company: COSHAHO
* @Version 1.0
* @Author 何科序
*/
public class OperationInfo
{
private String operationName; private String requestXml; private String responseXml; public OperationInfo(WsdlOperation operation)
{
operationName = operation.getName();
requestXml = operation.createRequest( true );
responseXml = operation.createResponse(true);
} public String getOperationName() {
return operationName;
} public void setOperationName(String operationName) {
this.operationName = operationName;
} public String getRequestXml() {
return requestXml;
} public void setRequestXml(String requestXml) {
this.requestXml = requestXml;
} public String getResponseXml() {
return responseXml;
} public void setResponseXml(String responseXml) {
this.responseXml = responseXml;
}
}
测试代码
package com.coshaho.integration; import com.coshaho.integration.wsdl.InterfaceInfo;
import com.coshaho.integration.wsdl.OperationInfo;
import com.coshaho.integration.wsdl.WsdlInfo; /**
*
* WSDLParseTest.java Create on 2016年7月20日 下午9:24:36
*
* 类功能说明: WSDL解析测试
*
* Copyright: Copyright(c) 2013
* Company: COSHAHO
* @Version 1.0
* @Author 何科序
*/
public class WSDLParseTest
{
public static void main(String[] args) throws Exception
{
String url = "http://webservice.webxml.com.cn/WebServices/ChinaOpenFundWS.asmx?wsdl";
WsdlInfo wsdlInfo = new WsdlInfo(url);
System.out.println("WSDL URL is " + wsdlInfo.getWsdlName()); for(InterfaceInfo interfaceInfo : wsdlInfo.getInterfaces())
{
System.out.println("Interface name is " + interfaceInfo.getInterfaceName());
for(String ads : interfaceInfo.getAdrress())
{
System.out.println("Interface address is " + ads);
}
for(OperationInfo operation : interfaceInfo.getOperations())
{
System.out.println("operation name is " + operation.getOperationName());
System.out.println("operation request is ");
System.out.println("operation request is " + operation.getRequestXml());
System.out.println("operation response is ");
System.out.println(operation.getResponseXml());
}
}
}
}
测试结果
WSDL URL is http://webservice.webxml.com.cn/WebServices/ChinaOpenFundWS.asmx?wsdl
Interface name is ChinaOpenFundWSSoap12
Interface address is http://webservice.webxml.com.cn/WebServices/ChinaOpenFundWS.asmx
operation name is getFundCodeNameDataSet
operation request is
operation request is <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/">
<soap:Header/>
<soap:Body>
<web:getFundCodeNameDataSet/>
</soap:Body>
</soap:Envelope>
operation response is
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<soap:Header/>
<soap:Body>
<web:getFundCodeNameDataSetResponse>
<!--Optional:-->
<web:getFundCodeNameDataSetResult>
<xs:schema>
<!--Ignoring type [{http://www.w3.org/2001/XMLSchema}schema]-->
</xs:schema>
<!--You may enter ANY elements at this point-->
</web:getFundCodeNameDataSetResult>
</web:getFundCodeNameDataSetResponse>
</soap:Body>
</soap:Envelope>
operation name is getFundCodeNameString
operation request is
operation request is <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/">
<soap:Header/>
<soap:Body>
<web:getFundCodeNameString/>
</soap:Body>
</soap:Envelope>
operation response is
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/">
<soap:Header/>
<soap:Body>
<web:getFundCodeNameStringResponse>
<!--Optional:-->
<web:getFundCodeNameStringResult>
<!--Zero or more repetitions:-->
<web:string>?</web:string>
</web:getFundCodeNameStringResult>
</web:getFundCodeNameStringResponse>
</soap:Body>
</soap:Envelope>
operation name is getOpenFundDataSet
operation request is
operation request is <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/">
<soap:Header/>
<soap:Body>
<web:getOpenFundDataSet>
<!--Optional:-->
<web:userID>?</web:userID>
</web:getOpenFundDataSet>
</soap:Body>
</soap:Envelope>
operation response is
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<soap:Header/>
<soap:Body>
<web:getOpenFundDataSetResponse>
<!--Optional:-->
<web:getOpenFundDataSetResult>
<xs:schema>
<!--Ignoring type [{http://www.w3.org/2001/XMLSchema}schema]-->
</xs:schema>
<!--You may enter ANY elements at this point-->
</web:getOpenFundDataSetResult>
</web:getOpenFundDataSetResponse>
</soap:Body>
</soap:Envelope>
WSDL解析的更多相关文章
- WSDL4J解析WSDL文件方法
利用wsdl4j解析WSDL文件 工具:wsdl4j1.6 解析wsdl文件是axis1.4的服务wsdl文件 wsdl文件: <?xml version="1.0" enc ...
- java环境下wsimport编译Wsdl
使用命令提示符进行操作:首先CD至java jdk/bin目录下.先bin目录下执行以下命令即可: -----------------------------服务需求放置的位置------------ ...
- 通用的调用WebService的两种方法。(调用别人提供的wsdl)(转)
转载自:http://blog.sina.com.cn/s/blog_65933e020101incz.html1.调用WebService的Client端采用jax-ws调用WebService:流 ...
- spring WebServiceTemplate 调用 axis1.4 发布的webservice
前言: 最近在开发中需要调用对方的 webservice服务,按照现有的技术,本应该是一件很简单的事情,只需要拿到wsdl文件,生成客户端代码即可,但是,对方的webservice服务是06年用ax ...
- IOS开发笔记 - 基于wsdl2objc调用webservice
为了方便在ios下调用webserivce,找来了wsdl2objc这样一个开源的框架来解析webservice方便在ios下引用. 下面做个小例子. 1.首先是用Asp.net搭建一个测试的webs ...
- WebService概述
一.WebService介绍 什么是WebService? 一言以蔽之:WebService是一种跨编程语言和跨操作系统平台的远程调用技术. 所谓跨编程语言和跨操作平台,就是说服务端程序采用java编 ...
- 微软.NET Framework cve-2017-8759 复现
0x00 漏洞前言 FireEye公司最近发现一份恶意微软Office RTF文档,其中利用到一项SOAP WSDL解析器代码注入漏洞——编号CVE-2017-8759.该漏洞允许恶意人士在解析SOA ...
- gsoap 学习 1-由wsdl文件生成h头文件
开始前先看一下用户向导吧 http://www.cs.fsu.edu/~engelen/soap.html 中左侧点击Documentation 英语水平确实有限,有些内容可能说的不准确,敬请参考向导 ...
- gsoap开发webservice
gSOAP编译工具提供了一个SOAP/XML 关于C/C++ 语言的实现,从而让C/C++语言开发web服务或客户端程序的工作变得轻松了很多.绝大多数的C++web服务工具包提供一组API函数类库来处 ...
随机推荐
- vs2010版本注释
转:http://www.cnblogs.com/chaselwang/p/3580839.html 关于Visual Studio 20**自动添加头部注释信息 作为一个万年潜水党,不关这一篇文章技 ...
- MUI音乐播放html5+audio模块
html5+ audio 模块MUI播放音频 Audio模块用于提供音频的录制和播放功能,可调用系统的麦克风设备进行录音操作,也可调用系统的扬声器设备播放音频文件.通过plus.audio获取音频管理 ...
- select、poll和epoll的比较
一.select机制 在linux下网络通信中,经常用到select机制,这是一种异步通信的实现方式,select中提供一fd_set的数据结果,实际上是一个long类型的数组, 每一个数组元素都能与 ...
- Java-01-问题解答
问题一:Java类文件是否只能有一个公有类? 1测试代码: //信1603 李敦岳 20163520 //测试Java是否只能有一个公有类 //2017.10.2 public class Test ...
- windows10安装ubuntu16.04双系统
因为科研需要,主要在ubuntu系统中进行学习开发,介绍一下安装windows10下安装ubuntu的经验. 1.工具 u盘(或者你也可以在你的硬盘中分出一部分FAT32的硬盘空间) Easyuefi ...
- ZOJ 3780 - Paint the Grid Again - [模拟][第11届浙江省赛E题]
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3780 Time Limit: 2 Seconds Me ...
- CSS垂直导航栏
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Fata7y Ya Warda! SPOJ - DRUIDEOI 单调栈
题意:1e5个数围成一个环.现在要输出每个数左右第一个大于它的数的下标.若没有,则输出-1. 题解:单调栈板题.只是要把数据压入栈压两遍来模仿环. 具体分析:考虑一个递减的数列.要找左边最大的 ...
- h5直播
直播开发之旅 ① 状态控制: 目前我们先考虑直播的三种状态: 直播前,直播中,结束. 针对每个状态我们肯定会有不同的显示,这三种状态可以是三个页面,相互切换,或者一个页面,控制页面相关隐藏和显示. 可 ...
- SpringMVC:JSON形式输出(基于Fastjson)
在Spring3.0中,@ResponseBody标记可以将对象"封装"为JSON形式的数据,并输出,下面的例子中使用的是阿里的Fastjson JSONaz解析工具,在sprin ...