You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by contactreji <co...@gmail.com> on 2015/04/07 09:27:15 UTC

Camel LOOP

Hi

Basically, I am trying to develop a module which pushes the customer records
into database. Incoming XML contains multiple customer records.

I am wondering how I can use the CamelLoopIndex property while looping
through xml records.
I have some code like follows. 

I want to loop through records while parsing them using Xpath expressions to
set them into the exchange property which later be used in camel sql insert
statement.

Can someone give me the syntax? Do I have to put the xpath expression inside
the camel simple to access the property CamelLoopIndex ??
*
<camel:when>
					<camel:simple>${in.header.operationName} ==
'CreateOperation'</camel:simple>
					<camel:loop>
					
					
<camel:xpath>count(//CustomerRecords/Record[${in.header.CamelLoopIndex}]/Cust_ID/text())</camel:xpath>
						<camel:setProperty propertyName="customerID">
							<camel:xpath>//CustomerRecords/Record/Cust_ID/text()</camel:xpath>
						</camel:setProperty>
						<camel:setProperty propertyName="customerName">
							<camel:xpath>//CustomerRecords/Record/Cust_Name/text()</camel:xpath>
						</camel:setProperty>
						<camel:setProperty propertyName="customerAddress">
						
<camel:xpath>//CustomerRecords/Record/Cust_Address/text()</camel:xpath>
						</camel:setProperty>
						<camel:setProperty propertyName="customerBalance">
						
<camel:xpath>//CustomerRecords/Record/Cust_Balance/text()</camel:xpath>
						</camel:setProperty>
						<camel:setProperty propertyName="customerPhoneNo">
							<camel:xpath>//CustomerRecords/Record/Cust_Phone/text()</camel:xpath>
						</camel:setProperty>
						<camel:setProperty propertyName="customerPostalPIN">
							<camel:xpath>//CustomerRecords/Record/Cust_PIN/text()</camel:xpath>
						</camel:setProperty>
						<camel:setBody>
							<camel:simple>insert into customer
values('${property.customerID}','${property.customerName}','${property.customerAddress}','${property.customerBalance}','${property.customerPhoneNo}','${property.customerPostalPIN}')</camel:simple>
						</camel:setBody>
						<camel:to uri="jdbc:dataSource" />
					</camel:loop>
				</camel:when>*




-----
Reji Mathews
Sr. Developer - Middleware Integration / SOA ( Open Source - Apache Camel & Jboss Fuse ESB | Mule ESB )
LinkedIn - http://in.linkedin.com/pub/reji-mathews/31/9a2/40a
Twitter - reji_mathews
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-LOOP-tp5765424.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel LOOP

Posted by contactreji <co...@gmail.com>.
And I tried using Xquery this way

*	<camel:when>
					<camel:simple>${in.header.operationName} ==
'CreateOperation'</camel:simple>
					<camel:setProperty propertyName="recordCount">
						<camel:xquery>count(//CustomerRecords/Record)</camel:xquery>
					</camel:setProperty>
					<camel:log message="Count = ${property.recordCount}"
						loggingLevel="INFO" logName="Log" />*

it returns following exception

org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to
insert a node where it is not permitted.

The incoming XML is as follows
*<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <CustomerRecords>
         
         <Record>
            <Cust_ID>1010</Cust_ID>
            <Cust_Name>REJI MATHEWS</Cust_Name>
            <Cust_Address>7TH MAIN, BANGALORE</Cust_Address>
            <Cust_Balance>1000</Cust_Balance>
            <Cust_Phone>+4231213</Cust_Phone>
            <Cust_PIN>560043</Cust_PIN>
         </Record>
           <Record>
            <Cust_ID>1004</Cust_ID>
            <Cust_Name>REJI MATHEWS</Cust_Name>
            <Cust_Address>7TH MAIN, BANASAWADI, BANGALORE</Cust_Address>
            <Cust_Balance>1000</Cust_Balance>
            <Cust_Phone>+23232</Cust_Phone>
            <Cust_PIN>560043</Cust_PIN>
         </Record>

  <Record>
            <Cust_ID>1006</Cust_ID>
            <Cust_Name>REJI MATHEWS</Cust_Name>
            <Cust_Address>7TH MAIN, BANGALORE</Cust_Address>
            <Cust_Balance>1000</Cust_Balance>
            <Cust_Phone>123</Cust_Phone>
            <Cust_PIN>560043</Cust_PIN>
         </Record>

      </CustomerRecords>
   </soapenv:Body>
</soapenv:Envelope>*



-----
Reji Mathews
Sr. Developer - Middleware Integration / SOA ( Open Source - Apache Camel & Jboss Fuse ESB | Mule ESB )
LinkedIn - http://in.linkedin.com/pub/reji-mathews/31/9a2/40a
Twitter - reji_mathews
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-LOOP-tp5765424p5765429.html
Sent from the Camel - Users mailing list archive at Nabble.com.