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函数类库来处 ...
 
随机推荐
- 【转】Hudson插件Email-Ext邮件模板时间格式化的解决方法
			
原文地址:http://www.cnblogs.com/haycco/archive/2012/03/20/3031397.html 最近因对Hudson版本进行了升级为2.2.0,所以各方面都在搞项 ...
 - jenkins中windows节点设置开机自启动slave-agent
			
做web UI自动化时,为了提高效率,用了多台windows节点来跑自动化,但slave-agent每次在关机后都得手工启动,麻烦,网上看到了一系列说启动任务中,感觉还是不考虑,这里使用windows ...
 - 【转】python中json.loads与eval的区别
			
JSON有两种结构: “名称/值”对的集合(A collection of name/value pairs).不同的语言中,它被理解为对象(object),纪录(record),结构(struct) ...
 - 第一个springMVC入门程序
			
先看下项目结构 要加载与spring相关的包 HelloController.java(注意是在包controller下) package controller; import org.springf ...
 - Ubuntu16.04双网卡主备配置
			
前几日写了一篇Ubuntu14.04双网卡主备配置,没成想变化总是这么快,今日安装某软件,提示最匹配的ubuntu版本是16.04,作为一个码农能有什么办法,只能不断去适应变化.拥抱变化. 首先16. ...
 - ubuntu下中文乱码解决方案(全)
			
转自 http://www.cnblogs.com/end/archive/2011/04/19/2021507.html 1.ibus输入法 Ubuntu 系统安装后已经自带了ibus输入法,在 ...
 - Redis的启动过程
			
本文主要介绍Redis启动加载过程,总体上可以分为如下几步: 1. 初始化全局服务器配置 2. 加载配置文件(如果指定了配置文件,否则使用默认配置) 3. 初始化服务器 4. 加载数据库 5. 网络监 ...
 - IE new Date NaN 问题
			
var ctime = "2015/1/7 10:35"; ctime = ctime.replace(/-/g,"/"); //为了兼容IE var date ...
 - 开放思源 专注高效 HPE&msup软件技术开放日回顾
			
7月22日,HPE和msup联合举办的软件技术开放日在上海浦东新区张江高科技园区召开,主.分会场共邀请HPE 13 名测试.质量.大数据专家分享技术实践与经验,与180多名测试总监一起拆解质量保障及大 ...
 - Python面向对象:获取对象信息
			
学习笔记内容简介: 获取对象属性和方法的函数: type(): 判断对象类型 isinstance() : 判断class的类型 dir() : 获得一个对象的所有属性和方法 把属性和方法列出来是不够 ...