Forum Home » Fuse Distributions » Fuse Mediation Router

Thread: The splitter - how does it work ?

 
This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 5 - Last Post: Apr 27, 2012 3:46 PM Last Post By: davsclaus
nicolasduminil

Posts: 87
Registered: 02/24/09
The splitter - how does it work ?
Posted: Apr 26, 2012 10:58 AM
 
  Click to reply to this thread Reply
Greetings,

Looking at the splitter, I was thinking that it is recursive. I mean, given a route like the following:

from("...").split(body().tokenize("...")).streaming().unmarshal(new JaxbDataFormat(...))

it would go through the whole file and it will cyclicly take each record (delimited by the token) and unmarshall it, etc.

But after having tested it, it seems that it only does it with the first record, ie until it finds the first occurrence of the token. Looking in the documentation at the "What the splitter returns", it says that it returns the last splitted message which, in my case, is the first record in the file. So this is what happened.

But I'm confused now as I need to cycle, occurrence of token by occurrence of token, until the end of the file.

How could I don this ?

Many thanks in advance,

Nicolas
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: The splitter - how does it work ?
Posted: Apr 26, 2012 11:27 AM   in response to: nicolasduminil in response to: nicolasduminil
 
  Click to reply to this thread Reply
It will iterate the expression, so in your case you are tokenizing the message body. Camel uses the java.util.Scanner when you use the tokenize in the DSL. So make sure that this tokenizer works as expected.
nicolasduminil

Posts: 87
Registered: 02/24/09
Re: The splitter - how does it work ?
Posted: Apr 26, 2012 1:49 PM   in response to: davsclaus in response to: davsclaus
 
  Click to reply to this thread Reply
Hi Claus,

Thank you for helping again. Yes, the problem comes from the tokenizer. I made a separate test using the java.util.Scanner and it appears that it doesn't work as I expected. I have an XML file and I want to split it XML element by XML element.

For example:

<0>
<a>11111111111</a>
<b>22222222222</b>
............................
</0>

And i use "</0>" as a tokenizer but, what happens is that the tokenizer itself, ie "</0>", is not included. Is there any option to specify a splitting such that to have every thing between <0> and </0>, including <0> and </0>, i any splited part ?

Many thanks in advance,

Nicolas
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: The splitter - how does it work ?
Posted: Apr 26, 2012 3:09 PM   in response to: nicolasduminil in response to: nicolasduminil
 
  Click to reply to this thread Reply
Hi

If you XML file is not big, you can use xpath instead. But that would mean the file content is loaded into memory.
<split>
<xpath>/0</xpath>
...
</split>

And for splitting big files see a few blog posts I did
http://davsclaus.blogspot.se/2011/11/splitting-big-xml-files-with-apache.html
http://davsclaus.blogspot.com/2011/11/splitting-big-xml-files-with-apache_24.html
nicolasduminil

Posts: 87
Registered: 02/24/09
Re: The splitter - how does it work ?
Posted: Apr 27, 2012 3:44 PM   in response to: davsclaus in response to: davsclaus
 
  Click to reply to this thread Reply
Hi Claus,

Many thanks. The current file is not too big and the splitting works for now, but it may become much larger. The problem is that the stax parsing and the XML tokens are supported, as far as I understood, starting with Camel 2.9 which is not yet available in download on the FuseSource web-site. It may be available at the Apache site but we are using the FuseSource one.

Kind regards,

Nicolas
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: The splitter - how does it work ?
Posted: Apr 27, 2012 3:46 PM   in response to: nicolasduminil in response to: nicolasduminil
 
  Click to reply to this thread Reply
Yeah Fuse Camel 2.9 will be released as part of the upcoming Fuse ESB Enterprise.
http://fusesource.com/press-releases/fusesource-press-release-04-10-2012/