Sets the message body in the Route.
cSetBody replaces the payload of each message sent to
cSetBody Standard properties
These properties are used to configure cSetBody running in the Standard Job framework.
cSetBody component belongs to the Core family.
Select the language of the expression you use to set the content for matched messages,
Type in the expression to set the message content.
This option appears when XPath is selected in the
Select this check box to add namespaces for the Xpath expression.
cSetBody is used as a middle
Scenario: Replacing the content of messages with their extracts
This scenario applies only to a Talend solution with ESB.
In this scenario, file messages are routed from one endpoint to another, with the
content of each message replaced with the information extracted from it.
The following is an example of the XML files used in this use case:
Dropping and linking the components
This use case uses two cFile components, one as
the message sender and the other as the receiver, a cSetBody component to replace the content of the messages on route,
and a cProcessor component to display the new
content of the messages routed to the receiving endpoint.
- From the Palette, expand the Connectivity folder, and drop two cFile components onto the design workspace.
From the Core folder, drop a cSetBody component onto the design workspace, between the
two cFile components.
From the Custom folder, drop a cProcessor component onto the design workspace, following
the second cFile component.
Right-click the first cFile select
Row > Route from the contextual menu and click the cSetBody component.
- Repeat this operation to connect the cSetBody component to the second cFile component, and the second cFile component to the cProcessor component.
Label the components to better identify their roles in the Route, as shown
Configuring the components and connections
Double-click the cFile component labeled
Sender to display its Basic settings view in the Component tab.
In the Path field, fill in or browse to
the path to the folder that holds the source files.
From the Encoding list, select the
encoding type of your source files. Leave the other parameters as they
- Repeat these steps to define output file path and encoding type in the Basic settings view of the other cFile component, which is labeled Receiver.
Double-click the cSetBody component to
display its Basic settings view in the
From the Language list box, select the
language of the expression you are going to use.Here we are handling XML files, so select XPath from the list box.
In the Expression field, type in the
expression that will return the new message content you want.In this use case, we want person to be
the root element of each file when routed to the receiving endpoint, so type
"/people/person"in the Expression field.
Double-click the cProcessor component to
display its Basic settings view in the
Component tab, and customize the code
so that the console will display information the way you wish.In this use case, we want to display the file name and content of each message routed to
the receiving endpoint, so we customize the code as follows:123456System.out.println("File received: " +exchange.getIn().getHeader("CamelFileName") +"Content:" +exchange.getIn().getBody(String.class));
- Press Ctrl+S to save your Route.
Viewing code and executing the Route
Click the Code tab at the bottom of the
design workspace to have a look at the generated code.In this partially shown code, a message route is built
.toanother, and while in routing, the content of each
message is replaced according to the condition
Click the Run view to display it and
click the Run button to launch the
execution of your Route. You can also press F6 to execute it.RESULT: The XML files are sent to the receiver, where person has become the root element of each file.