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

can not use endChoice() in nest choice DSL

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 3.6.0, 3.11.0
    • Future
    • camel-core, eip
    • None
    • Unknown

    Description

      I want to use nest choice DSL to finish some job, but it doesn't work well in my test case.  When I use endChoice() in the inner choice clause, it return back to the outer choice definition actually. 

      And this is the test case:

      ProcessorDefinition<?> end = from("timer:foo?period=5000&synchronous=true")
      .transform(simple("${random(1000)}"))
      .choice()
      .when(simple("${body} > 500"))
      .log("High number ${body}")
      .choice()
      .when(simple("${body} > 750"))
      .log("High number >750 ${body}")
      .endChoice()
      .otherwise()
      .log("High number <750 ${body}")
      .endChoice()
      .endChoice()
      .otherwise()
      .log("Low number ${body}")
      .endChoice();

       

      Though in this case, I can fix the problem by not use endChoice(), I see the code of endChoice(). I found that change the sequence of the two judgement below can fix my problem, but I am not sure the influence. So I hope you can give me an answer, thx!

      // are we nested choice?
      ProcessorDefinition<?> def = this;
      if (def.getParent() instanceof WhenDefinition)

      { return (ChoiceDefinition) def.getParent().getParent(); }

      // are we already a choice?
      if (def instanceof ChoiceDefinition)

      { return (ChoiceDefinition) def; }

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            ttyy1112 tang honggang
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: