This scenario describes a three-component Job that updates the information of a list of users to a remote database through a REST service using the HTTP POST method. When executed, the Job displays the client-server message exchange information on the Run console.
The user information to be updated to the server is stored in a CSV file, which looks like the following:
id;first_name;last_name 1;John;Smith 2;Martin;Reagan 3;James;White 4;Jenny;Jackson 5;Robert;Thomson
If you are a Talend Open Studio for ESB user, create a Job
as described in Scenario 3: REST service accepting HTTP POST requests and run the Job
as a REST server to expose a REST service that accepts HTTP POST requests. Upon
execution of the Job, the console displays the service implementation information,
including the service endpoint URL, which is
this example. If you enter
http://localhost:8045/users?_wadl in your Web
browser, you should see the service definition information like the following:
If you are not a Talend Open Studio for ESB user, then you need to get the service-related information from your REST service provider including the URL, the resource path, and the data structure, and make necessary modifications in the scenario configurations accordingly.
Create a Job and add the following components by typing their names in the design workspace or drop them from the Palette:
tFileInputDelimited, to read user information of a local file,
tXMLMap, to adapt the input structure to the REST service structure, and
tRESTClient, used to call the REST service to send data to the remote database.
Connect the tFileInputDelimited to the tXMLMap using a Row > Main connection.
Connect the tXMLMap to the tRESTClient using a Row > Main connection, and give the output flow a name, request in this example.
Label the components to best describe the actions to perform.
Configuring the input data and the structure mappings
Double-click the tFileInputDelimited component to open its Basic settings view.
Specify the input file in the File name field, fill the Header field with 1 to skip the header row, and keep the rest parameters as they are.
Click the [...] button next to Edit schema to open the [Schema] dialog box, and edit the input schema as follows:
id, type Integer, 2 characters long, set as the key column
first_name, type String
last_name, type String
Double-click the tXMLMap component to open the Map Editor.
Rename the root node in the output table: right-click the node, select Rename from the contextual menu, and specify a new name in the pop-up dialog box, user in this example.
Select all the three columns in the input table and drop them onto the user node, and select the Create as sub-element of target node option from the pop-up dialog box to set these columns as sub-elements of the user node. When done, click OK to validate the mappings and close the Map Editor.
Configuring the service call
Double-click the tRESTClient component to open its Basic settings view.
Fill the URL field with the URI location where the REST service is accessible,
"http://localhost:8088/users"in this example.
In the Relative Path field, enter the resource path,
"/post/" + row1.id+ "/" + row1.first_name + "/" + row1.last_namein this example. This will send the data from the input row to the server end via the resource path.
From the HTTP Method list, select GET to send an HTTP request for retrieving the existing records.
From the Accept Type list, select the type the client end is prepared to accept for the response from the server end, XML.
In the Advanced settings view of the tRESTClient component, select the Log messages check box to log the message exchange information with the server.
Leave the rest of the settings as they are.