You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Tim Dudgeon <td...@gmail.com> on 2012/09/09 16:09:09 UTC
Surviving exceptions during splitting
I've got a route that splits a large file into records, using a splitter.
Its basically working but I can't get it to tolerate errors during the
splitting. The route terminates on the first error, but I want that
error to be caught so that the bad record can be logged and processing
continue with the next record.
I'm trying something like this in Groovy, but its not working.
camelContext.addRoutes(new RouteBuilder() {
def void configure() {
onException(IOException).handled(true).log('ERROR')
from("file://C:/Users/username/tmp/examples/in?fileName=letters.txt")
.log('Processing file ${header.CamelFileName}')
.split(bean('splitter', 'split')).streaming()
.log('Found ${body}')
}
})
My simple example splits the text in the file into individual
characters, but throws IOException when a 'Z' is encountered.
The route halts at the first 'Z'.
What am I doing wrong?
Thanks
Tim
Re: Surviving exceptions during splitting
Posted by Tim Dudgeon <td...@gmail.com>.
Hi,
I'm using 2.10 version.
Yes, its a custom splitter so I could handle the exception. But not sure
what I would do with it, or whethr that is really a good thing to do.
stopOnException seems to relate to exceptions that occur downstream of
the splitter, not from the splitting itself?
And I'm not needing to aggregate the results, so don't need an
AggregationStrategy.
Thanks
Tim
On 09/09/2012 16:58, Christian Müller wrote:
> Which version of Camel do you use [1]?
> Checkout [2] -> stopOnException how to continue if an exception occurs (use
> a custom AggregationStrategy).
> And because it's a custom splitter, you have the full control how to handle
> the error...
>
> [1] http://camel.apache.org/how-can-i-get-help.html
> [2] http://camel.apache.org/splitter.html
>
> Best,
> Christian
>
> On Sun, Sep 9, 2012 at 4:09 PM, Tim Dudgeon <td...@gmail.com> wrote:
>
>> I've got a route that splits a large file into records, using a splitter.
>> Its basically working but I can't get it to tolerate errors during the
>> splitting. The route terminates on the first error, but I want that error
>> to be caught so that the bad record can be logged and processing continue
>> with the next record.
>> I'm trying something like this in Groovy, but its not working.
>>
>> camelContext.addRoutes(new RouteBuilder() {
>> def void configure() {
>>
>> onException(IOException).**handled(true).log('ERROR')
>>
>> from("file://C:/Users/**username/tmp/examples/in?**fileName=letters.txt")
>> .log('Processing file ${header.CamelFileName}')
>> .split(bean('splitter', 'split')).streaming()
>> .log('Found ${body}')
>> }
>> })
>>
>>
>> My simple example splits the text in the file into individual characters,
>> but throws IOException when a 'Z' is encountered.
>> The route halts at the first 'Z'.
>> What am I doing wrong?
>>
>> Thanks
>> Tim
>>
>>
>>
>
> --
>
Re: Surviving exceptions during splitting
Posted by Christian Müller <ch...@gmail.com>.
Which version of Camel do you use [1]?
Checkout [2] -> stopOnException how to continue if an exception occurs (use
a custom AggregationStrategy).
And because it's a custom splitter, you have the full control how to handle
the error...
[1] http://camel.apache.org/how-can-i-get-help.html
[2] http://camel.apache.org/splitter.html
Best,
Christian
On Sun, Sep 9, 2012 at 4:09 PM, Tim Dudgeon <td...@gmail.com> wrote:
> I've got a route that splits a large file into records, using a splitter.
> Its basically working but I can't get it to tolerate errors during the
> splitting. The route terminates on the first error, but I want that error
> to be caught so that the bad record can be logged and processing continue
> with the next record.
> I'm trying something like this in Groovy, but its not working.
>
> camelContext.addRoutes(new RouteBuilder() {
> def void configure() {
>
> onException(IOException).**handled(true).log('ERROR')
>
> from("file://C:/Users/**username/tmp/examples/in?**fileName=letters.txt")
> .log('Processing file ${header.CamelFileName}')
> .split(bean('splitter', 'split')).streaming()
> .log('Found ${body}')
> }
> })
>
>
> My simple example splits the text in the file into individual characters,
> but throws IOException when a 'Z' is encountered.
> The route halts at the first 'Z'.
> What am I doing wrong?
>
> Thanks
> Tim
>
>
>
--
Re: Surviving exceptions during splitting
Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Sep 10, 2012 at 8:36 AM, Tim Dudgeon <td...@gmail.com> wrote:
> On 10/09/2012 07:04, Claus Ibsen wrote:
>>
>> Where from is the IOException being thrown
>
> From within the next() method of the Iterator that the splitter generates.
>
Yeah the expression is not intended to throw exceptions, you need to
deal with that yourself.
> Tim
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Re: Surviving exceptions during splitting
Posted by Tim Dudgeon <td...@gmail.com>.
On 10/09/2012 07:04, Claus Ibsen wrote:
> Where from is the IOException being thrown
From within the next() method of the Iterator that the splitter generates.
Tim
Re: Surviving exceptions during splitting
Posted by Claus Ibsen <cl...@gmail.com>.
On Sun, Sep 9, 2012 at 4:09 PM, Tim Dudgeon <td...@gmail.com> wrote:
> I've got a route that splits a large file into records, using a splitter.
> Its basically working but I can't get it to tolerate errors during the
> splitting. The route terminates on the first error, but I want that error to
> be caught so that the bad record can be logged and processing continue with
> the next record.
> I'm trying something like this in Groovy, but its not working.
>
> camelContext.addRoutes(new RouteBuilder() {
> def void configure() {
>
> onException(IOException).handled(true).log('ERROR')
>
> from("file://C:/Users/username/tmp/examples/in?fileName=letters.txt")
> .log('Processing file ${header.CamelFileName}')
> .split(bean('splitter', 'split')).streaming()
> .log('Found ${body}')
> }
> })
>
>
> My simple example splits the text in the file into individual characters,
> but throws IOException when a 'Z' is encountered.
> The route halts at the first 'Z'.
> What am I doing wrong?
>
Where from is the IOException being thrown?
> Thanks
> Tim
>
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen