In this tutorial will see:
I've used Talend Open Studio 2.4.1 with a Java project.
Any job can be exported and called as a webservice, the webservice will simply return the “return code” given by the operating system process. Here is a very simple job that create a /tmp/now.txt file and write the current datetime inside.
Export you job as a webservice : in the Repository view, right click on the job, Export Job Scripts, Select the export type : Axis Webservice (WAR), and give an war archive name to create.
In your Apache Tomcat webapp directory, copy the war archive.
[pierrick@plegall] ~/download/apache-tomcat-5.5.26/webapps $ cp /tmp/hello_simple_0.1.war .
Tomcat will automaticaly deploy the webapp.
The URL to call the webservice is http://localhost:8080/hello_simple_0.1/services/hello_simple?method=runJob where hello_simple_0.1 is the name of the webapp deployed in Tomcat and hello_simple is the name of the job.
The return code is 0, it means that everything is OK.
We now want to simulate a problem on the job execution. For example, I create the /tmp/now.txt file as root, so that the file can't be overwritten by the webservice. Now the return code is 1, which means an error has occured.
If you want the job to return some data in the webservice, you have to use tBufferOutput component. This component does nothing when the job is called as a simple script, and outputs a SOAP answer (XML format) when the job is called as a webservice.
Let's design something pretty simple, 2 context variables {nb_lines, lastname}, tFixedFlowInput generates context.nb_lines lines with 3 columns {now, firstname, lastname}.
As in the previous example, export as webservice and copy the war archive to the Tomcat webapp directory. The job will use default values for context variables. The basic browser call of the webservice gives:
Now we want to call the webservice and overload the 2 context variables : http://localhost:8080/hello_0.1/services/hello?method=runJob&arg1=--context_param%20lastname=legall&arg2=--context_param%20nb_line=2
%20 stands for a blank space in the URL speaking language. the way to set context variable for webservice call is very near the way to set context variables for script call.
We have asked the lastname to be “plegall” and to generated 2 lines.