在ETL工具Spoon中调用WebService的方法:
Spoon是开源kettle的pentaho工具中data integration工具。
1. 新建转换,添加SOAP请求的"Modified Java Script Value"Step。
SOAP请求:
//Script here
var request=new XML();
request = <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="http://test.cxf.com/">
<soapenv:Header/>
<soapenv:Body>
<test:addUser>
<!--Optional:-->
<arg0>?</arg0>
<!--Optional:-->
<arg1>?</arg1>
</test:addUser>
</soapenv:Body>
</soapenv:Envelope>;
request = request.toXMLString();
将request输出。
2. 添加"HTTP Post"Step
URL中添加"http://1.1.1.1:1234/user?wsdl"
入参"Request entity field"中选择"request"(是SOAP请求步骤中输出的参数)
返回"Result fieldname"中填写"result"(返回参数名称可自己命名)
3. 添加SOAP相应的"Modified Java Script Value"Step。
SOAP相应:
//Script here
// 去除<xml ...>
result = result.replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, "");
// 将result转换为XML对象。
var response = new XML(result);
// 也可以使用下面的方式
// var response = eval(result);
var soap = response.namespace();
// 也可以
//var soap = new Namespace("http://schemas.xmlsoap.org/soap/envelope/");
var ws = response.*.*.namespace();
//也可以
//var ws = new Namespace("http://test.cxf.com/");
default xml namespace = ws;
// 获取addUserResponse节点内容
var responseBody = response.soap::Body.addUserResponse;
// 获取return节点的值
var returns = eval(responseBody.toXMLString())['return'];
Alert(returns);