You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Daniel Frey <qw...@gmx.ch> on 2010/02/09 10:24:08 UTC

Nested doTry and choice blocks

Hi there

I would like to nest exception handling and choice like this:

from(queue)
    .doTry()
        .choice()
            .when().xpath("/StaticDataServiceRequest")
            .when().xpath("/StaticDataServicePing").bean(handler,
"processPingRequest")
            .otherwise().throwException(new
StaticDataServiceHandlerException("unknown request type"))
        .end()
    .doCatch(Exception.class) // fails to compile
        .handled(false)
        .bean(handler, "processException")
    .end();

of if necessary the other way round:

from(queue)
    .choice()
        .when().xpath("/StaticDataServiceRequest")
            .doTry()
                .bean(handler, "processCacheRequest")
            .doCatch(Exception.class)
                .bean(handler, "processException")
            .end();
        .when().xpath("/StaticDataServicePing")
            .doTry()
                .bean(handler, "processPingRequest")
            .doCatch(Exception.class)
                .bean(handler, "processException")
            .end();
        .otherwise().bean(handler, "processUnknownRequest")
    .end()

In both cases Camel returns a ProcessorExpression at the end of the choice
in the first case and the end of the try in the second, which does not
provide a doCatch. Is there a way to get this combination working?

Thanks in advance
Daniel
-- 
View this message in context: http://old.nabble.com/Nested-doTry-and-choice-blocks-tp27512473p27512473.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Nested doTry and choice blocks

Posted by Daniel Frey <qw...@gmx.ch>.
Thanks for the hint, will follow that approach.
Cheers, Daniel
-- 
View this message in context: http://old.nabble.com/Nested-doTry-and-choice-blocks-tp27512473p27512803.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Nested doTry and choice blocks

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

The JDK language is not really suited well for DSL like and you can
only stretch it as far we have done with Camel.
There are some cases where you cannot just keep adding methods and
expect the scope to appear correctly.

You can use onException instead of try .. catch stuff and have error
handling logic in another place and keep route logic clean.
Then the DSL in Java should be possible to do more easily.


On Tue, Feb 9, 2010 at 10:24 AM, Daniel Frey <qw...@gmx.ch> wrote:
>
> Hi there
>
> I would like to nest exception handling and choice like this:
>
> from(queue)
>    .doTry()
>        .choice()
>            .when().xpath("/StaticDataServiceRequest")
>            .when().xpath("/StaticDataServicePing").bean(handler,
> "processPingRequest")
>            .otherwise().throwException(new
> StaticDataServiceHandlerException("unknown request type"))
>        .end()
>    .doCatch(Exception.class) // fails to compile
>        .handled(false)
>        .bean(handler, "processException")
>    .end();
>
> of if necessary the other way round:
>
> from(queue)
>    .choice()
>        .when().xpath("/StaticDataServiceRequest")
>            .doTry()
>                .bean(handler, "processCacheRequest")
>            .doCatch(Exception.class)
>                .bean(handler, "processException")
>            .end();
>        .when().xpath("/StaticDataServicePing")
>            .doTry()
>                .bean(handler, "processPingRequest")
>            .doCatch(Exception.class)
>                .bean(handler, "processException")
>            .end();
>        .otherwise().bean(handler, "processUnknownRequest")
>    .end()
>
> In both cases Camel returns a ProcessorExpression at the end of the choice
> in the first case and the end of the try in the second, which does not
> provide a doCatch. Is there a way to get this combination working?
>
> Thanks in advance
> Daniel
> --
> View this message in context: http://old.nabble.com/Nested-doTry-and-choice-blocks-tp27512473p27512473.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus