Categories
SAP Blogs

EIPinCPI – Message Translator

EIPinCPI – Message Translator

This week, we’ll begin studying Message Transformation patterns and the first one is known as Message Translator.

When do I use this pattern?

I like to think of middleware software as a translator similar to a language translator. A language translator can translate one language into another. For example, word Hello in English is Hola in Spanish or Namaskara in Marathi or Kon’nichiwa in Japanese.

Similarly, if system A speaks in XML and system B speaks in JSON, middleware software can translate. If system A calls unique identification of a customer as CustomerID and system B calls it KUNNR, middleware software can translate.

When two systems have different ways of representing the data such as JSON, XML, etc. or when two systems have a different data model to represent the same entity, Message Translator pattern can be applied.

Message Translator in CPI

In CPI, we can tackle both kinds of translations. Converters can be used to translate messages from one format into another. Whereas, Mappings can be used to translate messages from one data model to another.

Converter

In essence, CPI supports translating 3 formats: XML, JSON, and CSV. There are 4 converters supported out of the box:

  • JSON to XML Converter
  • CSV to XML Converter
  • XML to CSV Converter
  • XML to JSON Converter

How would you convert JSON to CSV and vice versa? Simply combine the two converters. For converting a message from JSON to CSV, use JSON to XML Converter first and then use XML to CSV Converter. For converting the message from CSV to JSON, use CSV to XML Converter first and then use XML to JSON Converter.

Let’s look at the examples for each of these converters below. I’ll show simple examples to get started. To learn more and dive deep, please go through Help Documentation on each converter linked above or below in the References/Further Readings section.

JSON to XML Converter

The Integration Flow used for this exercise is simple. It uses the Command Message pattern to Get the Customer ‘ALFKI’ in JSON format using HTTP Receiver Adapter, passes the payload through JSON to XML Converter, and logs the output using Groovy Script.

Similar to Integration flow used for JSON to XML Converter, this Integration Flow uses the Command Message pattern to Get the Customer ‘ALFKI’ in XML format using OData Receiver Adapter, passes the payload through XML to CSV Converter, and logs the output using Groovy Script.

Similar to Integration flow used for JSON to XML Converter, this Integration Flow uses the Command Message pattern to Get the Customer ‘ALFKI’ in XML format using OData Receiver Adapter, passes the payload through XML to JSON Converter, and logs the output using Groovy Script.

Similar to Integration flow used for JSON to XML Converter, this Integration Flow uses the Command Message pattern to Get the Customer ‘ALFKI’ in XML format using OData Receiver Adapter, passes the payload through XML to JSON Converter, and logs the output using Groovy Script.

Mapping

CPI supports Message Mapping and XSLT Mapping. Message Mapping uses a visual editor to map the value of a node from a source data model to target data model. Whereas, XSLT mapping, as the name suggests, uses XSLT stylesheets to transform a source XML document into the target XML document.

Message Mapping

A sample message mapping looks like below:

XSLT Mapping

An example of an XSL Stylesheet is like below:

Daniel Graversen has listed the advantages of using XSLT mappings in his blog I *heart* XSLT mappings.

Groovy Mapping

Groovy Mapping is a way of using Groovy Script to transform source payload into target payload. Eng Swee Yeoh argues that Groovy Mappings are a way to go for mapping in his blog I *heart* Groovy mapping.
Which kind of mapping to use and when?

For understanding Pros and Cons of each type of mappings offered by CPI, read Morten Wittrock‘s blog Cloud Integration mapping: Your options explained and compared.

Conclusion

Message Translator pattern is applied when two systems use a different format of representing data or different schema to represent the same entity.

References/Further Readings

  • Message Translator Pattern in Enterprise Integration Patterns
  • Blogs for choosing which mapping to use
    • Daniel Graversen‘s I *heart* XSLT mappings
    • Eng Swee Yeoh‘s I *heart* Groovy mapping
    • Morten Wittrock‘s Cloud Integration mapping: Your options explained and compared
  • EIPinCPI
    • Command Message
  • CPI Components
    • Converter
    • JSON to XML Converter
    • CSV to XML Converter
    • XML to CSV Converter
    • XML to JSON Converter
    • Mapping
    • Message Mapping
    • XSLT mapping

    Other

    • HTTP Receiver Adapter
    • OData Receiver Adapter
    • Groovy Script

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    ×
    Placement Report
    EIPinCPI – Message Translator

    EIPinCPI – Message Translator
    ×
    Interview Questions
    EIPinCPI – Message Translator

    EIPinCPI – Message Translator
    ×
    Learn More
    EIPinCPI – Message Translator

    EIPinCPI – Message Translator
    ×
    Sign Up Now
    EIPinCPI – Message Translator

    EIPinCPI – Message Translator
    ×
    Join Us
    EIPinCPI – Message Translator

    EIPinCPI – Message Translator
    ×
    Get started
    EIPinCPI – Message Translator

    EIPinCPI – Message Translator
    ×
    Buy Now
    EIPinCPI – Message Translator

    EIPinCPI – Message Translator
    ×
    Download Course Content
    EIPinCPI – Message Translator

    EIPinCPI – Message Translator
    ×
    Call Back
    EIPinCPI – Message Translator

    EIPinCPI – Message Translator
    ×
    Ask for Demo
    EIPinCPI – Message Translator

    EIPinCPI – Message Translator
    ×
    Enquiry
    EIPinCPI – Message Translator

    EIPinCPI – Message Translator
    ×
    Please fill form to see Video
    EIPinCPI – Message Translator

    EIPinCPI – Message Translator
    ×
    Schedule Your Demo
    EIPinCPI – Message Translator

    EIPinCPI – Message Translator
    ×
    Apply for scholarship