How to use Camel Message Filter Bean in Spring XML

2.5k Views Asked by At

The Camel documentation for Message Filter shows several Java DSL examples using a "filter bean" like so:

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");
    }
}

But that page doesn't show how to invoke that bean in Spring XML:

<route id="my-route">
    <from uri="direct:a" />
    <filter>
        <method>??? how to call MyBean#isGoldCustomer from here???</method>
        <to uri="direct:b" />
    </filter>
</route>

In the above snippet, how do I wire my <filter/> with a Java bean, and what interface does that Java bean need to implement/extend?

2

There are 2 best solutions below

0
On
<bean id="myCustomPredicate" class="com.hveiga.test.MyCustomPredicate"/>
<route id="my-route">
    <from uri="direct:a" />
    <filter>
        <method ref="myCustomPredicate" method="myCustomPredicateMethod"/>
        <to uri="direct:b" />
    </filter>
</route>
0
On

You should be able to do it like this:

<bean id="myCustomPredicate" class="com.hveiga.test.MyCustomPredicate"/> 

<route id="my-route">
    <from uri="direct:a" />
    <filter>
        <method ref="myCustomPredicate" />
        <to uri="direct:b" />
    </filter>
</route>