Search code examples
restintegrationtalend

Talend tREST component cookie extract


Providing additional context in addition to the answer below that helped me get this done:

enter image description here

  1. tRowGenerator_1 - Used to simply allow tMap_1 to be used, nothing special here
  2. tMap_1 - Here I build the payload to be used in the call and pass it to a variable in tRESTClient_1 called string. This is what I was missing. enter image description here
  3. tRESTClient_1 - Perform the post to fetch an auth token, nothing special here either.
  4. We now need to unpack the cookie returned in the response to make subsequent calls.
String str[] = ((java.util.Map)globalMap.get("tRESTClient_1_HEADERS")).get("Set-Cookie").toString().replace("[","").replace("]","").replace(",",";").split("; ");

String out = "";

for(int index = 0; index < str.length; index++){
    if(str[index].startsWith("JSESSIONID=") || str[index].startsWith("CSRFToken=") || str[index].startsWith("SecurityTokenURL=")){
        out = out + str[index] + "; ";
    }
};

globalMap.put("cookie", out);

Assign the elements of the cookie to variable called cookie. 5. Pass the cookie into your next REST call: enter image description here

I hope this helps along the next person who needs a little assistant.

I'm working on a pretty straight forward proof of concept to log-in via a POST action using Talend.

From the application side, I use a POST with a body to then receive a cookie. However, I'm at a loss for how to get the cookie details from the response of the endpoint.

In my forum lurking, there appear to be two approaches: one using tREST, the other using tRESTClient.

Using tREST, I can successfully post to the endpoint, but I can not appear to retrieve the response header or body: Talend Job Setup with tREST

This is the tREST component properties: tREST component setup

The cookie passed from this call needs to be recycled into subsequent calls in order for them to authenticate.

I'm hoping to understand how to get the Cookie out and passed along, either with tREST or tRESTClient. My issue with tRESTClient is that I do not have a way to pass the body to that component.

Any thoughts?


Solution

  • On your last point - you can pass the body to tRestClient by having a flow going into tRestClient. That flow can have a "string" field containing the body in json format, and that field will need to map to the "string" column in the component input schema. If, in your case, you do not already have a flow containing the body, you can generate it by using the tFixedFlowInput component.