Content Filter
Camel supports the Content Filter from the EIP patterns using one of the following mechanisms in the routing logic to transform content from the inbound message.
-
Using a Message Translator
-
Invoking a Bean with the filtering programmed in Java
-
Using a Processor with the filtering programmed in Java
-
Using an Expression
Message Content filtering using a Processor
In this example we add our own Processor using explicit Java to filter the message:
from("direct:start")
.process(new Processor() {
public void process(Exchange exchange) {
String body = exchange.getMessage().getBody(String.class);
// do something with the body
// and replace it back
exchange.getMessage().setBody(body);
}
})
.to("mock:result");
Message Content filtering using a Bean EIP
we can use Bean EIP to use any Java method on any bean to act as content filter:
from("activemq:My.Queue")
.bean("myBeanName", "doFilter")
.to("activemq:Another.Queue");
And in XML DSL:
<route>
<from uri="activemq:Input"/>
<bean ref="myBeanName" method="doFilter"/>
<to uri="activemq:Output"/>
</route>
Message Content filtering using expression
In the example we use xpath to filter a XML message to select all the <foo><bar>
elements:
from("activemq:Input")
.setBody().xpath("//foo:bar")
.to("activemq:Output");
And in XML DSL:
<route>
<from uri="activemq:Input"/>
<setBody><xpath>//foo:bar</xpath></setBody>
<to uri="activemq:Output"/>
</route>