Christoph Läubrich created CAMEL-10572:
------------------------------------------

             Summary: RefLanguage should support Predicates for Choice
                 Key: CAMEL-10572
                 URL: https://issues.apache.org/jira/browse/CAMEL-10572
             Project: Camel
          Issue Type: Improvement
          Components: camel-core
    Affects Versions: 2.18.1
            Reporter: Christoph Läubrich
            Priority: Minor


The documentation for the CBR 
(http://camel.apache.org/content-based-router.html) states 
{quote}The following example shows how to route ... depending on the evaluation 
of various Predicate expressions{quote}
If you now look at the predicate section 
(http://camel.apache.org/predicate.html) it says:
{quote}Camel supports extensible Predicates using multiple Languages; the 
following languages are supported out of the box
...
Ref Language
...{quote}But going to the Ref page (http://camel.apache.org/ref-language.html) 
it states{quote}The Ref Expression Language is really just a way to lookup a 
custom Expression from the Registry. {quote}
So Ref Language does NOT support Predicates, it works in most cases since 
nearly all classes in Camel core implement Expresion and Predicate interface 
and there is a lot of converting between those, but if you have a custom 
expression that only implements predicate, you get in fact an (a bit 
misleading) exception:
{quote}java.lang.IllegalArgumentException: Cannot find expression in registry 
with ref: predicate
        at 
org.apache.camel.language.ref.RefLanguage$1.evaluate(RefLanguage.java:50)
        at 
org.apache.camel.support.ExpressionAdapter.evaluate(ExpressionAdapter.java:36)
        at 
org.apache.camel.support.ExpressionSupport.matches(ExpressionSupport.java:32)
        at 
org.apache.camel.util.ExpressionToPredicateAdapter.matches(ExpressionToPredicateAdapter.java:35)
        at 
org.apache.camel.processor.FilterProcessor.matches(FilterProcessor.java:65)
        at 
org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:93)
        at 
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
        at 
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:542)
        at 
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
        at 
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
        at 
org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:192)
        at 
org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:76){quote}

It takes me some time to find out that Camel is in fact finding my bean but 
can't use it, beside that its hard to work out why a predicate must also 
implement expression (Choice it self requires an Predicate in fact, so it 
converts all expresions to Predicates).

So the following improvements would be nice

# Let RefLanguage send out some kind of TypeConverterException if it can't use 
the bean as the desired type
# Let Ref, if it finds that the referenced bean is a predicate, convert this to 
an expression e.g with PredicateToExpressionAdapter



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to