...
In this example, we are converting two different XML messages into a common format and then the commonly formatted messages are routed.
Code Block |
---|
|
<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 |
---|
|
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 + \"/>";
}
} |