You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by balavino <ba...@gmail.com> on 2014/08/30 09:41:24 UTC

Camel Splitter EIP to process xml file

I have a requirement to stream an xml file from a server <streamXMLFile> and
divide the original xml to sub xml files based on a tag and also to extract
the value of a particular xml tag path from the splitted xml's then to
create a map with the extracted value and the split xml file <recordBuilder>
and put all the maps of each split to a list.

/		<route id="processXMLFiles">
			<from uri="ref:activemqQueue" />			
			<process ref="processFileReadyMessage" />
			<process ref="streamXMLFile" />
			<split>
 				<tokenize token="snapshotRecord" xml="true" />
 				<setHeader headerName="subscriberId">
 					<xpath
resultType="java.lang.String">/superTagName/subTagName/@attributeName</xpath>
 				</setHeader>
                                <process ref="recordBuilder" />
                               <process ref="anotherProcessor"/>
                               <process ref="anotherProcessor"/>
 		    </split>
 		</route>/

As the <recordBuilder> process is inside the split tag i'm getting each
split xml file and i have a if condition in the <recordBuilder>  to check
the split size set the created list of maps inside the exchange body as:
/
		if (splitSize == recordNumber) {
		       			exchange.getOut().setBody(snapshotList);
		}/

while this condt is not meet the next processor is invoked with an empty
exchange body. 

if i put the processors outside the split tag, i get the bytestream exchange
body which is actually the output of the <streamXMLFile> process.

How do i make sure i send the list of maps to the successive processors only
after i create the list fully with all the xml splits.





--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Splitter-EIP-to-process-xml-file-tp5755861.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Splitter EIP to process xml file

Posted by balavino <ba...@gmail.com>.
Hi Claus,

Ya aggregation strategy helped me .. thanks! 



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Splitter-EIP-to-process-xml-file-tp5755861p5755875.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Splitter EIP to process xml file

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Is the idea that anotherProcessor is invoked once with the result of
the splitting?

Then you should do move them outside the splitter

 <route id="processXMLFiles">
                        <from uri="ref:activemqQueue" />
                        <process ref="processFileReadyMessage" />
                        <process ref="streamXMLFile" />
                        <split>
                                <tokenize token="snapshotRecord" xml="true" />
                                <setHeader headerName="subscriberId">
                                        <xpath
resultType="java.lang.String">/superTagName/subTagName/@attributeName</xpath>
                                </setHeader>
                                <process ref="recordBuilder" />
                    </split>
                    <process ref="anotherProcessor"/>
                    <process ref="anotherProcessor"/>
               </route>

And then use a custom aggregation strategy where you merge the data
together as the result that is the result of the splitter, which is
routed the the another processors. See the splitter docs how to use an
aggregation strategy.


On Sat, Aug 30, 2014 at 9:41 AM, balavino <ba...@gmail.com> wrote:
> I have a requirement to stream an xml file from a server <streamXMLFile> and
> divide the original xml to sub xml files based on a tag and also to extract
> the value of a particular xml tag path from the splitted xml's then to
> create a map with the extracted value and the split xml file <recordBuilder>
> and put all the maps of each split to a list.
>
> /               <route id="processXMLFiles">
>                         <from uri="ref:activemqQueue" />
>                         <process ref="processFileReadyMessage" />
>                         <process ref="streamXMLFile" />
>                         <split>
>                                 <tokenize token="snapshotRecord" xml="true" />
>                                 <setHeader headerName="subscriberId">
>                                         <xpath
> resultType="java.lang.String">/superTagName/subTagName/@attributeName</xpath>
>                                 </setHeader>
>                                 <process ref="recordBuilder" />
>                                <process ref="anotherProcessor"/>
>                                <process ref="anotherProcessor"/>
>                     </split>
>                 </route>/
>
> As the <recordBuilder> process is inside the split tag i'm getting each
> split xml file and i have a if condition in the <recordBuilder>  to check
> the split size set the created list of maps inside the exchange body as:
> /
>                 if (splitSize == recordNumber) {
>                                         exchange.getOut().setBody(snapshotList);
>                 }/
>
> while this condt is not meet the next processor is invoked with an empty
> exchange body.
>
> if i put the processors outside the split tag, i get the bytestream exchange
> body which is actually the output of the <streamXMLFile> process.
>
> How do i make sure i send the list of maps to the successive processors only
> after i create the list fully with all the xml splits.
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-Splitter-EIP-to-process-xml-file-tp5755861.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/