You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Jean Francois LE BESCONT <jf...@gmail.com> on 2013/03/05 19:32:55 UTC
Handle exception
Hey !
I am trying to catch exception from validation properly.
In a main from route I do :
from ...
[...]
.doTry()
.to("direct:validationAED")
.doCatch(PredicateValidationException.class)
.to("direct:erreurFormatAEDFonctionnelZone")
.doFinally()
[...]
With an :
*from("direct:validationAED")*
* .validate(zonePredicate)*
* .end();*
*
*
*And :*
*
*
from("direct:erreurFormatAEDFonctionnelZone")*
*
.log("Error on : '${body}' ")
.end();
It works but I have polution :
org.apache.camel.processor.validation.PredicateValidationException:
Validation failed for
Predicate[com.mycomp.mediation.aed.ZonePredicate@c21990a]. Exchange[null]
In my log
I have play with :
onException(PredicateValidationException.class).handled(true / false)
.to("mock:err") .end();
If I put false I continue to have log error and if I put true my
direct:erreurFormatAEDFonctionnelZone is not called ...
Any idea of how solve this ?
Thanks !
Re: Handle exception
Posted by Jean Francois LE BESCONT <jf...@gmail.com>.
I answer my own question :)
1/Creation a new Exception MyException.
2/
onException(MyException.class
).to("direct:erreurFormatAEDZone").handled(true).end();
3/
.doTry()
.process(new PredicateValidatingProcessor(zonePredicate) )
.doCatch(Exception.class).throwException(new MyException())
.doFinally()
.to("mock:finally")
.end()
2013/3/5 Jean Francois LE BESCONT <jf...@gmail.com>
> But the rejected line stay in the route ... I have in my output line not
> validated by the process.
> Do you know how to ignore / skip not validate element passed to my error
> direct route ?
>
>
> 2013/3/5 Jean Francois LE BESCONT <jf...@gmail.com>
>
>> Thanks !
>>
>> Very helpfull !
>>
>> I would this way to handle businessException :
>>
>> .doTry()
>> .process(new PredicateValidatingProcessor(zonePredicate))
>> .doCatch(Exception.class).handled(true)
>> .to("direct:erreurFormatAEDZone")
>> .doFinally()
>> .to("mock:finally")
>> .end()
>>
>>
>>
>> 2013/3/5 boday <be...@initekconsulting.com>
>>
>>> if you don't want the error to propagate back up, then set handled(true)
>>> in
>>> your doCatch() block...
>>>
>>> also, don't try to mix try/catch with onException handling of the same
>>> error
>>> class...just pick one or the other
>>>
>>>
>>> jeff wrote
>>> > Hey !
>>> >
>>> > I am trying to catch exception from validation properly.
>>> >
>>> > In a main from route I do :
>>> >
>>> > from ...
>>> > [...]
>>> > .doTry()
>>> > .to("direct:validationAED")
>>> > .doCatch(PredicateValidationException.class)
>>> > .to("direct:erreurFormatAEDFonctionnelZone")
>>> > .doFinally()
>>> > [...]
>>> > With an :
>>> >
>>> > *from("direct:validationAED")*
>>> > * .validate(zonePredicate)*
>>> > * .end();*
>>> > *
>>> > *
>>> > *And :*
>>> > *
>>> > *
>>> > from("direct:erreurFormatAEDFonctionnelZone")*
>>> > *
>>> > .log("Error on : '${body}' ")
>>> > .end();
>>> >
>>> > It works but I have polution :
>>> >
>>> > org.apache.camel.processor.validation.PredicateValidationException:
>>> > Validation failed for
>>> > Predicate[com.mycomp.mediation.aed.ZonePredicate@c21990a].
>>> Exchange[null]
>>> >
>>> > In my log
>>> >
>>> > I have play with :
>>> >
>>> > onException(PredicateValidationException.class).handled(true / false)
>>> > .to("mock:err") .end();
>>> >
>>> > If I put false I continue to have log error and if I put true my
>>> > direct:erreurFormatAEDFonctionnelZone is not called ...
>>> >
>>> >
>>> >
>>> > Any idea of how solve this ?
>>> >
>>> > Thanks !
>>>
>>>
>>>
>>>
>>>
>>> -----
>>> Ben O'Day
>>> IT Consultant -http://consulting-notes.com
>>>
>>> --
>>> View this message in context:
>>> http://camel.465427.n5.nabble.com/Handle-exception-tp5728590p5728592.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>
>>
>
Re: Handle exception
Posted by Jean Francois LE BESCONT <jf...@gmail.com>.
But the rejected line stay in the route ... I have in my output line not
validated by the process.
Do you know how to ignore / skip not validate element passed to my error
direct route ?
2013/3/5 Jean Francois LE BESCONT <jf...@gmail.com>
> Thanks !
>
> Very helpfull !
>
> I would this way to handle businessException :
>
> .doTry()
> .process(new PredicateValidatingProcessor(zonePredicate))
> .doCatch(Exception.class).handled(true)
> .to("direct:erreurFormatAEDZone")
> .doFinally()
> .to("mock:finally")
> .end()
>
>
>
> 2013/3/5 boday <be...@initekconsulting.com>
>
>> if you don't want the error to propagate back up, then set handled(true)
>> in
>> your doCatch() block...
>>
>> also, don't try to mix try/catch with onException handling of the same
>> error
>> class...just pick one or the other
>>
>>
>> jeff wrote
>> > Hey !
>> >
>> > I am trying to catch exception from validation properly.
>> >
>> > In a main from route I do :
>> >
>> > from ...
>> > [...]
>> > .doTry()
>> > .to("direct:validationAED")
>> > .doCatch(PredicateValidationException.class)
>> > .to("direct:erreurFormatAEDFonctionnelZone")
>> > .doFinally()
>> > [...]
>> > With an :
>> >
>> > *from("direct:validationAED")*
>> > * .validate(zonePredicate)*
>> > * .end();*
>> > *
>> > *
>> > *And :*
>> > *
>> > *
>> > from("direct:erreurFormatAEDFonctionnelZone")*
>> > *
>> > .log("Error on : '${body}' ")
>> > .end();
>> >
>> > It works but I have polution :
>> >
>> > org.apache.camel.processor.validation.PredicateValidationException:
>> > Validation failed for
>> > Predicate[com.mycomp.mediation.aed.ZonePredicate@c21990a].
>> Exchange[null]
>> >
>> > In my log
>> >
>> > I have play with :
>> >
>> > onException(PredicateValidationException.class).handled(true / false)
>> > .to("mock:err") .end();
>> >
>> > If I put false I continue to have log error and if I put true my
>> > direct:erreurFormatAEDFonctionnelZone is not called ...
>> >
>> >
>> >
>> > Any idea of how solve this ?
>> >
>> > Thanks !
>>
>>
>>
>>
>>
>> -----
>> Ben O'Day
>> IT Consultant -http://consulting-notes.com
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Handle-exception-tp5728590p5728592.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>
Re: Handle exception
Posted by Jean Francois LE BESCONT <jf...@gmail.com>.
Thanks !
Very helpfull !
I would this way to handle businessException :
.doTry()
.process(new PredicateValidatingProcessor(zonePredicate))
.doCatch(Exception.class).handled(true)
.to("direct:erreurFormatAEDZone")
.doFinally()
.to("mock:finally")
.end()
2013/3/5 boday <be...@initekconsulting.com>
> if you don't want the error to propagate back up, then set handled(true) in
> your doCatch() block...
>
> also, don't try to mix try/catch with onException handling of the same
> error
> class...just pick one or the other
>
>
> jeff wrote
> > Hey !
> >
> > I am trying to catch exception from validation properly.
> >
> > In a main from route I do :
> >
> > from ...
> > [...]
> > .doTry()
> > .to("direct:validationAED")
> > .doCatch(PredicateValidationException.class)
> > .to("direct:erreurFormatAEDFonctionnelZone")
> > .doFinally()
> > [...]
> > With an :
> >
> > *from("direct:validationAED")*
> > * .validate(zonePredicate)*
> > * .end();*
> > *
> > *
> > *And :*
> > *
> > *
> > from("direct:erreurFormatAEDFonctionnelZone")*
> > *
> > .log("Error on : '${body}' ")
> > .end();
> >
> > It works but I have polution :
> >
> > org.apache.camel.processor.validation.PredicateValidationException:
> > Validation failed for
> > Predicate[com.mycomp.mediation.aed.ZonePredicate@c21990a].
> Exchange[null]
> >
> > In my log
> >
> > I have play with :
> >
> > onException(PredicateValidationException.class).handled(true / false)
> > .to("mock:err") .end();
> >
> > If I put false I continue to have log error and if I put true my
> > direct:erreurFormatAEDFonctionnelZone is not called ...
> >
> >
> >
> > Any idea of how solve this ?
> >
> > Thanks !
>
>
>
>
>
> -----
> Ben O'Day
> IT Consultant -http://consulting-notes.com
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Handle-exception-tp5728590p5728592.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Re: Handle exception
Posted by boday <be...@initekconsulting.com>.
if you don't want the error to propagate back up, then set handled(true) in
your doCatch() block...
also, don't try to mix try/catch with onException handling of the same error
class...just pick one or the other
jeff wrote
> Hey !
>
> I am trying to catch exception from validation properly.
>
> In a main from route I do :
>
> from ...
> [...]
> .doTry()
> .to("direct:validationAED")
> .doCatch(PredicateValidationException.class)
> .to("direct:erreurFormatAEDFonctionnelZone")
> .doFinally()
> [...]
> With an :
>
> *from("direct:validationAED")*
> * .validate(zonePredicate)*
> * .end();*
> *
> *
> *And :*
> *
> *
> from("direct:erreurFormatAEDFonctionnelZone")*
> *
> .log("Error on : '${body}' ")
> .end();
>
> It works but I have polution :
>
> org.apache.camel.processor.validation.PredicateValidationException:
> Validation failed for
> Predicate[com.mycomp.mediation.aed.ZonePredicate@c21990a]. Exchange[null]
>
> In my log
>
> I have play with :
>
> onException(PredicateValidationException.class).handled(true / false)
> .to("mock:err") .end();
>
> If I put false I continue to have log error and if I put true my
> direct:erreurFormatAEDFonctionnelZone is not called ...
>
>
>
> Any idea of how solve this ?
>
> Thanks !
-----
Ben O'Day
IT Consultant -http://consulting-notes.com
--
View this message in context: http://camel.465427.n5.nabble.com/Handle-exception-tp5728590p5728592.html
Sent from the Camel - Users mailing list archive at Nabble.com.