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

Search Discussions

  • Claus Ibsen at Sep 11, 2012 at 2:21 pm
    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
    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
  • Vishal1981 at Sep 11, 2012 at 2:26 pm
    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.
  • Andreas Jacobsen at Sep 11, 2012 at 4:16 pm
    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 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.
  • Mitko Kolev at Sep 11, 2012 at 8:18 pm
    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 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 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.
  • Andreas Jacobsen at Sep 13, 2012 at 9:35 am
    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 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 <vishal.changrani@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.
  • Andreas Jacobsen at Oct 1, 2012 at 8:57 am

    On 30 September 2012 11:57, Claus Ibsen 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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriescamel
postedSep 11, '12 at 4:04a
activeOct 1, '12 at 8:57a
posts7
users4
websitecamel.apache.org

People

Translate

site design / logo © 2022 Grokbase