tRESTRequest
Receives GET/POST/PUT/PATCH/DELETE requests from the clients on the server
end.
tRESTRequest accepts the HTTP and/or HTTPS
requests from the clients and supports GET, POST, PUT, PATCH and DELETE HTTP
methods.
To enable the HTTPS support, you have to generate a keystore
and add some HTTPS security configuration properties in the
org.ops4j.pax.web.cfg
file of your Runtime container before deploying the service on
it. For more information, see the
Talend ESB Container Administration
Guide.
tRESTRequest Standard properties
These properties are used to configure tRESTRequest running in the Standard
Job framework.
The Standard
tRESTRequest component belongs to the ESB family.
This component is relevant only when used with one of the
Talend
solutions with ESB, as it should be used with the Service Repository node and the Data Service creation related wizard(s).
Basic settings
Initialize from OAS/Swagger 2.0 API |
Click […] to |
REST Endpoint |
Fill this field with the URI location The default port is different depending on the build type or where you
run the service:
|
REST API Mapping |
Click the [+] button beneath the mapping table to
Output Flow: Click The schema is not mandatory, so if you do Add a schema with the name body to get the request body of If you specify URI parameters in the
output flow schema, you might need to define what type of parameter it is in the Comment field of the schema. By default, if you leave the Comment field empty, the parameter is considered as a Path parameter. Below is a list of supported Comment values:
Note:
We recommend you to set the
HTTP Verb: Select
URI pattern: Fill
Consumes: Select
Produces: When
Streaming: Select |
Use Service Locator | Select this check box to enable the Service Locator. It maintains the availability of the service to help meet demands and service level agreements (SLAs). Specify the Service namespace and the Service name in the corresponding fields. |
Use Service Activity Monitor |
Select this check box to enable the Service Activity Monitor. It captures events and stores this information to facilitate in-depth analysis of service activity and track-and-trace of messages throughout a business transaction. This can be used to analyze service response times, identify traffic patterns, perform root cause analysis and more. |
Use Authentication (ESB |
Select this check box to enable the
|
Use |
Select this check box to enable For more information about the |
Use Business |
Select this check box to enable the If this option is not enabled on the |
Advanced settings
Log messages | Select this check box to log the message exchange between the service provider and the consumer. |
Wrap JSON Request | Select this check box to wrap the JSON request with a root element. |
Convert JSON values to String in response |
Select this check box to convert the JSON values to string format in the response. |
Service Locator Customer Properties |
This option appears when Use Service Locator is enabled in the Basic settings tab. Click [+] to add as many properties as needed to the table. Enter the name and the value of each property in the Property Name field and the Property Value field respectively to identify the service. |
Service Activity Customer Properties |
This option appears when Use Service Activity Monitor is enabled in the Basic settings tab. Click [+] to add as many properties as needed to the table. Enter the name and the value of each property in the Property Name field and the Property Value field respectively to identify the service. |
Expose Swagger specification |
This option appears when tRESTRequest is used as a service provider. Select this If the Job is running in the Studio, the Swagger If the Job is deployed in Talend Runtime, the Swagger |
Include Documentation into Swagger |
This option appears when tRESTRequest is used as a service provider and the For more information about the Documentation tab, see Talend Studio User Guide. |
tStatCatcher |
Select this check box to gather the Job |
Global Variables
Global Variables |
NB_LINE: the number of rows processed. This is an After
URI: the URI of the REST request. This is a Flow variable
URI_BASE: the base URI of the REST request. This is a
URI_ABSOLUTE: the absolute URI of the REST request. This
HTTP_METHOD: the http method. This is a Flow variable and
ATTACHMENT_HEADERS: the attachment headers from the REST
ATTACHMENT_FILENAMES: the attachment filenames from the
PRINCIPAL_NAME: the principal name of the REST request.
CORRELATION_ID: the correlation ID by which chained
ERROR_MESSAGE: the error message generated by the A Flow variable functions during the execution of a component while an After variable To fill up a field or expression with a variable, press Ctrl + For further information about variables, see |
Usage
Usage rule |
This component covers the possibility The tRESTRequest component should be used |
Limitation |
Using context variables for dynamic |
Using a REST service to accept HTTP GET requests and send responses
This scenario applies only to Talend Open Studio for ESB, Talend Data Services Platform and Talend Data Fabric.
This scenario describes the process of accepting an HTTP request from the client,
processing it and sending the response back.
Configuring the tRESTRequest component
-
Drop the following components from the Palette onto the design workspace: a tRESTRequest, two tXMLMap and
two tRESTResponse. -
Double-click tRESTRequest in the design
workspace to display its Basic settings
view. -
Fill the REST Endpoint field with the URI
location where the REST-ful web service will be accessible for requests. For
example, “http://192.168.0.235:8088/user”.Note:If you want your service to be available on both HTTP and HTTPS, fill the
field with a relative path. For example, if you type in “/test”, your service will be available on both
http://<DefaultHTTPEnpointAddress>/test and https://<DefaultHTTPSEnpointAddress>/test, provided that
you have configured your Runtime container to support HTTPS. For more
information, see the Talend ESB Container
Administration Guide. -
Click the [+] button to add one line in the
REST API Mapping table. -
Select the newly-added line and click the […] button in the Output Flow
column to add a schema for the output flow.In this scenario, the output flow will be named as
GetOneUser.Then click the [+] button to add a new line
id to the schema in the dialog box. - Click OK to save the schema.
- Select GET from the list in the HTTP Verb column.
-
Fill the field in the URI Pattern column with
"/{id}/"
. -
In the same way, add another line in the REST API
Mapping table and name this schema GetUserNumber. Add a line string of String type to the
schema. Enter query in the Comment field to get the number parameter in the
request.Select GET from the list in the HTTP Verb column. Fill the field in the URI Pattern column with
"/number"
.
Configuring the first tXMLMap component
-
Connect tRESTRequest to a tXMLMap using the Row > GetOneUser
connection. -
Double-click tXMLMap in the design workspace
to open the Map Editor. -
Click the [+] button on the top right to add
an output and name it as ResponseUsers. -
Click the [+] button on the bottom right to
add two columns for the output.Name the first column as body and set the Type to Document.Name the second column as string and set the Type to String. -
Right-click on the node root and select
Create Sub-Element to create a sub-element.
Name the sub-element as foo in the popup dialog box. -
Right-click on the foo node created in the previous step
and select As loop element. -
Select the id column of the GetOneUser table to the left and drop it onto the
Expression field of the foo node of the ResponseUsers table to the right. - Click OK to save the settings.
Configuring the second tXMLMap component
-
Connect tRESTRequest to the other tXMLMap using the Row > GetUserNumber
connection. -
Double-click the first tXMLMap in the design
workspace to open the Map Editor. -
Click the [+] button on the top right to add
an output and name it as ResponseUserNumber. -
Click the [+] button on the bottom right to
add one column for the output.Name the first column as body and set the Type to Document. -
Right-click on the node root and select
Create Sub-Element to create a sub-element.
Name the sub-element as number in the popup dialog
box. -
Right-click on the number node created in the previous
step and select As loop element. -
Select the string column of the GetUserNumber table to the left and drop it onto
the Expression field of the number node of the ResponseUserNumber table to the right. - Click OK to save the settings.
Configuring the tRESTResponse component
-
Connect tXMLMap to a tRESTResponse using Row >
ResponseUsers connection.The schema defined in tXMLMap is retrieved in
tRESTResponse automatically. - Select OK(200) from the Return status code list.
- Leave the rest of the settings as they are.
-
Connect tRESTRequest to the other tRESTResponse using the Row > GetUserNumber
connection.
Saving and executing the Job
-
Save the Job and press F6 to execute
it. -
Go to your browser if you want to test the service.
The HTTP request for a user id is accepted by the REST service and the HTTP
response is sent back to the server. -
Repeat this step and type in http://localhost:8088/user/number?string=123 in the address bar.
Press Enter.You can see that 123 is returned in the
response.
Using URI Query parameters to explore the data of a database
This scenario applies only to Talend Open Studio for ESB, Talend Data Services Platform and Talend Data Fabric.
This scenario describes how to use URI query parameters in tRESTRequest to explore data of a database, and send the response via
the tRESTResponse.
To do so, you can create two subJobs linked together by an OnSubjobOk connection; this way the two subJobs will be executed
sequentially. For more information on Trigger connection, see the
Talend Studio User
Guide. The first subJob will create and populate the database and the
second one will allow to explore the database through the REST service.
Creating the first subJob
To do this, proceed as follows:
-
Drop the following components from the Palette onto the design workspace: tFixedFlowInput from the Misc family and tMysqlOutput from the Databases > Mysql
family. -
Link tFixedFlowInput to tMysqlOutput using a Row > Main
connection. -
Double-click tFixedFlowInput to display
its Basic settings view: -
Click the […] button next to Edit schema to open the schema editor.
-
In the schema editor, click the [+]
button three times to add three lines and set them as displayed in the above
screenshot. - Click Ok.
-
Back to tFixedFlowInput
Basic settings view, in the Mode area, select the Use
inline table option. -
Under the inline table, click the [+]
button three times to add three rows in the table. -
In the inline table, click the id field
of the first row and type in 1. -
Click the firstname field of the first
row, press Ctrl+Space to display the
autocompletion list and select the TalendDataGenerator.getFirstName() variable in the
list. -
Click the lastname field of the first
row, press Ctrl+Space to display the
autocompletion list and select the TalendDataGenerator.getLastName() variable in the
list. -
Do the same for the two following rows to obtain the settings displayed in
the screenshot. -
Double-click tMysqlOutput to display its
Basic settings view: -
From the Property Type list, leave
Built-in and fill in the Host, Port,
Database, Username and Password
fields manually. If you centralized your connection information to the
database in the Metadata > DB Connections node of the Repository, you can select Repository from the list and the fields will be
automatically filled in.For more information about storing metadata, see
Talend Studio User Guide. -
In the Table field, type in the name of
the table in which the data will be loaded, for example: users. -
From the Action on table list, select
Drop table if exists and create, select
Insert from the Action on data list. -
Click Sync columns to retrieve the schema
coming from the previous component.
Creating the second subJob
The following components are used as displayed in the first screenshot:
-
tRESTRequest and tRESTResponse from the ESB >
REST family, -
tFlowToIterate from the Orchestration family,
-
tMysqlInput from the Databases > Mysql family,
-
tXMLMap from the Processing family.
Configuring the tRESTRequest component
To do this, proceed as follows:
-
Double-click tRESTRequest in the
design workspace to display its Basic
settings view: -
Fill the REST Endpoint field with
the URI location where the REST-ful web service will be accessible
for requests. For example, “http://localhost:8088/users”. -
Click the [+] button to add one
line in the REST API Mapping
table. -
Select the newly-added line and click the […] button in the Output
Flow column to add a schema for the output
flow. -
In the dialog box, name the output flow getUsers. A schema editor dialog box appears.
-
In the schema editor, click the [+] button twice to add two lines and set them as
displayed in the above screenshot. - Click OK.
-
Back to tRESTRequest
Basic settings view, select
GET from the list in the
HTTP Verb column. -
Leave the URI Pattern column as
is. - Use the corresponding link to connect to the following component: connect tRESTRequest to tFlowToIterate using Row > getUsers connection.
-
Leave the tFlowToIterate settings
as is. -
Connect tFlowToIterate to
tMysqlInput using Row > Iterate connection.
Configuring the tMysqlInput component
To do this, proceed as follows:
-
Double-click tMysqlInput to
display its Basic settings
view: -
From the Property Type list,
leave Built-in and fill in the
Host, Port, Database,
Username and Password fields manually. If you
centralized your connection information to the database in the
Metadata > DB Connections node of the Repository, you can select Repository from the list and the fields
will be automatically filled in.For more information about storing metadata, see
Talend Studio User
Guide. -
Leave the Schema list as
Built-in and click the
[…] button next to the
Edit schema field. -
In the schema editor, define the schema exactly like the one of
the tFixedFlowInput. -
In the Table Name field, fill in
the name of the table in which the data are stored: users. -
Leave the Query Type list as
Built-in and fill in the
Query field with the following
SQL query allowing to explore the database data with the URI query
set in the tRESTRequest component:“select * from users where id >= ” + globalMap.get(“getUsers.from”) + ” and id <= ” + globalMap.get(“getUsers.to”)
Configuring the tXMLMap component
-
Right-click tMysqlInput, hold and
drag to tXMLMap to connect the two
components together. -
Double-click tXMLMap in the design
workspace to open the Map Editor. -
Click the [+] button on the top right
to add an output and name it as ResponseUsers. -
Click the [+] button on the bottom
right to add two columns for the output.Name the first column as body and
set the Type to Document.Name the second column as string
and set the Type to String. -
Right-click on the root node, select
Rename in the list and rename it
users
-
Right-click on the users node and
select Create Sub-Element to create a
sub-element. Name the sub-element user in the popup
dialog box. -
Right-click on the user node created in the
previous step and select As loop
element. -
Select the id column of the
row2 table to the left and drop
it onto the user node of the
ResponseUsers table to the
right. -
In the Selection dialog box, select
the Create as attribute of target node
option and click OK. -
Select the firstname and lastname columns of the row2 table to the left and drop it onto the
user node of the ResponseUsers table to the right. -
In the Selection dialog box, select
the Create as sub-element of target
node option and click OK. -
Click the wrench icon on the top of the ResponseUsers table to open the setting panel.
-
Set the All in one feature as
true, this way all XML data is
outputted in one single flow. - Click OK to save the settings.
Configuring the tRESTResponse component
-
Connect tXMLMap to tRESTResponse using Row > ResponseUsers
connection. -
The schema defined in tXMLMap is
retrieved in tRESTResponse
automatically. Leave the other settings as they are.
Connecting the two subJobs
Now that the two subJobs are created, you can connect them together:
-
Right-click the tFixedFlowInput
component of the first subjob. - Select Trigger > OnSubjobOk on the list.
-
Click the tRESTRequest component of
the second subJob.
first one’s execution succeeded.
Saving and executing the Job
-
Save the Job and press F6 to execute
it. -
Go to your browser if you want to test the service.
For example, use the URI query
?to=2
to retrieve the data of
the two first users.The HTTP request for a user id is accepted by the REST service and the
HTTP response is sent back to the server.For a use case that calls this REST service using
Talend Open Studio for ESB
components, see Getting user information by interacting with a RESTful service.
Using a REST service to accept HTTP POST requests
This scenario applies only to Talend Open Studio for ESB, Talend Data Services Platform and Talend Data Fabric.
This scenario describes a Job composed of two subJobs: the first subJob exposes a REST
service that accepts HTTP POST requests from REST clients, writes data to a database
upon receiving an HTTP request, and displays the server-client exchange information on
the Run console; the second subJob displays the results
of database updates.
Setting up the Job
-
Create a Job and add the following components to the Job by typing their
names in the design workspace or dropping them from the Palette: a tRESTRequest, a tMysqlOutput, a tXMLMap,
and a tRESTResponse. -
Connect the tRESTRequest to the tMysqlOutput component using a Row > Main
connection, and give the output flow a name, request in this example. -
Connect the tMysqlOutput component to the
tXMLMap component using a Row > Main
connection. -
Connect the tXMLMap component to the
tRESTResponse component using a
Row > Main connection, and give it a name, response in this example. Click OK in the pop-up dialog box to accept the schema propagation
from the tRESTResponse component. -
Add a tMysqlInput component and a
tLogRow component to the Job by typing
their names in the design workspace or dropping them from the Palette, and connect the tMysqlInput to the tLogRow
using a Row > Main connection. -
Connect the tMysqlOutput to the tMysqlInput using a Trigger > OnComponentOk
connection to link the two subJobs.
Configuring the components
Configuring REST request parameters
-
Double-click the tRESTRequest component
to open its Basic settings view. -
Fill the REST Endpoint field with the URI
location where the REST service will be accessible for requests, “http://localhost:8045/users” in this
example. -
Click the output flow name, which is request in this example, in the Output
Flow column of the REST API
Mapping table to show the […] button, and click the button to open the Schema dialog box. Then define the schema for
the request flow as follows:-
id, type Integer, 2 characters
long, set as the key column -
first_name, type String
-
last_name, type String
When done, click OK to validate the
schema setting and close the dialog box. -
-
Click the HTTP Verb column and select
POST from the list. -
In the URI Pattern column, enter the
acceptable URI pattern of POST requests,
"/post/{id}/{first_name}/{last_name}"
in this
example.Leave the rest parameters as they are. -
Click the Advanced settings tab, and
select the Log messages check box.
Configuring the database and the response parameters
-
Double-click the tMysqlOutput component
to open its Basic settings view. -
Leave the Property Type as Built-in and fill in the database connection
details manually in the Host, Port, Database,
Username and Password fields.If you have centralized your connection information to the database in the
Metadata > DB
Connections node of the Repository, you can select Repository from the Property
Type list and browse to the centralized connection to have
the fields automatically filled in. For more information about storing
metadata, see
Talend Studio User
Guide. -
Fill in the Table field with the target
database table name, users in this
example. -
Select the actions to be carried out on the database table and data
according to your needs from the corresponding lists. In this example, the
target table will be created if it does not exist in the specified database,
and data from client requests will be inserted, or updated if it already
exists, to the database table. -
Click the Sync columns button to
synchronize the table schema with the input schema. -
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. -
Double-click the tRESTResponse component
and set the response parameters according to your needs. In this example, we
keep the default settings for all the parameters.
Configuring result display
-
Double-click the tMysqlInput component to
open its Basic settings view. -
Specify the database connection details, table name and table schema,
which are the same as in the tMysqlOutput
component. -
Click the Guess Query button to fill the
Query field with the query
statement. -
Double-click the tLogRow component and
select the Table option to display the
content of the database in table cells.
Saving the executing the Job
- Press Ctrl+S to save your Job.
-
Click the Run button on the Run tab or press F6 to run it.
The console displays the service implementation information, including the
service URL.When an HTTP POST request is received from a client, the console displays
the relevant exchange information and the database update result.For a use case that calls this REST service using the HTTP POST method,
see Updating user information by interacting with a RESTful service.
Using a REST service to accept HTTP POST requests and send responses
This scenario applies only to Talend Open Studio for ESB, Talend Data Services Platform and Talend Data Fabric.
This scenario describes how to build a REST service that accepts HTTP POST requests of
Document
type from the client, processes it and sends the response
back. To do this, two Jobs are built: one to create the REST service and the other to
call it.
Creating the REST service Job
Drag and drop the following components from the Palette onto the design workspace: a tRESTRequest, a tXMLMap and a
tRESTResponse.
Configuring the tRESTRequest component
-
Double-click tRESTRequest in the
design workspace to display its Basic
settings view. -
In the REST Endpoint field, keep the
default URI “http://localhost:8088/” where the
REST-ful web service will be accessible for requests. -
Click the [+] button to add one line
in the REST API Mapping table. -
Select the newly-added line and click the […] button in the Output
Flow column to add a schema for the output flow. Give the
name for the schema UserInfo in this scenario.The schema editor opens. Click the [+] button to add a new line body
ofDocument
type and click OK to save the schema. -
Back to tRESTRequest
Basic settings view, select POST from the list in the HTTP Verb column. -
Fill the field in the URI Pattern
column with “/UserInfo”. Keep the default settings
of the other options.
Configuring the body of the response
-
Connect tRESTRequest to tXMLMap using the Row > UserInfo
connection. -
Double-click tXMLMap in the design
workspace to open the Map
Editor. -
Right-click on the root node of the
input table and select Create
Sub-Element. Name the sub-element as
person in the popup dialog box. -
Right-click on the person node created in the
previous step and select As loop
element. -
Create two sub-elements to the person node by
selecting Create Sub-Element in the
contextual menu, id and name
in this use case. -
Click the [+] button on the top right
to add an output and name it as Response. -
Click the [+] button on the bottom
right to add a column body ofDocument
type for the output. -
Right-click the node root in the
output table and select Create
Sub-Element. Name the sub-element as
person in the popup dialog box. -
Right-click the person node created in the
previous step and select As loop
element. -
Create three sub-elements to the person node by
selecting Create Sub-Element in the
contextual menu, id, name and
company in this use case. -
Select the id column from the input
table and drop it onto the Expression
field of the id node of the output
table. -
Select the name column from the
input table and drop it onto the Expression field of the name node in the output table.Click the Expression field of the
name node in the output table,
and click […] in this field to show
the Expression Builder wizard.In the Expression area, enter
StringHandling.UPCASE([UserInfo.body:/root/person/name])
to convert the name of the user to upper case. Click OK to close the wizard.For further information about using the Expression Builder, see
Talend Studio User Guide. -
In the Expression field of the
company node, enter
“Talend”. - Click OK to save the settings.
Configuring the tRESTResponse component
-
Connect tXMLMap to a tRESTResponse using Row > Response
connection.The schema defined in tXMLMap is
retrieved in tRESTResponse
automatically. - Select OK(200) from the Return status code list.
- Leave the rest of the settings as they are.
Launching the service
Save the Job and press F6 to execute it. The
service is started.
Creating the consumer Job
Drag and drop the following components from the Palette onto the design workspace: a tFixedFlowInput, a tXMLMap, a
tRESTClient and a tLogRow.
Configuring the tFixedFlowInput component
-
Double-click tFixedFlowInput in the
design workspace to display its Basic
settings view. -
Click Edit schema to show the schema
editor. In the schema editor, click the [+] button to add two columns ofString
type, id and name.Click
Ok to close the schema
editor. -
Back to tFixedFlowInput
Basic settings view, in the Mode area, select the Use Inline Content option. -
In the Content box, enter the
id and name of three
users, for example:1231;ford2;smith3;thomson
Configuring the tXMLMap component
-
Connect tFixedFlowInput to tXMLMap using the Row > Main
connection. -
Connect tXMLMap to tRESTClient using the Row > Main
connection, and name the output flow request in
this example. -
Double-click tXMLMap in the design
workspace to open the Map
Editor. -
Right-click on the node root in the
output table and select Create
Sub-Element. Name the sub-element as
person in the popup dialog box. -
Right-click on the person node created in the
previous step and select As loop
element. -
Create two sub-elements to the person node by
selecting Create Sub-Element in the
contextual menu, id, and name
in this use case. -
Select the id column from the input
table and drop it onto the Expression
field of the id node of the output
table. -
Select the name column from the
input table and drop it onto the Expression field of the name node in the output table. - Click OK to save the settings.
Configuring the tRESTClient component
-
Double-click the tRESTClient
component to open its Basic settings
view. -
Fill the URL field with the URL of
the REST service built in the service Job, “http://localhost:8088/”. -
Fill the Relative Path
with the “UserInfo”. -
From the HTTP Method list, select
POST. - Leave the rest of the settings as they are.
-
Connect tRESTClient to tLogRow using the Row > Response
connection. Keep the default settings of the tLogRow to monitor the message exchanges.
Saving and executing the Job
Save the Job and press F6 to execute it. The
user information is shown in the console, including id,
name, and company. The name of the
user has been converted to upper case.
Using a REST service to accept HTTP POST requests in an HTML form
This scenario applies only to Talend Open Studio for ESB, Talend Data Services Platform and Talend Data Fabric.
This scenario describes how to upload data to a REST service using HTTP POST in a HTML
form file. To do so, a Job is created to accept HTTP POST requests using the tRESTRequest component.
A predefined HTML form UploadFile.html is used to upload data to
the REST service:
1 2 3 4 |
<form action="http://localhost:8088/UserInfo" method="post" enctype="multipart/form-data"> <input type="file" name="id" /> <button>upload</button> </form> |
The customer.xml that contains a user ID will be uploaded:
1 2 3 |
<customer> <id>100</id> </customer> |
Setting up the Job
Drop the following components from the Palette
onto the design workspace: a tRESTRequest, a
tJavaRow, a tXMLMap and a tRESTResponse.
Configuring the tRESTRequest component
-
Double-click tRESTRequest in the design
workspace to display its Basic settings
view. -
In the REST Endpoint field, keep the
default URI “http://localhost:8088/” where the REST-ful
web service will be accessible for requests. -
Click the [+] button to add one line in
the REST API Mapping table. -
Select the newly-added line and click the […] button in the Output
Flow column to add a schema for the output flow. Give the
name for the schema UserInfo in this scenario.The schema editor opens. Click the [+]
button to add a new line id ofbyte[]
type
and enter multipart in the Comment field. Click OK to
save the schema. -
Back to tRESTRequest
Basic settings view, select POST from the list in the HTTP Verb column. -
Fill the field in the URI Pattern column
with “/UserInfo”. -
Select Multipart in the Consumes list. Keep the default settings of the
other options.
Configuring the tJavaRow component
-
Connect tRESTRequest to tJavaRow using the Row > UserInfo
connection. -
Double-click tJavaRow in the design
workspace to display its Basic settings
view. -
Enter the following code in the Code box
to convert the message intoDocument
type and print it in the
console.123456789String result = new String(input_row.id,0,input_row.id.length);routines.system.Document doc = new routines.system.Document();doc.setDocument(org.dom4j.DocumentHelper.parseText(result));output_row.id = doc;System.out.println(result);
Configuring the tXMLMap component
-
Connect tJavaRow to tXMLMap using the Row >
Main connection. -
Double-click tXMLMap in the design
workspace to open the Map Editor. -
Click the [+] button on the bottom left
to add a column id ofDocument
type for
the input. -
Right-click the root node of the input
table and select Rename in the contextual
menu and rename it customer. -
Create a sub-element to the customer node by
selecting Create Sub-Element in the
contextual menu. Name the sub-element as id in the
pop-up dialog box. -
Click the [+] button on the top right to
add an output and name it as response. -
Click the [+] button on the bottom right
to add a column body ofDocument
type for
the output. -
Right-click the root node of the input
table and select Rename in the contextual
menu and rename it customer. -
Create a sub-element to the customer node by
selecting Create Sub-Element in the
contextual menu. Name the sub-element as id in the
pop-up dialog box. -
Select the id column from the input
table and drop it onto the Expression field
of the id node of the output
table. - Click OK to save the settings.
Configuring the tRESTResponse component
-
Connect tXMLMap to a tRESTResponse using Row > response
connection.The schema defined in tXMLMap is
retrieved in tRESTResponse
automatically. - Select OK(200) from the Return status code list.
- Leave the rest of the settings as they are.
Saving and executing the Job
-
Save the Job and press F6 to execute
it. -
Run the UploadFile.html using a web browser.
-
Click the Browse button to navigate to
the customer.xml that contains the user ID and click
upload. -
The HTTP POST request is accepted by the REST service and the user ID is
sent back to the server.You can also view the response in the page source. -
The content of the input file is printed in the execution console.