...
Here is another example of using a bean to define the filter behavior
Code Block |
from("direct:start")
.filter().method(MyBean.class, "isGoldCustomer").to("mock:result").end()
.to("mock:end");
public static class MyBean {
public boolean isGoldCustomer(@Header("level") String level) {
return level.equals("gold");
}
}
|
...
Wiki Markup |
{snippet:id=example|lang=xml|url=""> |
You can also use a method call _expression_ (to call a method on a bean) in the Message Filter, as shown below:
<bean id="myBean" class="com.foo.MyBean"/>
<
route
>
<
filter
>
<
method ref="myBean" method="isGoldCustomer"/
>
</
filter
>
</
route
>
</
camelContext
>
|
Info |
title |
filtered endpoint required inside </filter> tag |
|
make sure you put the endpoint you want to filter (<to uri="seda:b"/>, etc.) before the closing </filter> tag or the filter will not be applied (in 2.8+, omitting this will result in an error) |
For further examples of this pattern in use you could look at the junit test case
Using stop
Available as of Camel 2.0
Stop is a bit different than a message filter as it will filter out all messages and end the route entirely (filter only applies to its child processor). Stop is convenient to use in a Content Based Router when you for example need to stop further processing in one of the predicates.
...
The property has the key Exchange.FILTER_MATCHED
, which has the String value of CamelFilterMatched
. Its value is a boolean indicating true
or false
. If the value is true
then the Exchange was routed in the filter block. This property will be visible within the Message Filter block who's Predicate matches (value set to true
), and to the steps immediately following the Message Filter with the value set based on the results of the last Message Filter Predicate evaluated.
Include Page |
|