August 15, 2023

cConvertBodyTo – Docs for ESB 6.x

cConvertBodyTo

Converts the message body to the given class type.

cConvertBodyTo Standard properties

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

The Standard
cConvertBodyTo component belongs to the Transformation family.

Basic settings

Target Class Name

Enter the name of the class type that you want to convert the
message body to.

Usage

Usage rule

cConvertBodyTo is used as a
middle component in a Route.

Limitation

 n/a

Scenario: Converting the body of an XML file into an
org.w3c.dom.Document.class

This scenario applies only to a Talend solution with ESB.

In this scenario, a cConvertBodyTo component is used
to convert the body of an XML file into an org.w3c.dom.Document.class. Then a cBean component imports the org.w3c.dom.Document class,
checks its content and prints out the root element name and the content of each
category element.

The XML file is as follows:

Creating a Bean

  1. From the repository tree view, expand the Code node and right click the Beans node. In the contextual menu, select Create Bean.

    use_case_ccxf5.png

  2. The [New Bean] wizard opens. In the Name field, type in a name for the bean, for
    example, PrintConvertToBean. Click Finish to close the wizard.

    use_case_cconvertbodyto_7.png

  3. Enter the following code in the design workspace.

  4. Press Ctrl+S to save your bean.

For more information about creating and using Java Beans, see
Talend Studio User
Guide
.

Dropping and linking the components

  1. Drag and drop a cFile, a cConvertBodyTo, a cBean and a cBeanRegister
    from the Palette onto the workspace.

    use_case_cconvertbodyto_1.png
  2. Link the cFile, cConvertBodyTo and cBean
    using the Row > Route connection as shown above.
  3. Label the components to better identify their functionality.

Configuring the components

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

    use_case_cconvertbodyto_2.png

  2. In the Path field, enter or browse to the
    path to the source XML file.

    If the source file folder contains more than one file, enter the name of
    the XML file of interest in the FileName
    field, and leave the other parameters as they are.
  3. Double-click the cConvertBodyTo component
    to open its Basic settings view in the
    Component tab.

    use_case_cconvertbodyto_3.png

  4. In the Target Class Name field, enter
    your target class name, org.w3c.dom.Document.class in this scenario.
  5. Double-click the cBeanRegister component to open its Basic
    settings
    view in the Component
    tab.

    use_case_cconvertbodyto_8.png

  6. In the Id field, enter
    "bean".

    Select the Simple option and in the
    Class Name field, enter the name of the
    bean to be invoked, beans.PrintConvertToBean in this scenario.
  7. Double-click the cBean component to open
    its Basic settings view in the Component tab.

    use_case_cconvertbodyto_4.png
  8. Select Reference and in the Id field, enter "bean" to call the
    bean that is registered by the cBeanRegister.
  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 check the generated code.

    use_case_cconvertbodyto_6.png

    As shown above, the message from the endpoint
    Read_message_cFile_1 has its body converted to
    org.w3c.dom.Document.class by
    cConvertBodyTo_1, and then processed by bean
    invoked by cBean_1.
  2. Press F6 to execute the Route.

    RESULT: The root element name and the contents of the category elements are displayed.
    use_case_cconvertbodyto_5.png


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