You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by vishal1981 <vi...@ericsson.com> on 2012/09/11 06:04:02 UTC

Global exception policy across Route builder configure methods

Hi,
If I understand correctly, the onException() defined in the configure method
of a Routebuilder is global across all routes subsequently defined in that
method using the Camel DSL.
Is there a way to make these onException() global across routebuilder such
that I can define in one place something like,
onException(myexception.class).to(mybean)
onException(myexception2.class).to(mybean2)
just once for apply it to all possible routes (some of which may be added
later) in the given camel context irrespective of the route builder used to
create them?

Thanks in advance,
-v-



--
View this message in context: http://camel.465427.n5.nabble.com/Global-exception-policy-across-Route-builder-configure-methods-tp5719075.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Global exception policy across Route builder configure methods

Posted by Andreas Jacobsen <an...@andreasjacobsen.com>.
On 30 September 2012 11:57, Claus Ibsen <cl...@gmail.com> wrote:
>> [0]: https://issues.apache.org/jira/browse/CAMEL-5456
>>
>
> I finally got some time to help with this, and have fixed the issue reported.
>
> I also updated the error handler docs to better reflect the scopes for
> Java DSL vs XML DSLs.
> http://camel.apache.org/error-handling-in-camel.html
>

Thank you very much for taking the time to look at this :)

-Andreas

Re: Global exception policy across Route builder configure methods

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Sep 13, 2012 at 11:34 AM, Andreas Jacobsen
<an...@andreasjacobsen.com> wrote:
> That doesn't match my experiences. I've stepped through the
> DefaultExceptionPolicyStrategy and global scope is definitely global
> in Java DSL routebuilders too. I wish the documentation were more
> clear on what the expected behavior should be.
>
> I've created CAMEL-5456[0] because I thought it was meant to be
> routebuilder-scoped, but if it's actually global to the camelcontext,
> I'm very unhappy with the implementation.
>
> Perhaps a dev could chime in and clarify the intent and suggested use?
> The pattern Claus suggested works fine until you start using more
> complex setups…
>
> [0]: https://issues.apache.org/jira/browse/CAMEL-5456
>

I finally got some time to help with this, and have fixed the issue reported.

I also updated the error handler docs to better reflect the scopes for
Java DSL vs XML DSLs.
http://camel.apache.org/error-handling-in-camel.html



> On 11 September 2012 22:17, Mitko Kolev <me...@gmail.com> wrote:
>> Hi,
>>
>> the "global" scope mentioned here
>> http://camel.apache.org/exception-clause.html in this case actually means
>> "route builder" scope.
>> For example the rule for ValidationException will trigger for both routes
>> in the same route builder (at least with the Camel version 2.6.x with which
>> I did the test to find this out some months ago)
>>
>> configure(){
>> ...
>> onException(ValidationException.class).
>>   to("activemq:validationFailed");
>>
>> from("seda:inputA").
>>   to("validation:foo/bar.xsd", "activemq:someQueue");
>>
>> from("seda:inputB").to("direct:foo").
>>   to("rnc:mySchema.rnc", "activemq:anotherQueue");
>> }
>>
>> However, if you split this in 2 route builders like this
>>
>> configure(){
>> ...
>> onException(ValidationException.class).
>>   to("activemq:validationFailed");
>>
>> from("seda:inputB").to("direct:foo").
>>   to("rnc:mySchema.rnc", "activemq:anotherQueue");
>> }
>>
>> &
>>
>> configure(){
>> ...
>> from("seda:inputB").to("direct:foo").
>>   to("rnc:mySchema.rnc", "activemq:anotherQueue");
>> }
>>
>> the onException will not process ValidationExceptions from the second route
>> ("seda:inputB"). In this sense the onException clause is not context
>> scoped, but rather route builder scoped.
>>
>> I guess the confusion comes from the Sping DSL format, as the onException
>> clause is within the camelContext tag, so you might think the onException
>> definition is "camel context" scoped (configuration of the camel context).
>>
>>
>> Regards,
>> Mitko
>>
>> On Tue, Sep 11, 2012 at 6:14 PM, Andreas Jacobsen <
>> andreas@andreasjacobsen.com> wrote:
>>
>>> My understanding is that exception policies defined in global scope
>>> are actually global. You could set up a seperate routebuilder
>>> specifically for the global exception policies.
>>>
>>> Claus's suggestion works too, since the same exception policies will
>>> be created several times.
>>>
>>> On 11 September 2012 16:26, vishal1981 <vi...@ericsson.com>
>>> wrote:
>>> > Alright thanks.
>>> > But then global scope doesn't really means global to the camelcontext.
>>> Its
>>> > global to the routes currently being defined.
>>> > Thanks for your help
>>> >
>>> >
>>> >
>>> > --
>>> > View this message in context:
>>> http://camel.465427.n5.nabble.com/Global-exception-policy-across-Route-builder-configure-methods-tp5719075p5719131.html
>>> > Sent from the Camel - Users mailing list archive at Nabble.com.
>>>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Global exception policy across Route builder configure methods

