Search code examples
xmlresttalend

Talend: tRESTClient returns empty response after delete


I'm new to Talend. I use 5.6.1 Talend Studio. I'm sending DELETE request using tRESTClient to a service. I expect to get xml response with error codes.

In client log I can see xml that I need, but both body and string values in response row are empty. tRESTClient log:

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>

I tried to add payload and other fields to clients output row, but with no results. tLogRow after client:

|200|||

XML is needed for further processing and plain status code is not enough. POST and GET requests work fine, I'm getting response data in string or body fields. When using DELETE service with tools like SOAP UI everything is also fine, I receive expected XML.

Can any one suggest why I'm facing this issue and how It can be resolved?

Update:

Playing around with debugger i found out that responseDoc_tRESTClient_1 that is used to produce body or string for output row is always null. It is initialized with null at beginning and is never changed.

Looks like problem is with the generated code for service invocation. For example if we send GET request it produces following code:

responseDoc_tRESTClient_1 = webClient_tRESTClient_1.get(responseClass_tRESTClient_1);

If we send DELETE request it produces following code:

webClient_tRESTClient_1.invoke("DELETE", requestBody_tRESTClient_1);

I saw that webClient has also method .delete() that returns Response as .get(...) method. Is there a way to force Talend use .delete() method instead of .invoke() ?


Solution

  • I managed to find solution for this issue.

    I replaced tRESTClient component with tJavaRow that creates cxf client, calls service and adds response to output row.

    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;
    

    Imports:

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

    Talend Studio might throw NoClassDefFoundError, but in runtime job works well.

    But I'm pretty sure there should be better solution.