Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In the above illustration, we can see that we have implemented the Normalizer pattern using a Content-Based Router in conjunction with several Message Translators.

Normalizer using XML DSL

In this example, we are converting two different XML messages into a common format and then the commonly formatted messages are routed.

Code Block
languagexml
<camelContext xmlns="http://camel.apache.org/schema/spring">
  <route>
    <from uri="direct:input"/>
    <choice>
      <when>
        <xpath>/partner</xpath>
        <to uri="bean:normalizer?method=convertPartner"/>
      </when>
      <when>
        <xpath>/customer</xpath>
        <to uri="bean:normalizer?method=convertCustomer"/>
      </when>
    </choice>
    <to uri="out:result"/>
  </route>
</camelContext>

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

Using Java Bean as the Normalizer:

Code Block
languagejava
public class MyNormalizer {

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

    public void customerToPerson(Exchange exchange, @XPath("/customer/@name") String name) {
        exchange.getMessage().setBody(createPerson(name));
    }

    private String createPerson(String name) {
        return "<person name=\" + name + \"/>";
    }
}

...