View Source

{section}
{column}

h1. Preliminary notes

This use case can only be reproduced with Talend Integration Suite.
People using Talend Open Studio can find an alternative in the use cases "Data Flow - From a job to Petals using attachments" and "Data Flow - From a job to Petals using a tBufferOutput".

h1. Rationale

Generate a data flow in a job and send it inside Petals.

The input message provides nothing.
The job's result and the generated data flow are expected in the response.
{column}

{hide-if:display=pdf}
{column:width=350px}
{panel:title=Table of contents}{toc}{panel}
{panel:title=Contributors}{contributors:order=name|mode=list}{panel}
{column}
{hide-if}
{section}

h1. Creating and exporting the job

The job to be executed performs the following actions:
# The job generates a data flow.
# This data flow is sent into Petals.

This job has no context variable.


h2. Creating the job

The job is made up of two components:
# The tRowGenerator generates the data flow.
# The tPetalsOutput makes this data flow available in Petals.

Here is the overall aspect of the job.

!JobWithTpo.jpg!

\\
Here is the schema and the generation settings for the tRowGenerator component.

!JobToPetals_tpo_trgschema.jpg!

\\
Here is the schema of the tPetalsOutput component.

!JobToPetals_tpo_tposchema.jpg!



h2. Exporting the job

Select the job and right-click it. Select *Export Job Scripts*.
In the *Export type* combo, select *Petals ESB*.
Update the target destination and let the job be exposed as a singleton.


You should have the following dialog:

!DefaultExport.jpg!

Click *Finish*.



h1. Deploying and testing in Petals


h2. Looking at the generated WSDL

In the created Petals service assembly, the most interesting thing to look at is the WSDL.
Indeed, the WSDL will determine the way the exported service will be called.

\\
The input message's description expects no parameter.

{code:lang=xml}
<xs:element name="executeJob" type="tns:executeJob" />
<xs:complexType name="executeJob">
<xs:sequence>
<xs:element minOccurs="0" name="contexts" type="tns:talendContexts" />
<xs:element minOccurs="0" name="in-attachments" type="tns:inAttachments" />
<xs:element maxOccurs="unbounded" minOccurs="0" name="in-data-bean" type="tns:inRow" />
<xs:element maxOccurs="unbounded" minOccurs="0" name="talend-option" type="xs:string" />
</xs:sequence>
</xs:complexType>

<xs:complexType name="talendContexts">
<xs:sequence>
</xs:sequence>
</xs:complexType>

<xs:complexType name="inAttachments">
<xs:sequence>
</xs:sequence>
</xs:complexType>

<xs:complexType name="inRow">
<xs:sequence>
</xs:sequence>
</xs:complexType>
{code}

\\
And the output message includes the job's result and the generated data flow.

{code:lang=xml}
<xs:element name="executeJobResponse" type="tns:executeJobResponse" />
<xs:complexType name="executeJobResponse">
<xs:sequence>
<xs:element minOccurs="0" name="talend-job-output" type="tns:talendJobOutput" />
</xs:sequence>
</xs:complexType>

<xs:complexType name="talendJobOutput">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="executionResult" nillable="true" type="ns1:stringArray" />
<xs:element minOccurs="0" name="outAttachment" type="tns:outAttachments" />
<xs:element maxOccurs="unbounded" minOccurs="0" name="outDataBean" nillable="true" type="tns:outRow" />
</xs:sequence>
</xs:complexType>

<xs:complexType name="outAttachments">
<xs:sequence>
</xs:sequence>
</xs:complexType>

<xs:complexType name="outRow">
<xs:sequence>
<xs:element name="name" type="xs:string" nillable="true" />
<xs:element name="age" type="xs:integer" nillable="true" />
</xs:sequence>
</xs:complexType>
{code}

\\
The WSDL generation has taken into account the schema of the tPetalsOutput.

{tip}
Notice that a Java *Date* type in the component's schema would have been translated to a *timestamp* (long) during the export.
{tip}


h2. Deploying and testing this new service

To test this service, you can use a tool like SoapUI.
This way, you can see what the XML messages look like.

The first thing to do is to create a service-unit for the Petals-BC-SOAP component, that exposes (consumes) our _Talend job as a service_ outside the bus.
This step is not described here. You can take a look at the Petals-BC-SOAP documentation and the Petals Studio documentation.
Just make sure the SOAP configuration uses the InOut MEP.

\\
Now, your input message (in SoapUI) should look like this:

{code:lang=xml}
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tal="http://petals.ow2.org/talend/">

<soapenv:Header/>
<soapenv:Body>
<tal:executeJob>
<!--Optional:-->
<tal:contexts/>
<!--Optional:-->
<tal:in-attachments/>
<!--Zero or more repetitions:-->
<tal:in-data-bean/>
</tal:executeJob>
</soapenv:Body>
</soapenv:Envelope>
{code}

\\
The returned message, when everything works, is:

{code:lang=xml}
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<tns:executeJobResponse
xmlns:tns="http://petals.ow2.org/talend/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<tns:talend-job-output>
<tns:executionResult>
<jaxb:item xmlns:jaxb="http://jaxb.dev.java.net/array">0</jaxb:item>
</tns:executionResult>
<tns:outAttachment/>
<tns:outDataBean>
<tns:name>onq1slKprbEZN2k</tns:name>
<tns:age>70</tns:age>
</tns:outDataBean>
<tns:outDataBean>
<tns:name>oghHxi7r85k04Nu</tns:name>
<tns:age>61</tns:age>
</tns:outDataBean>

<!-- ... -->

<tns:outDataBean>
<tns:name>JppSgHonz7d7z0h</tns:name>
<tns:age>7</tns:age>
</tns:outDataBean>
<tns:outDataBean>
<tns:name>IVDkn38bDRAAcXi</tns:name>
<tns:age>52</tns:age>
</tns:outDataBean>
<tns:outDataBean>
<tns:name>McT8WFoqX1QGCqG</tns:name>
<tns:age>50</tns:age>
</tns:outDataBean>
<tns:outDataBean>
<tns:name>bw6NIKoICJdwvXk</tns:name>
<tns:age>20</tns:age>
</tns:outDataBean>
<tns:outDataBean>
<tns:name>zMKQMzp6cpTSUN7</tns:name>
<tns:age>13</tns:age>
</tns:outDataBean>
</tns:talend-job-output>
</tns:executeJobResponse>
</soapenv:Body>
</soapenv:Envelope>
{code}

\\
Notice the XML shape.
The first child is the job's result.
If the job execution fails, the 0 is replaced by another integer, e.g. 1.
One failure reason can be, as an example, that the database is not started.

\\
The list of _outDataBean_ is made available to Petals through the tPetalsOutput.
Every _outDataBean_ has the same list of children, each child being a column in the schema of the tPetalsOutput.

Thus, the expected data schema is defined by the job, and not by the service's contract.
In fact, the service's contract is partially generated from this schema.
As said in the other use cases, it is the job's content which define what the service contract will be.