2 Replies Latest reply on Feb 3, 2012 4:06 PM by timgstewart

    Loop in a CAMEL route

    mpalvankar

      Based on the request, I need to invoke external web service multiple times. I've taken a look at http://camel.apache.org/loop.html but that one requires me to know the total number of loops; which I do not have or which I need to calculate based on the elements in the request.

       

      For example:

       

      My request is ab below and based on the report elements, I need to invoke external service.

       

      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

            

           <soapenv:Body>

                <tns:getReportsRequest

                xmlns:tns="http://ubs.com/wma/wmf/service/report/v1.0">

                     <tns:reports>

                          <tns:report>

                               <tns:reportID>123</tns:reportID>

                               <tns:reportRequest></tns:reportRequest>

                          </tns:report>

                          <tns:report>

                               <tns:reportID>786</tns:reportID>

                               <tns:reportRequest></tns:reportRequest>

                          </tns:report>

                     </tns:reports>

                </tns:getReportsRequest>

           </soapenv:Body>

      </soapenv:Envelope>

       

      Any solution please?

        • 1. Re: Loop in a CAMEL route
          davsclaus

          There is a Dynamic Router you can use. It can route to an endpoint, an it will re-evaluate an expression each time. Mind that you need to return null for the expression, when you are done.

           

          http://fusesource.com/docs/router/2.8/eip/_IDU_DynamicRouter.html

           

          And btw we will possible in the future look at making the loop be like a while loop instead. But for now its a fixed for loop.

          • 2. Re: Loop in a CAMEL route
            timgstewart

            I did something similar with this by splitting the incoming XML on an XPath to make multiple messages, then passing those individual messages onto another route that does something to each one:

             

             

            from("direct:splitReports").split(xpath("/*//report")).to("direct:handleReport");

             

            from("direct:handleReport")......