kettle 批量调用 http://10.84.16.166:9191/NotifyGT/services/Service?wsdl
时间: 2025-07-29 11:33:03 浏览: 4
<think>我们面对的是一个WSDL格式的WebService,通常这是SOAP服务。在Kettle中调用SOAP服务与调用RESTAPI有所不同,主要步骤包括:1.准备请求参数(根据WSDL定义的接口结构生成SOAP请求体)2.使用HTTPPOST方法发送SOAP请求3.解析SOAP响应(XML格式)步骤详解:1.**获取WSDL并分析接口结构**首先,我们需要分析提供的WSDL(http://10.84.16.166:9191/NotifyGT/services/Service?wsdl)来确定要调用的方法及其参数结构。可以使用浏览器打开该WSDL链接查看,或者使用SoapUI等工具。2.**准备输入数据源**假设我们有一批需要调用的数据,可以来自文件或数据库。例如,一个CSV文件,每行包含一个请求所需的参数。3.**生成SOAP请求体**在Kettle中,我们可以使用“生成记录”或“获取数据”步骤来获取参数,然后通过“添加常量”或“拼接字段”构建SOAP请求的XML主体。注意:SOAP请求需要符合特定的格式,包括SOAPEnvelope、Header(如果有)和Body。4.**使用HTTPClient步骤发送请求**配置HTTPClient步骤:-URL:通常是WSDL地址去掉?wsdl部分,即:http://10.84.16.166:9191/NotifyGT/services/Service-方法:POST-请求头:Content-Type设置为text/xml;charset=utf-8,同时可能需要SOAPAction头(具体值查看WSDL,通常在WSDL中有定义)-请求体字段:选择我们构建好的XML请求字段5.**解析SOAP响应**使用“XML解析”步骤(XPath)来解析返回的XML响应,提取所需数据。6.**错误处理和结果输出**具体步骤示例:假设我们要调用的方法名为`notify`,它有一个参数`message`。那么一个SOAP请求可能如下:```xml<soapenv:Envelopexmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"xmlns:ser="http://service.ws.notifygt.example.com/"><soapenv:Header/><soapenv:Body><ser:notify><message>${MESSAGE}</message></ser:notify></soapenv:Body></soapenv:Envelope>```在Kettle中的实现流程:```mermaidgraphLRA[参数输入]-->B[构建SOAP请求]B-->C[HTTPClient]C-->D[解析XML响应]D-->E[输出结果]```详细步骤:1.**输入步骤**:例如“CSV文件输入”,读取包含消息内容的文件,假设字段名为`MESSAGE`。2.**构建SOAP请求**:使用“添加常量”步骤来构建SOAP请求的框架,然后通过“字符串替换”或“拼接字段”将参数插入到XML中。或者使用“JavaScript”步骤来构建整个XML字符串。例如,在“JavaScript”步骤中:```javascriptvarsoapBody="<soapenv:Envelopexmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'xmlns:ser='http://service.ws.notifygt.example.com/'>"+"<soapenv:Header/>"+"<soapenv:Body>"+"<ser:notify>"+"<message>"+MESSAGE+"</message>"+"</ser:notify>"+"</soapenv:Body>"+"</soapenv:Envelope>";```3.**HTTPClient步骤**:-URL:http://10.84.16.166:9191/NotifyGT/services/Service-方法:POST-请求头:添加两个头部:-Content-Type:text/xml;charset=utf-8-SOAPAction:""(具体值需要查看WSDL,如果WSDL中未指定,可以留空或用双引号)-请求体字段:选择上一步创建的`soapBody`字段4.**解析响应**:使用“XML解析”步骤(或者“XPath解析”步骤)解析返回的XML。假设返回的响应结构如下:```xml<soap:Envelope><soap:Body><ns:notifyResponse><return>Success</return></ns:notifyResponse></soap:Body></soap:Envelope>```我们可以使用XPath表达式:`/soap:Envelope/soap:Body/ns:notifyResponse/return`来提取结果。注意:需要定义好命名空间前缀映射(在步骤中设置)。5.**输出**:将解析的结果写入文件或数据库。注意事项:-由于是批量调用,需要控制并发量,避免压垮服务端。可以在HTTPClient步骤中设置“每批请求数”或使用“阻塞步骤”进行控制。-错误处理:配置HTTPClient步骤的错误处理连接,捕获HTTP错误或响应错误,记录失败的请求。-认证:如果服务需要认证,可以在HTTPClient步骤中添加基本认证或通过SOAPHeader传递认证信息。示例转换(伪代码):```javascript//转换结构{"steps":[{"name":"csv_input","type":"CSVFileInput","file":"messages.csv","delimiter":","},{"name":"js_build_soap","type":"ScriptValueMod","script":"varsoapBody=...;","fields":["soapBody"]},{"name":"http_client","type":"HTTPClient","url":"http://10.84.16.166:9191/NotifyGT/services/Service","method":"POST","headers":[{"name":"Content-Type","value":"text/xml;charset=utf-8"},{"name":"SOAPAction","value":"\"\""}],"bodyField":"soapBody","resultFieldName":"response"},{"name":"xpath_parser","type":"XPathParse","field":"response","xpath":"/soap:Envelope/soap:Body/ns:notifyResponse/return","namespaces":[{"prefix":"soap","uri":"http://schemas.xmlsoap.org/soap/envelope/"},{"prefix":"ns","uri":"http://service.ws.notifygt.example.com/"}],"resultField":"result"},{"name":"text_output","type":"TextFileOutput","file":"results.txt","fields":["MESSAGE","result"]}],"hops":[{"from":"csv_input","to":"js_build_soap"},{"from":"js_build_soap","to":"http_client"},{"from":"http_client","to":"xpath_parser"},{"from":"xpath_parser","to":"text_output"}]}```由于实际WSDL中定义的方法和命名空间可能不同,请根据实际情况调整。相关问题:1.如何根据WSDL确定SOAP请求的具体格式?2.在Kettle中如何处理SOAP调用的命名空间问题?3.如果WebService需要WS-Security认证,在Kettle中如何配置?4.如何提高Kettle批量调用WebService的性能?</think>### Kettle 批量调用 Web Service API 实现方案(针对 WSDL 服务)
以下是针对您提供的 WSDL 服务地址(`http://10.84.16.166:9191/NotifyGT/services/Service?wsdl`)的完整实现指南。由于这是 SOAP 服务而非 REST API,需要特殊处理 WSDL 结构和 SOAP 消息。
#### 核心实现步骤
```mermaid
graph TD
A[参数输入] --> B[Web Service Lookup]
B --> C[XML 请求构建]
C --> D[HTTP Post]
D --> E[XML 响应解析]
E --> F[结果输出]
```
1. **准备输入数据源**
使用 `表输入` 或 `CSV文件输入` 准备批量参数:
```sql
/* 表输入示例 */
SELECT request_id, param1, param2 FROM batch_requests
```
2. **配置 Web Service Lookup**
关键配置项:
- WSDL 地址:`http://10.84.16.166:9191/NotifyGT/services/Service?wsdl`
- 操作名称:根据 WSDL 定义确定(如 `notifyGT`)
- 输入字段映射:将输入参数映射到 SOAP 请求元素
3. **构建 SOAP 请求**
使用 `XML Join` 或 `Add XML` 步骤构建符合规范的 SOAP 消息:
```xml
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns:notifyGT xmlns:ns="http://service.notifygt.example">
<param1>${param1}</param1>
<param2>${param2}</param2>
</ns:notifyGT>
</soap:Body>
</soap:Envelope>
```
4. **HTTP POST 调用**
在 `HTTP Post` 步骤中配置:
```properties
URL = http://10.84.16.166:9191/NotifyGT/services/Service
Headers = Content-Type: text/xml; charset=utf-8
SOAPAction = "" # 根据WSDL确定具体值
```
5. **解析 XML 响应**
使用 `Get XML Data` 步骤提取结果:
```xpath
/soap:Envelope/soap:Body/ns:notifyGTResponse/return
```
配置命名空间:
| 前缀 | URI |
|------|-----|
| soap | http://schemas.xmlsoap.org/soap/envelope/ |
| ns | http://service.notifygt.example |
6. **错误处理机制**
添加 `写日志` 步骤捕获异常:
```javascript
// 在JavaScript步骤中检查HTTP状态码
if (http_status_code >= 400) {
writeToLog("Error: " + response_body);
}
```
#### 完整转换示例
```xml
<!-- kettle 转换片段 -->
<step>
<name>WebServiceLookup</name>
<type>WebServiceLookup</type>
<wsdl>http://10.84.16.166:9191/NotifyGT/services/Service?wsdl</wsdl>
<operation>notifyGT</operation>
<requestField>soap_request</requestField>
</step>
<step>
<name>HTTPPost</name>
<type>HTTPPOST</type>
<url>http://10.84.16.166:9191/NotifyGT/services/Service</url>
<headers>
<header>
<name>Content-Type</name>
<value>text/xml; charset=utf-8</value>
</header>
<header>
<name>SOAPAction</name>
<value>""</value>
</header>
</headers>
<fieldName>soap_request</fieldName>
<resultFieldName>response_xml</resultFieldName>
</step>
<step>
<name>ParseResponse</name>
<type>GetXMLData</type>
<field>xpath:/soap:Envelope/soap:Body/ns:notifyGTResponse/return</field>
<namespaces>
<namespace>
<prefix>soap</prefix>
<uri>http://schemas.xmlsoap.org/soap/envelope/</uri>
</namespace>
<namespace>
<prefix>ns</prefix>
<uri>http://service.notifygt.example</uri>
</namespace>
</namespaces>
</step>
```
#### 性能优化技巧
1. **并发控制**
在 `HTTP Post` 步骤设置:
```properties
每批请求数 = 20 # 根据服务端承受能力调整
```
2. **连接复用**
在 `kettle.properties` 中启用连接池:
```properties
http.connection.max.total=100
http.connection.timeout=30000
```
3. **重试机制**
使用 `执行SQL脚本` 记录失败请求:
```sql
INSERT INTO failed_requests(request_id, retry_count)
VALUES (?, 1) ON CONFLICT DO UPDATE SET retry_count = retry_count + 1
```
#### 安全配置
```xml
<!-- 添加WS-Security头示例 -->
<soap:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>${USERNAME}</wsse:Username>
<wsse:Password>${PASSWORD}</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
```
#### 注意事项
1. 使用前通过 SoapUI 验证 WSDL 有效性
2. 批量调用前确认服务的每秒请求限制(Rate Limit)
3. 建议添加 `延迟步骤` 控制调用频率:`$$ \text{延迟时间} = \frac{3600}{\text{最大允许调用次数}} \text{ 秒} $$`
4. 使用 `过滤步骤` 跳过已处理的请求
> 实际命名空间和操作名称需根据 WSDL 具体内容调整[^1]。建议先用 `Web Service Lookup` 步骤自动生成请求模板[^2]。
阅读全文
相关推荐




















