A <choice
> is either one or the other, so in your example you can only reach one destination URI. Therefore you may need to add a <split>
before the <choice>
so that you have two separate messages being evaluated.
See splitter for your options there, for example you may want to create your own POJO with a method that returns a list of two ValidatedWitches objects - one with the "goodWitches" collection populated only and one with the "badWitches" collection populated only.
There are many predicate options available, but an easy one would be to check if each array was empty.
Then your route could look something like this:
<to uri="bean:witchValidator?method=process" />
<split>
<method beanType="SPLITTER_CLASS_NAME" method="SPLITTER_METHOD" />
<choice>
<when>
<simple>${body.goodWitches.size} > 0</simple>
<to uri="direct:goodWitches" />
</when>
<when>
<simple>${body.badWitches.size} > 0</simple>
<to uri="direct:badWitches" />
</when>
</choice>
</split>
Key points:
- Splitter should return a collection of two or more objects
- Choice needs to be able to distinguish between the split objects