4 Replies Latest reply on Nov 24, 2009 7:49 AM by lyfe

    message routing with choice option within choice option

    lyfe

      I'm trying to get the below code to work:

       

      from().choice().when().method().process().to().when().method().process().to().end();

       

      I want to evaluate against the second "method" depending on the output from the first "to".  If the second "method" evalutes to false, I want to return the output from the first "to".

       

      When I run the code, it only evaluates against the first "method" and never hits the second "method".

        • 1. Re: message routing with choice option within choice option
          davsclaus

          choice

            when

            when

            otherwise

           

          is just like a regular java

           

          if

          else if

          else is

          else

           

          So no surprise that if the first when is evaluated to true then its executed. And if its evaluated to false then the next when is evaluated and so on.

           

          What do you use in the when as predicate? Maybe its being evaluated to true all the time.

          • 2. Re: message routing with choice option within choice option
            lyfe

            I'm using a bean.  I take the exchange as an xml string and set variables while I parse it.  Then I pass back a true or false based on what I want to know.

             

            I'm a little confused on your last sentence: Maybe its being evaluated to true all the time.  Can you elaborate?

             

            From my testing, all when statements (except the one in question) is evaluating correctly.  I actually have 5 when statements.  4 of the 5 when statement's predicates are being evaluated against tags that only appear in a request.  The last when statement's predicate is being evaluated against tags that only appear in a response.

             

            Also, for additional clarity, I want to achieve:

             

            if {...}

            else if {... if {...}}

            else if {...}

            else {...}

             

            ..based on what is returned from first if else, I want to execute the embedded if.

             

            I apologize in advance for rehashing if you understood the situation.

            • 3. Re: message routing with choice option within choice option
              davsclaus

              You can do nested choices but then remember to end it with an end(). Its however often most easier to use direct to link to another route with has the nested route

               

               

              from foo

                choice

                   when bar to bar

                   when baz to baz

                end

               

               

              from bar

                choice

                  when a

                  when b

              • 4. Re: message routing with choice option within choice option
                lyfe

                worked beautifully...thanks