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函数类库来处 ...
随机推荐
- 【CF883B】Berland Army 拓扑排序
[CF883B]Berland Army 题意:给出n个点,m条有向边,有的点的点权已知,其余的未知,点权都在1-k中.先希望你确定出所有点的点权,满足: 对于所有边a->b,a的点权>b ...
- Office Online Server2016安装手册
Office Online Server2016安装手册 1.加入域 加入域,机器名为:OOS.Contoso.com 2.安装前提条件 运行powershell检查先决条件 Add-WindowsF ...
- jqGrid 中的editrules来自定义colModel验证规则
editrules editrules是用来设置一些可用于可编辑列的colModel的额外属性的.大多数的时候是用来在提交到服务器之前验证用户的输入合法性的.比如editrules:{edith ...
- [转]-[携程]-A Hybrid Collaborative Filtering Model with Deep Structure for Recommender Systems
原文链接:推荐系统中基于深度学习的混合协同过滤模型 近些年,深度学习在语音识别.图像处理.自然语言处理等领域都取得了很大的突破与成就.相对来说,深度学习在推荐系统领域的研究与应用还处于早期阶段. 携程 ...
- saltstack------安装篇
一.环境准备 系统:centos7 and centos6.8 IP 系统 172.16.1.10 centos7 172.16.1.11 centos7 172.16.1.21 centos6. ...
- Linux--抓取Appium网站命令
# 获取各命令url地址 curl http://appium.io/docs/en/commands/device/app/is-app-installed/ 2>/dev/null | gr ...
- opencv学习笔记之cvSobel 函数解析
首先,我们来开一下计算机是如何检测边缘的.以灰度图像为例,它的理论基础是这样的,如果出现一个边缘,那么图像的灰度就会有一定的变化,为了方便假设由黑渐变为白代表一个边界,那么对其灰度分析,在边缘的灰度函 ...
- Python:字符串处理函数
split() / join() 拆分和组合 #split() 通过指定分隔符对字符串进行切片(拆分),默认空格符 lan = "python ruby c c++ swift" ...
- 敌兵布阵---hud1166(线段树或者树状数组模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166 线段树中对某一点的值进行改变: #include<iostream> #includ ...
- 【Loadrunner】Error -26601: Decompression function 错误解决、27728报错解决方案
一. Error -26601: Decompression function 错误解决 Action2.c(30): Error -26601: Decompression function ...