3 Replies Latest reply on May 29, 2013 2:22 AM by davsclaus

    How to convert a table record to xml format?

    axw1234

      Hi all,

       

      I am newer to camel and fuse. I have a route to select a record from database then convert to xml file or stream.

      my route is:

       

      . It will not have any advantage if I convert a string to xml.

        • 1. Re: How to convert a table record to xml format?
          davsclaus

          The SQL component returns the data as a List type. So you cannot convert that to a Map etc.

           

          If you know there is only 1 row selected, then you can transform the message and pickup the first row as shown below

           

          <to uri="sql:{{sql.selectCalls}}"/>
          <transform>
            <simple>${body[0]}</simple>
          </transform>
          ...
          

           

          Then the message body would be a Map now.

           

          Then the {{processCalls}} method on your bean, should have a Map as its type for the 1st parameter in the method signature.

           

          There is a ticket to improve SQL component in the future so you can tell it what output type you want: https://issues.apache.org/jira/browse/CAMEL-6366

          • 2. Re: How to convert a table record to xml format?
            axw1234

            Thank you very much.

            I got the Map struct for the record.

             

            Now I have multi records and try to using loop to fetch the data. First I hard code the

            the size is 2, it repeat twice.

             

                   

            or

                  something like "CamelLoopSize" and "CamelLoopIndex".

            Could you give me details about how to using them.

             

            Thank you.

            • 3. Re: How to convert a table record to xml format?
              davsclaus

              Hi

               

              See about the splitter EIP pattern

              http://camel.apache.org/splitter

               

              ...
              <to uri="sql:{{sql.selectCalls}}"/>
              <split>
                <simple>body</simple>
                <to uri="bean:callsBean?method=processCalls"></to>
                <to uri="log:foo"></to>
               </split>
              

               

              Edited by: davsclaus on May 29, 2013 6:21 AM