Normalizer - 6.3

Talend ESB Mediation Developer Guide

EnrichVersion
6.3
EnrichProdName
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
task
Design and Development
EnrichPlatform
Talend ESB

Camel supports the Normalizer from the EIP patterns by using a Message Router in front of a number of Message Translator instances.

The below example shows a Message Normalizer that converts two types of XML messages into a common format. Messages in this common format are then filtered.

Using the Fluent Builders

// we need to normalize two types of incoming messages
from("direct:start")
    .choice()
        .when().xpath("/employee").to(
            "bean:normalizer?method=employeeToPerson")
        .when().xpath("/customer").to(
            "bean:normalizer?method=customerToPerson")
    .end()
    .to("mock:result");

In this case we're using a Java bean as the normalizer. The class looks like this

public class MyNormalizer {
    public void employeeToPerson(Exchange exchange, 
        @XPath("/employee/name/text()") String name) {
        exchange.getOut().setBody(createPerson(name));            
    }

    public void customerToPerson(Exchange exchange,
        @XPath("/customer/@name") String name) {
        exchange.getOut().setBody(createPerson(name));
    }        
    
    private String createPerson(String name) {
        return "<person name=\"" + name + "\"/>";
    }
}    

Using the Spring XML Extensions

The same example in the Spring DSL

<camelContext xmlns="http://camel.apache.org/schema/spring">
   <route>
      <from uri="direct:start"/>
      <choice>
         <when>
            <xpath>/employee</xpath>
            <to uri="bean:normalizer?method=employeeToPerson"/>
         </when>
         <when>
            <xpath>/customer</xpath>
            <to uri="bean:normalizer?method=customerToPerson"/>
         </when>
      </choice>
      <to uri="mock:result"/>
   </route> 
</camelContext>

<bean id="normalizer" class="org.apache.camel.processor.MyNormalizer"/>