To create a data service using the Integration perspective of Talend Studio, you have to design a data service Job that addresses all of the different sources and targets required for data integration processes and combines them with Web services.
The Integration perspective of Talend Studio provides the Services item to help create a data service Job from a given WSDL defined in the Repository tree view.
The following sections present a scenario to illustrate how to create a WSDL file and the data service Jobs to provide and consume a Web service.
To illustrate the way Talend Studio combines data integration with Web services, find below a real-life example scenario. In this scenario, you will define an airport Web service by creating a WSDL file, send a request to this Web service to get country codes and retrieve the response from the Web service for a further use. To do this, you need to create two data service Jobs:
one Job that will give access to the Web service via a WSDL, to send a request and retrieve the response - the data service provider.
one Job that will actually send data to request the Web service - the data service consumer.
From the Services item of the Repository tree view, you are able to define the Web service of interest by creating a WSDL file or by importing an existing WSDL file.
In this scenario, we will create a new WSDL file to define the airport Web service. For further information about how to create a WSDL file from scratch, see How to create a Service and How to edit a WSDL file.
To define the airport Web service, proceed as follows:
On the Repository tree view, right-click the Services node and from the contextual menu, select Create Service.
In the pop-up wizard, enter the information corresponding to the fields you need to complete. In this scenario, enter airport in the Name field. Click Next to go to the next step.
Select the Create new WSDL option.
Click Finish to validate this creation.
The service opens in the design workspace with a basic WSDL skeleton, which contains one service, one binding and one port type of one operation.
Right-click the port airportPort in the WSDL skeleton and select Show properties.
In its Properties view, define its name in the Name field, for example, airportSoap.
In the Address field, specify the address where you want the service to be published, for example,
Click the binding in the WSDL skeleton.
In its Properties view, define the name of the binding, for example airportSoap.
Click the portType airportPortType in the WSDL skeleton.
In its Properties view, define the name of the portType, for example airportSoap.
Click the operation airportOperation in the WSDL skeleton.
In its Properties view, set its name as getAirportInformationByISOCountryCode.
Save the WSDL file. We will use it to build the Web service.
Then the newly defined Web service with exclamation icon displays under the Services node of the Repository view. The exclamation icon means that this defined Web service is not yet used.
In this scenario, the data service provider uses the tESBProviderRequest and the tESBProviderResponse components to create the access to the airport Web service and uses the tXMLMap component to join the airport data provided by a given MySQL database into the request-response main flow for publication. The database data is loaded by the tMysqlInput component.
To create this data service provider, proceed as follows:
Under the Services node of the Repository tree view, right-click the operation of the newly defined airport Web service and from the contextual menu, select Assign Job. In this scenario, this operation is getAirportInformationByISOCountryCode.
The [Assign Job] wizard opens. Select the Create a new Job and Assign it to this Service operation and click Next.
In the [New Job] view of the wizard, the Job to be created is already named automatically, so simply click Finish.
A draft Job is opened on the workspace.
In the draft Job, a tESBProviderRequest and a tESBProviderResponse are already selected and configured. tESBProviderRequest will send a request to the specified Web service and tESBProviderResponse will send back the response corresponding to the request. These two components can be found in the ESB group of the Palette.
To create the data service provider Job, proceed as follows:
Right-click tESBProviderRequest, hold and drag to tESBProviderResponse to link these two components.
Drop a tXMLMap in the middle of the row link from the Palette and in the pop-up window, name the output link as, for example, airport_response. This will also be used as the name of the output table in the map editor of tXMLMap. For further information, see Designing a Job.
Then your data service provider Job should look like:
The red cross icon prompts you to configure the tXMLMap component.
From the Db Connections node of the Repository tree view, drop the connection to the airport data, the airport database table in this example, onto the workspace. Then the [Components] wizard is opened.
For further information about how to create a database connection in the Repository, see Centralizing database metadata.
Double click tMysqlInput in this wizard to create the corresponding component on the workspace and link it to tXMLMap.
In this scenario, the airport data is composed of airport names and the corresponding country codes. The following figure presents the database table in use.
Till now, you need only to configure tXMLMap as the other components are already configured automatically.
To to this, perform the following operations:
On the workspace, double click tXMLMap to open its editor. At this moment, the editor should look like:
In the main row table of the input flow side (left), right-click the column name payload and from the contextual menu, select Import from Repository. Then the [Metadatas] wizard is opened. For further information, see Using the document type to create the XML tree.
Expand the File XML node in this wizard, select the schema of the request side and click OK to validate this selection. In this example, the schema is getAirportInformationByISOCountryCode.
Do the same to import the hierarchical schema for the response side (right). In this example, this schema is getAirportInformationByISOCountryCodeResponse.
Then to create the join to the lookup data, click the CountryAbbrviation node in the main row of the input side (left), hold and drop it onto the Exp.key column of the lookup flow, corresponding to the id row.
On the table representing the lookup flow, click the wrench icon on the up-right corner to open the setting panel.
Set Lookup Model as Reload at each row, Match Model as All matches and Join Model as Inner join.
For further information about Lookup Model, see Handling Lookups.
For further information about Match Model, see How to use Explicit Join.
For further information about Join Model, see How to use Inner Join.
A step-by-step tutorial related to this Join topic is available on the Talend Technical Community Site. For further information, see http://talendforge.org/tutorials/tutorial.php?language=english&idTuto=101.
Do the same to open the setting panel on the output side (right) and set the All in one option as true. This ensures that only one response is returned every time when one request is sent, as, otherwise, the airport data from the given database may provide several airports, thus several responses, to each country code that you send as one request.
For further information about All in one, see How to output elements into one document
Click the name row in the lookup flow (left), hold and drop it onto the Expression column corresponding to the tns:getAirportInformationByISOCountryCodeResult node in the XML tree view of the output flow (airport_response in this example).
Then your tXMLMap editor should look like:
In the real-world practice, you can as well add hierarchical data for lookup. For further information, see Talend Components Reference Guide.
Click OK to close the editor and validate this configuration.