Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-10572

RefLanguage should support Predicates for Choice

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.18.1
    • Fix Version/s: 2.19.0
    • Component/s: camel-core
    • Labels:
      None
    • Estimated Complexity:
      Novice

      Description

      The documentation for the CBR (http://camel.apache.org/content-based-router.html) states

      The following example shows how to route ... depending on the evaluation of various Predicate expressions

      If you now look at the predicate section (http://camel.apache.org/predicate.html) it says:

      Camel supports extensible Predicates using multiple Languages; the following languages are supported out of the box
      ...
      Ref Language
      ...

      But going to the Ref page (http://camel.apache.org/ref-language.html) it states

      The Ref Expression Language is really just a way to lookup a custom Expression from the Registry.


      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:

      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)

      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

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

        Attachments

          Activity

            People

            • Assignee:
              davsclaus Claus Ibsen
              Reporter:
              laeubi Christoph Läubrich
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: