AdjustingForInflation
AdjustingForInflation

Reputation: 1611

How to use Camel Message Filter Bean in Spring XML

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?

Upvotes: 1

Views: 2549

Answers (2)

user2715256
user2715256

Reputation: 1

<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>

Upvotes: 0

hveiga
hveiga

Reputation: 6925

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>

Upvotes: 2

Related Questions