Question

My Talend Job has the following structure:

  • tREST component that executes a POST HTTP Request, and receives a XML file.

  • tExtractXMLField component that reads a tag from that XML file, like:

Now, I want to save all the values from the tagX, and then access them. For each value of the tagX, I will perform a HTTP POST with that value in the body. How can I do that?

Thanks

Was it helpful?

Solution

You need a component called tHttpRequest. But this component doesn't allow to be connected to row flows. But there's a way to accomplish.

Let's say you extracted your tagX field and put the value on a String field called 'tagX' you fed to an outgoing connection. You then need the component 'tFlowToIterate' to convert a row connection to a iterate connection. Look the iterate connection as a kind of signal that doesn't contain data; it's triggered at each incoming iteration. This subjob below calls the tJava code (which in turn prints 'hello world' on console) for every row incoming from tExtractXMLField:

tFlowToIterate Now the magic. Inside the parameters of tFlowToIterate you can define one or more global variables fed with fields from the incoming connection. The example above set the global var foo with the value of the field customer of the connection row2:

tFlowToIterare parameters

This variable is now accessible everywhere in your Talend job using (String)globalMap.get("foo"). Be careful to cast to the proper type, as globalMap is a Object-only collection.

To parametrize your HTTP post call, you just need a tHttpRequest component with the variable you just set:

parametrized tHttpRequest

Now it's up to you to handle tHttpRequest output (a single big String field with the entire response). Remember that rows in in input, when converted to Iterate signal, lost their data (the fields you saved into the globalMap don't technically own to the flow anymore) but the total number is unchanged. So, if you have, let's say, 4 incoming rows, you will trig the Iterate signal 4 times, causing the involved globalMap variables to be refreshed and tHttpRequest component to make 4 (parametrized) http requests automatically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top