|
Page Edited :
CAMEL :
Normalizer
Normalizer has been edited by Jonathan Anstey (Nov 10, 2008). Content:NormalizerCamel supports the Normalizer ExampleThis 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 // before we can filter, we need to normalize the incoming messages from("direct:start").choice() .when().xpath("/employee").to("bean:normalizer?method=employeeToPerson").to("seda:queue") .when().xpath("/customer").to("bean:normalizer?method=customerToPerson").to("seda:queue"); // filter the normalized messages from("seda:queue").filter().xpath("/[EMAIL PROTECTED]'Jon']").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 id="camel" xmlns="http://activemq.apache.org/camel/schema/spring"> <route> <from uri="direct:start"/> <choice> <when> <xpath>/employee</xpath> <to uri="bean:normalizer?method=employeeToPerson"/> <to uri="seda:queue"/> </when> <when> <xpath>/customer</xpath> <to uri="bean:normalizer?method=customerToPerson"/> <to uri="seda:queue"/> </when> </choice> </route> <route> <from uri="seda:queue"/> <filter> <xpath>/[EMAIL PROTECTED]'Jon']</xpath> <to uri="mock:result"/> </filter> </route> </camelContext> <bean id="normalizer" class="org.apache.camel.processor.MyNormalizer"/> See AlsoUsing This PatternIf you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out. |
Unsubscribe or edit your notifications preferences
