August 15, 2023

cSetBody – Docs for ESB 6.x

cSetBody

Sets the message body in the Route.

cSetBody replaces the payload of each message sent to
it.

cSetBody Standard properties

These properties are used to configure cSetBody running in the Standard Job framework.

The Standard
cSetBody component belongs to the Core family.

Basic settings

Language

Select the language of the expression you use to set the content for matched messages,
from None, Bean, CONSTANT,
CorrelationID, EL, GROOVY, HEADER,
JAVASCRIPT, JoSQL, JSonPath, JXPATH,
MVEL, OGNL, PHP,
PROPERTY, PYTHON, RUBY,
SIMPLE, SpEL, SQL,
XPATH, and XQUERY.

Expression

Type in the expression to set the message content.

Correlation expression/Add
Namespaces

This option appears when XPath is selected in the
Language list.

Select this check box to add namespaces for the Xpath expression.
Click [+] to add as many namespaces
as required to the table and define the prefix and URI in the
corresponding columns.

Usage

Usage rule

cSetBody is used as a middle
component in a Route.

Limitation

 n/a

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.

use_case-csetbody1.png

  1. From the Palette, expand the Connectivity folder, and drop two cFile components onto the design workspace.
  2. From the Core folder, drop a cSetBody component onto the design workspace, between the
    two cFile components.
  3. From the Custom folder, drop a cProcessor component onto the design workspace, following
    the second cFile component.
  4. Right-click the first cFile select
    Row > Route from the contextual menu and click the cSetBody component.
  5. Repeat this operation to connect the cSetBody component to the second cFile component, and the second cFile component to the cProcessor component.
  6. Label the components to better identify their roles in the Route, as shown
    above.

Configuring the components and connections

  1. Double-click the cFile component labeled
    Sender to display its Basic settings view in the Component tab.

    use_case-csetbody2.png

  2. In the Path field, fill in or browse to
    the path to the folder that holds the source files.
  3. From the Encoding list, select the
    encoding type of your source files. Leave the other parameters as they
    are.
  4. 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.
  5. Double-click the cSetBody component to
    display its Basic settings view in the
    Component tab.

    use_case-csetbody3.png

  6. 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.
  7. 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
    in "/people/person" in the Expression field.
  8. 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:
  9. Press Ctrl+S to save your Route.

Viewing code and executing the Route

  1. Click the Code tab at the bottom of the
    design workspace to have a look at the generated code.

    use_case-csetbody6.png

    In this partially shown code, a message route is built from one endpoint
    .to another, and while in routing, the content of each
    message is replaced according to the condition
    .xpath("/people/person") by
    "cSetBody_1".
  2. 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.

    use_case-csetbody7.png

    RESULT: The XML files are sent to the receiver, where person has become the root element of each file.

Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x