Posted by Andreas Jacobsen <an...@andreasjacobsen.com>.
That doesn't match my experiences. I've stepped through the
DefaultExceptionPolicyStrategy and global scope is definitely global
in Java DSL routebuilders too. I wish the documentation were more
clear on what the expected behavior should be.

I've created CAMEL-5456[0] because I thought it was meant to be
routebuilder-scoped, but if it's actually global to the camelcontext,
I'm very unhappy with the implementation.

Perhaps a dev could chime in and clarify the intent and suggested use?
The pattern Claus suggested works fine until you start using more
complex setups…

[0]: https://issues.apache.org/jira/browse/CAMEL-5456

On 11 September 2012 22:17, Mitko Kolev <me...@gmail.com> wrote:
> Hi,
>
> the "global" scope mentioned here
> http://camel.apache.org/exception-clause.html in this case actually means
> "route builder" scope.
> For example the rule for ValidationException will trigger for both routes
> in the same route builder (at least with the Camel version 2.6.x with which
> I did the test to find this out some months ago)
>
> configure(){
> ...
> onException(ValidationException.class).
>   to("activemq:validationFailed");
>
> from("seda:inputA").
>   to("validation:foo/bar.xsd", "activemq:someQueue");
>
> from("seda:inputB").to("direct:foo").
>   to("rnc:mySchema.rnc", "activemq:anotherQueue");
> }
>
> However, if you split this in 2 route builders like this
>
> configure(){
> ...
> onException(ValidationException.class).
>   to("activemq:validationFailed");
>
> from("seda:inputB").to("direct:foo").
>   to("rnc:mySchema.rnc", "activemq:anotherQueue");
> }
>
> &
>
> configure(){
> ...
> from("seda:inputB").to("direct:foo").
>   to("rnc:mySchema.rnc", "activemq:anotherQueue");
> }
>
> the onException will not process ValidationExceptions from the second route
> ("seda:inputB"). In this sense the onException clause is not context
> scoped, but rather route builder scoped.
>
> I guess the confusion comes from the Sping DSL format, as the onException
> clause is within the camelContext tag, so you might think the onException
> definition is "camel context" scoped (configuration of the camel context).
>
>
> Regards,
> Mitko
>
> On Tue, Sep 11, 2012 at 6:14 PM, Andreas Jacobsen <
> andreas@andreasjacobsen.com> wrote:
>
>> My understanding is that exception policies defined in global scope
>> are actually global. You could set up a seperate routebuilder
>> specifically for the global exception policies.
>>
>> Claus's suggestion works too, since the same exception policies will
>> be created several times.
>>
>> On 11 September 2012 16:26, vishal1981 <vi...@ericsson.com>
>> wrote:
>> > Alright thanks.
>> > But then global scope doesn't really means global to the camelcontext.
>> Its
>> > global to the routes currently being defined.
>> > Thanks for your help
>> >
>> >
>> >
>> > --
>> > View this message in context:
>> http://camel.465427.n5.nabble.com/Global-exception-policy-across-Route-builder-configure-methods-tp5719075p5719131.html
>> > Sent from the Camel - Users mailing list archive at Nabble.com.
>>

