Talend:删除后tRESTClient返回空响应

时间:2015-05-18 15:37:03

标签: xml rest talend

我是Talend的新手。我使用5.6.1 Talend Studio。我正在使用tRESTClient向服务发送DELETE请求。我希望得到带有错误代码的xml响应。

在客户端日志中,我可以看到我需要的xml,但响应行中的正文和字符串值都是空的。 tRESTClient日志:

ID: 1
Response-Code: 200
Encoding: ISO-8859-1
Content-Type: application/xml
Headers: 
{Content-Length=[492], 
content-type=[application/xml], 
Date=[Mon, 18 May 2015 15:02:24 GMT], 
Server=[Apache-Coyote/1.1]}
Payload: 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns1:Response xmlns:ns1="..." xmlns:ns2="...">
    <ns1:IsSuccess>false</ns1:IsSuccess>
    <ns1:ErrorList>
        <ns2:Error>
            <ns2:Code>80</ns2:Code>
            <ns2:Description>Can't find service</ns2:Description>
            <ns2:Severity>error</ns2:Severity>
        </ns2:Error>
    </ns1:ErrorList>
</ns1:Response>

我尝试将有效负载和其他字段添加到客户端输出行,但没有结果。 tLogRow在客户端之后:

| ||| 200

进一步处理需要XML,而普通状态代码还不够。 POST和GET请求工作正常,我在字符串或正文字段中获得响应数据。当使用像SOAP UI这样的工具使用DELETE服务时,一切都很好,我收到了预期的XML。

任何人都可以建议我为什么要面对这个问题以及如何解决这个问题?

更新

使用调试器我发现用于为输出行生成主体或字符串的responseDoc_tRESTClient_1始终为null。它在开始时用null初始化,永远不会改变。

看起来问题在于生成的服务调用代码。例如,如果我们发送GET请求,它会生成以下代码:

responseDoc_tRESTClient_1 = webClient_tRESTClient_1.get(responseClass_tRESTClient_1);

如果我们发送DELETE请求,它会生成以下代码:

webClient_tRESTClient_1.invoke("DELETE", requestBody_tRESTClient_1);

我看到webClient还有方法.delete(),它将Response返回为.get(...)方法。有没有办法强制Talend使用.delete()方法代替.invoke()

1 个答案:

答案 0 :(得分:1)

我设法找到了解决这个问题的方法。

我用tJavaRow替换了tRESTClient组件,它创建了cxf客户端,调用服务并将响应添加到输出行。

WebClient client = WebClient.create(context.serviceFullUrl);
client.path("rest/path/"+in1.serviceId);
client.accept("application/xml");
Response response = client.delete();        
String r = response.readEntity(String.class);

output_row.statusCode = response.getStatus();
output_row.string = r;
output_row.body = null;

进口:

import javax.ws.rs.core.Response;
import org.apache.cxf.jaxrs.client.WebClient;

Talend Studio可能会抛出NoClassDefFoundError,但在运行时工作效果很好。

但我非常确定应该有更好的解决方案。

相关问题