July 30, 2023

cSetHeader – Docs for ESB ESB 7.x

cSetHeader

Sets headers or customizes the default headers, if any, on each message sent to it
for subsequent message processing.

cSetHeader Standard properties

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

The Standard
cSetHeader component belongs to the Core family.

Basic settings

Headers

Click [+] to add as many headers
as required to the table.

Name: Type in a name for the
message header.

The header name CorrelationID is reserved.
The value of this header will be overridden by the correlation ID of
the message if it exist.

 

Language: Select the language of the expression you
use from None, Bean, Constant, CorrelationID, EL,
Groovy, Header, JavaScript,
JoSQL, JSonPath, JXPath,
MVEL, OGNL, PHP,
Property, Python, Ruby,
Simple, SpEL, SQL,
XPath, and XQuery.

Select Bean if you want to call a
predefined Java Bean to return the header value.

Select CorrelationID to
use the existing correlation ID of the message as the header value if the
correlation ID is available in the closest cSOAP connected to this component. For more information about
the cSOAP component, see cSOAP.

 

Value: Type in the expression to
set the value of the message header, or the Bean class that will
return a value for the message header, in the form of
beans.BEAN_NAME.

If CorrelationID is
selected in the Language list, this field
is grayed out. The existing correlation ID from the closest cSOAP connected to this component will be set as
the header value. For more information about the cSOAP component, see cSOAP.

Add Namespaces

Select this check box to add namespaces for the 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

cSetHeader is used as a middle
component in a Route.

Limitation

 n/a

Splitting a message and renaming the sub-messages according to contained
information

This scenario applies only to Talend Open Studio for ESB, Talend Data Services Platform and Talend Data Fabric.

In this scenario, a file message containing people information is split into
sub-messages. Each sub-messages is renamed according the city name it contains, and then
routed to another endpoint.

The following is the example XML file used in this use case:

A predefined Java Bean, setFileNames, is called by the cSetHeader component used in this use case to define a file
name for each message according to the city name it contains. For more information about
creating and using Java Beans, see
Talend Studio User
Guide
.

Dropping and linking the components

This use case uses two cFile components, one as
the message sender and the other as the receiver, a cSplitter component to split the source message into sub-messages, a
cSetHeader component to rename each
sub-message, and a cProcessor component to display
the file name of each message routed to the receiver.

cSetHeader_1.png

  1. From the Palette, expand the Connectivity folder, and drop two cFile components onto the design workspace.
  2. From the Routing folder, drop a cSplitter component onto the design workspace,
    between the two cFile components.
  3. From the Core folder, drop a cSetHeader component onto the design workspace, between the
    cSplitter component and the receiving
    cFile component.
  4. Right-click the first cFile component,
    select Row > Route from the contextual menu and click the cSplitter component.
  5. Right-click the cSplitter component,
    select Row > Split from the contextual menu and click the cSetHeader component.
  6. Right-click the cSetHeader component,
    select Row > Route from the contextual menu and click the second
    cFile component.
  7. Right-click the second cFile component,
    select Row > Route from the contextual menu and click the cProcessor component.
  8. 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.

    cSetHeader_2.png

  2. 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.
    In the FileName field, type in the file
    name of the source message. You can skip this step if the source folder
    contains only one file.
  3. Repeat steps 1 and 2 above to define the output file path and encoding
    type in the Basic settings view of the
    other cFile component, which is labeled
    Receiver. Leave the FileName field blank.

    cSetHeader_3.png

  4. Double-click the cSplitter component to
    display its Basic settings view in the
    Component tab.

    In this use case, as we want to split the message into sub-messages at
    each person node of the XML file. Select XPath in the Language list and type in "/people/person") in
    the Expression field.
    cSetHeader_4.png

  5. Double-click the cSetHeader component,
    which is labeled Set_file_name to display
    its Basic settings view in the Component tab.

    cSetHeader_5.png

  6. Click [+] to add a row to the Headers table.

    In the Name field, type in the name of
    the header you want to give to the messages.
    Here, as we want to define the file name for each incoming message, fill
    in "CamelFileName" as the header name.
    Select Bean in the Language field and type in the name of the predefined Java
    Bean in the Value field,
    beans.setFileNames.class in this use case.
  7. 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 each message routed to
    the receiving endpoint, so we customize the code as follows:
  8. 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.

    cSetHeader_6.png

    As shown in the code, a message route is built from one
    endpoint .to another, and while in routing, the source message
    is split according to the condition xpath("/people/person") by
    cSplitter_1, and each sub-message is given a header named
    CamelFileName, the value of which is returned by
    .method(beans.setFileNames.class).
  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.

    cSetHeader_7.png

    RESULT: The source file message is split into sub-messages and each
    sub-message is renamed after the city name it contains and routed to the
    receiving endpoint.

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