Re: Global exception policy across Route builder configure methods

Posted by Mitko Kolev <me...@gmail.com>.
Hi,

the "global" scope mentioned here
http://camel.apache.org/exception-clause.html in this case actually means
"route builder" scope.
For example the rule for ValidationException will trigger for both routes
in the same route builder (at least with the Camel version 2.6.x with which
I did the test to find this out some months ago)

configure(){
...
onException(ValidationException.class).
  to("activemq:validationFailed");

from("seda:inputA").
  to("validation:foo/bar.xsd", "activemq:someQueue");

from("seda:inputB").to("direct:foo").
  to("rnc:mySchema.rnc", "activemq:anotherQueue");
}

However, if you split this in 2 route builders like this

configure(){
...
onException(ValidationException.class).
  to("activemq:validationFailed");

from("seda:inputB").to("direct:foo").
  to("rnc:mySchema.rnc", "activemq:anotherQueue");
}

&

configure(){
...
from("seda:inputB").to("direct:foo").
  to("rnc:mySchema.rnc", "activemq:anotherQueue");
}

the onException will not process ValidationExceptions from the second route
("seda:inputB"). In this sense the onException clause is not context
scoped, but rather route builder scoped.

I guess the confusion comes from the Sping DSL format, as the onException
clause is within the camelContext tag, so you might think the onException
definition is "camel context" scoped (configuration of the camel context).


Regards,
Mitko

On Tue, Sep 11, 2012 at 6:14 PM, Andreas Jacobsen <
andreas@andreasjacobsen.com> wrote:

> My understanding is that exception policies defined in global scope
> are actually global. You could set up a seperate routebuilder
> specifically for the global exception policies.
>
> Claus's suggestion works too, since the same exception policies will
> be created several times.
>
> On 11 September 2012 16:26, vishal1981 <vi...@ericsson.com>
> wrote:
> > Alright thanks.
> > But then global scope doesn't really means global to the camelcontext.
> Its
> > global to the routes currently being defined.
> > Thanks for your help
> >
> >
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/Global-exception-policy-across-Route-builder-configure-methods-tp5719075p5719131.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Global exception policy across Route builder configure methods

Posted by Andreas Jacobsen <an...@andreasjacobsen.com>.
My understanding is that exception policies defined in global scope
are actually global. You could set up a seperate routebuilder
specifically for the global exception policies.

Claus's suggestion works too, since the same exception policies will
be created several times.

On 11 September 2012 16:26, vishal1981 <vi...@ericsson.com> wrote:
> Alright thanks.
> But then global scope doesn't really means global to the camelcontext. Its
> global to the routes currently being defined.
> Thanks for your help
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Global-exception-policy-across-Route-builder-configure-methods-tp5719075p5719131.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Global exception policy across Route builder configure methods

Posted by vishal1981 <vi...@ericsson.com>.
Alright thanks.
But then global scope doesn't really means global to the camelcontext. Its
global to the routes currently being defined.
Thanks for your help



--
View this message in context: http://camel.465427.n5.nabble.com/Global-exception-policy-across-Route-builder-configure-methods-tp5719075p5719131.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Global exception policy across Route builder configure methods

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

You can create a base class, and setup those onException in the
configure method. And the in sub classes, call super.configure()
first.


On Tue, Sep 11, 2012 at 6:04 AM, vishal1981
<vi...@ericsson.com> wrote:
> Hi,
> If I understand correctly, the onException() defined in the configure method
> of a Routebuilder is global across all routes subsequently defined in that
> method using the Camel DSL.
> Is there a way to make these onException() global across routebuilder such
> that I can define in one place something like,
> onException(myexception.class).to(mybean)
> onException(myexception2.class).to(mybean2)
> just once for apply it to all possible routes (some of which may be added
> later) in the given camel context irrespective of the route builder used to
> create them?
>
> Thanks in advance,
> -v-
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Global-exception-policy-across-Route-builder-configure-methods-tp5719075.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
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