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函数类库来处 ...
随机推荐
- 【CF900D】Unusual Sequences 容斥(莫比乌斯反演)
[CF900D]Unusual Sequences 题意:定义正整数序列$a_1,a_2...a_n$是合法的,当且仅当$gcd(a_1,a_2...a_n)=x$且$a_1+a_2+...+a_n= ...
- Unity3D笔记十九 持久化数据
1.PlayerPrefs类(生命周期???) 1.1 保存与读取数据 在C#中类似缓存.Cookie.Session等保存数据的,但是有点区别的是在C#中如果在取值时没有取到默认值则返回值是NULL ...
- 【转】JavaScript 事件顺序:冒泡和捕获
补充说明:这篇文章通俗易懂地讲解了冒泡和捕获原理,原文来自 ppk 大侠的 quirksmode 站点.感谢网友 hh54188 的翻译. 事件的发生顺序 这个问题的起源非常简单,假设你在一个元素中又 ...
- 170815、redis3.0安装配置
下载地址http://redis.io/download 安装步骤: 1 首先需要安装gcc,把下载好的redis-3.0.0-rc2.tar.gz 放到linux /usr/local文件夹下 2 ...
- POJ 1269 - Intersecting Lines - [平面几何模板题]
题目链接:http://poj.org/problem?id=1269 Time Limit: 1000MS Memory Limit: 10000K Description We all know ...
- 用栈来递归 模板 honoi
用栈来模拟递归的技巧 #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<vector> #include& ...
- 删除RAC集群节点
删除GRID集群节点:参考oracle database 11g RAC手册(第二版) 目前GRID集群中节点信息:[grid@node1 ~]$ olsnodesnode1node2node3nod ...
- 解决oracle12c安装报“[INS-30131]执行安装程序验证所需的初始设置失败(原因:无法访问临时位置)”方法
安装过很多次oracle,顺顺利利的,今天在新机子上安装oracle12c client过程中竟然神奇的报出一个错误: 很明显的,已经很明确的给出了安装失败的原因:无法访问临时位置!实际上,在安装数据 ...
- stack overflow underflow
Introduction to algorithms / Thomas H. Cormen...[etal.].—3rded. If we attempt to pop an empty stack, ...
- angularJS module里的'服务'
首先,为了举栗子,先写好如下的模型,控制器,html: html: <!DOCTYPE html> <html ng-app="serviceApp"> & ...