Export a job as webservice

In this tutorial will see:

  • how to create a job to be deployed as a webservice, with or without output data and context variables
  • how to export a job as a webservice
  • how to call it from your browser, with context variables
  • how to call it from another job, with context variables

I've used Talend Open Studio 2.4.1 with a Java project.

First glimpse

Create the simplest job

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 and deploy

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.

Call the webservice from your browser

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.


Advanced "webservice" job

Create a "webservice" oriented job

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}.

:doc:export_as_webservice-01.png :doc:export_as_webservice-02.png

:doc:export_as_webservice-03.png :doc:export_as_webservice-04.png

Export, deploy and call

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.


Call the webservice from a job


Even more interesting, it is possible to call a job exported as webservice in another job. tWebServiceInput is our friend.


We ask to output 5 lines in a tLogRow (table display mode).


doc/export_as_webservice.txt · Last modified: 2011/12/17 03:52 (external edit)
Recent changes RSS feed Driven by DokuWiki