You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Marco Mistroni <mm...@gmail.com> on 2012/04/10 22:46:37 UTC

handling exception at endpoints

Hello all
 i'd like to be able to handle exceptions at Endpoints in my app (as most
of the exceptions happen when endpoints are processing data).
as i plan to deploy my camel app remotely, i'd like to handle the exception
so that an email with the exception is sent to me.

i found out this thread with regards to exception handling at endpoints,
and was wondering if any changes have been introduced in camel to handle
exception at endpoints since this post

http://camel.465427.n5.nabble.com/Endpoint-exception-handling-td5504378.html

w/kindest regards
 marco

Re: handling exception at endpoints

Posted by Claus Ibsen <cl...@gmail.com>.
On Sat, Apr 14, 2012 at 1:11 PM, Marco Mistroni <mm...@gmail.com> wrote:
> Hello Claus,
>  sorry to bother, but i am still losing the plot with Exception Handling :(
> i read Camel In action chapter, and this is what i came out with:
>
>    <camel:route>
>            <camel:from uri="seda:processBloombergShares" />
>            <camel:onException>
>                <camel:exception>java.lang.Exception</camel:exception>
>                <camel:handled>
>                    <camel:constant>true</camel:constant>
>                </camel:handled>
>                <camel:to
> uri="bean:exceptionHandler?method=handleException" />
>            </camel:onException>
>
>            <camel:process ref="bloombergProcessor" />
>            <camel:bean ref="bloombergServiceActivator" method="fetchData"
> />
>            <camel:to uri="bean:endpointBean?method=handleBloombergShare" />
>
>   </camel:route>
>
>   the BloombergProcessor is throwing an Exception , as in code b elow
> public void process(Exchange exchange) throws Exception {
>        // TODO Auto-generated method stub
>        Set<String> set = new HashSet<String>();
>
>        set.add("BLOOMBERG-WMT");
>        //set.add("BLOOMBERG-GE");
>
>        String portfolio = (String)exchange.getIn().getBody();
>
>
>
>        throw new Exception("Exception from Bloomberg PRocessor...");
>  }
>
> this is the signature of my exception handler handleException method
>
> public void handleException(Map<?, ?> in, String payload, Map<String,
> Object> out) {
>        LOGGER.info("-------Handling exceptions:");
>        //exceptions.add(exception);
> }
>

When you bean have multiple parameters, you need to tell Camel what is
what. See bean parameter binding for detaisl
http://camel.apache.org/bean-binding.html

And if you need the caused exception, you need to declare a Exception
parameter.

An alternative is just to use the Camel Exchange as a single
parameter, but then your code imports Camel API.

If you got a copy of Camel in Action then using beans with Camel is
covered in chapter 4.
You got of course the Apache documentation, link mentioned above, as well.


>
> But somehow that method is never called...
> am i using the right signature?
> what am i forgetting?
>
> w/kindest regards
>  marco
>
>
>
>
>
>
>
>
>
> On Thu, Apr 12, 2012 at 8:07 PM, Marco Mistroni <mm...@gmail.com> wrote:
>
>> thaks Claus for the useful advices
>>
>> rgds
>>  marco
>>
>>
>> On Thu, Apr 12, 2012 at 8:40 AM, Claus Ibsen <cl...@gmail.com>wrote:
>>
>>> On Wed, Apr 11, 2012 at 9:15 PM, Marco Mistroni <mm...@gmail.com>
>>> wrote:
>>> > Hello Claus
>>> >  thanks for the reply!
>>> > mm i may be confusing the terminology sorry :(
>>> >
>>> > my camelapp consists of few routes.
>>> > Most of the routes have as  <camel:to
>>> uri="bean:endpointBean?method=handle"
>>> > />
>>> >
>>> > i want to be able to handle exceptions in my endpointBean....
>>> >
>>>
>>> So you want to have endpointBean being invoked, calling the handle
>>> method, when any exception occurs during processing messages in Camel?
>>>
>>> You can define an onException to do that
>>>
>>> Something a like. You can add before your routes in the XML file.
>>>
>>>  <onException>
>>>    <exception>java.lang.Exception</exception>
>>>    <handled>
>>>      <constant>true</constant>
>>>    </handled>
>>>    <to uri="bean:endpointBean?method=handle">
>>>  </onException>
>>>
>>> See more details here:
>>> http://camel.apache.org/exception-clause.html
>>>
>>>
>>> And if you got a copy of the Camel in Action book, I suggest to read
>>> chapter 5, which is all about error handling.
>>>
>>>
>>> > apart from the post below (i see you commented on that as well) are
>>> there
>>> > any other approaches to handle
>>> > exceptions in endpoints?
>>> >
>>> > w/kindest regards
>>> >  marco
>>> >
>>> >
>>> >
>>> > On Wed, Apr 11, 2012 at 6:47 AM, Claus Ibsen <cl...@gmail.com>
>>> wrote:
>>> >
>>> >> On Tue, Apr 10, 2012 at 10:46 PM, Marco Mistroni <mm...@gmail.com>
>>> >> wrote:
>>> >> > Hello all
>>> >> >  i'd like to be able to handle exceptions at Endpoints in my app (as
>>> most
>>> >> > of the exceptions happen when endpoints are processing data).
>>> >> > as i plan to deploy my camel app remotely, i'd like to handle the
>>> >> exception
>>> >> > so that an email with the exception is sent to me.
>>> >> >
>>> >>
>>> >> Can you tell a bit more what you mean by your endpoints process data.
>>> >> Its  the consumer or producers of the endpoints that process data.
>>> >>
>>> >> > i found out this thread with regards to exception handling at
>>> endpoints,
>>> >> > and was wondering if any changes have been introduced in camel to
>>> handle
>>> >> > exception at endpoints since this post
>>> >> >
>>> >> >
>>> >>
>>> http://camel.465427.n5.nabble.com/Endpoint-exception-handling-td5504378.html
>>> >> >
>>> >> > w/kindest regards
>>> >> >  marco
>>> >>
>>> >>
>>> >>
>>> >> --
>>> >> Claus Ibsen
>>> >> -----------------
>>> >> CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
>>> >> FuseSource
>>> >> Email: cibsen@fusesource.com
>>> >> Web: http://fusesource.com
>>> >> Twitter: davsclaus, fusenews
>>> >> Blog: http://davsclaus.blogspot.com/
>>> >> Author of Camel in Action: http://www.manning.com/ibsen/
>>> >>
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> -----------------
>>> CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
>>> FuseSource
>>> Email: cibsen@fusesource.com
>>> Web: http://fusesource.com
>>> Twitter: davsclaus, fusenews
>>> Blog: http://davsclaus.blogspot.com/
>>> Author of Camel in Action: http://www.manning.com/ibsen/
>>>
>>
>>



-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: handling exception at endpoints

Posted by Marco Mistroni <mm...@gmail.com>.
Hello Claus,
 sorry to bother, but i am still losing the plot with Exception Handling :(
i read Camel In action chapter, and this is what i came out with:

    <camel:route>
            <camel:from uri="seda:processBloombergShares" />
            <camel:onException>
                <camel:exception>java.lang.Exception</camel:exception>
                <camel:handled>
                    <camel:constant>true</camel:constant>
                </camel:handled>
                <camel:to
uri="bean:exceptionHandler?method=handleException" />
            </camel:onException>

            <camel:process ref="bloombergProcessor" />
            <camel:bean ref="bloombergServiceActivator" method="fetchData"
/>
            <camel:to uri="bean:endpointBean?method=handleBloombergShare" />

   </camel:route>

   the BloombergProcessor is throwing an Exception , as in code b elow
public void process(Exchange exchange) throws Exception {
        // TODO Auto-generated method stub
        Set<String> set = new HashSet<String>();

        set.add("BLOOMBERG-WMT");
        //set.add("BLOOMBERG-GE");

        String portfolio = (String)exchange.getIn().getBody();



        throw new Exception("Exception from Bloomberg PRocessor...");
  }

this is the signature of my exception handler handleException method

public void handleException(Map<?, ?> in, String payload, Map<String,
Object> out) {
        LOGGER.info("-------Handling exceptions:");
        //exceptions.add(exception);
}


But somehow that method is never called...
am i using the right signature?
what am i forgetting?

w/kindest regards
 marco









On Thu, Apr 12, 2012 at 8:07 PM, Marco Mistroni <mm...@gmail.com> wrote:

> thaks Claus for the useful advices
>
> rgds
>  marco
>
>
> On Thu, Apr 12, 2012 at 8:40 AM, Claus Ibsen <cl...@gmail.com>wrote:
>
>> On Wed, Apr 11, 2012 at 9:15 PM, Marco Mistroni <mm...@gmail.com>
>> wrote:
>> > Hello Claus
>> >  thanks for the reply!
>> > mm i may be confusing the terminology sorry :(
>> >
>> > my camelapp consists of few routes.
>> > Most of the routes have as  <camel:to
>> uri="bean:endpointBean?method=handle"
>> > />
>> >
>> > i want to be able to handle exceptions in my endpointBean....
>> >
>>
>> So you want to have endpointBean being invoked, calling the handle
>> method, when any exception occurs during processing messages in Camel?
>>
>> You can define an onException to do that
>>
>> Something a like. You can add before your routes in the XML file.
>>
>>  <onException>
>>    <exception>java.lang.Exception</exception>
>>    <handled>
>>      <constant>true</constant>
>>    </handled>
>>    <to uri="bean:endpointBean?method=handle">
>>  </onException>
>>
>> See more details here:
>> http://camel.apache.org/exception-clause.html
>>
>>
>> And if you got a copy of the Camel in Action book, I suggest to read
>> chapter 5, which is all about error handling.
>>
>>
>> > apart from the post below (i see you commented on that as well) are
>> there
>> > any other approaches to handle
>> > exceptions in endpoints?
>> >
>> > w/kindest regards
>> >  marco
>> >
>> >
>> >
>> > On Wed, Apr 11, 2012 at 6:47 AM, Claus Ibsen <cl...@gmail.com>
>> wrote:
>> >
>> >> On Tue, Apr 10, 2012 at 10:46 PM, Marco Mistroni <mm...@gmail.com>
>> >> wrote:
>> >> > Hello all
>> >> >  i'd like to be able to handle exceptions at Endpoints in my app (as
>> most
>> >> > of the exceptions happen when endpoints are processing data).
>> >> > as i plan to deploy my camel app remotely, i'd like to handle the
>> >> exception
>> >> > so that an email with the exception is sent to me.
>> >> >
>> >>
>> >> Can you tell a bit more what you mean by your endpoints process data.
>> >> Its  the consumer or producers of the endpoints that process data.
>> >>
>> >> > i found out this thread with regards to exception handling at
>> endpoints,
>> >> > and was wondering if any changes have been introduced in camel to
>> handle
>> >> > exception at endpoints since this post
>> >> >
>> >> >
>> >>
>> http://camel.465427.n5.nabble.com/Endpoint-exception-handling-td5504378.html
>> >> >
>> >> > w/kindest regards
>> >> >  marco
>> >>
>> >>
>> >>
>> >> --
>> >> Claus Ibsen
>> >> -----------------
>> >> CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
>> >> FuseSource
>> >> Email: cibsen@fusesource.com
>> >> Web: http://fusesource.com
>> >> Twitter: davsclaus, fusenews
>> >> Blog: http://davsclaus.blogspot.com/
>> >> Author of Camel in Action: http://www.manning.com/ibsen/
>> >>
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
>> FuseSource
>> Email: cibsen@fusesource.com
>> Web: http://fusesource.com
>> Twitter: davsclaus, fusenews
>> Blog: http://davsclaus.blogspot.com/
>> Author of Camel in Action: http://www.manning.com/ibsen/
>>
>
>

Re: handling exception at endpoints

Posted by Marco Mistroni <mm...@gmail.com>.
thaks Claus for the useful advices

rgds
 marco

On Thu, Apr 12, 2012 at 8:40 AM, Claus Ibsen <cl...@gmail.com> wrote:

> On Wed, Apr 11, 2012 at 9:15 PM, Marco Mistroni <mm...@gmail.com>
> wrote:
> > Hello Claus
> >  thanks for the reply!
> > mm i may be confusing the terminology sorry :(
> >
> > my camelapp consists of few routes.
> > Most of the routes have as  <camel:to
> uri="bean:endpointBean?method=handle"
> > />
> >
> > i want to be able to handle exceptions in my endpointBean....
> >
>
> So you want to have endpointBean being invoked, calling the handle
> method, when any exception occurs during processing messages in Camel?
>
> You can define an onException to do that
>
> Something a like. You can add before your routes in the XML file.
>
>  <onException>
>    <exception>java.lang.Exception</exception>
>    <handled>
>      <constant>true</constant>
>    </handled>
>    <to uri="bean:endpointBean?method=handle">
>  </onException>
>
> See more details here:
> http://camel.apache.org/exception-clause.html
>
>
> And if you got a copy of the Camel in Action book, I suggest to read
> chapter 5, which is all about error handling.
>
>
> > apart from the post below (i see you commented on that as well) are there
> > any other approaches to handle
> > exceptions in endpoints?
> >
> > w/kindest regards
> >  marco
> >
> >
> >
> > On Wed, Apr 11, 2012 at 6:47 AM, Claus Ibsen <cl...@gmail.com>
> wrote:
> >
> >> On Tue, Apr 10, 2012 at 10:46 PM, Marco Mistroni <mm...@gmail.com>
> >> wrote:
> >> > Hello all
> >> >  i'd like to be able to handle exceptions at Endpoints in my app (as
> most
> >> > of the exceptions happen when endpoints are processing data).
> >> > as i plan to deploy my camel app remotely, i'd like to handle the
> >> exception
> >> > so that an email with the exception is sent to me.
> >> >
> >>
> >> Can you tell a bit more what you mean by your endpoints process data.
> >> Its  the consumer or producers of the endpoints that process data.
> >>
> >> > i found out this thread with regards to exception handling at
> endpoints,
> >> > and was wondering if any changes have been introduced in camel to
> handle
> >> > exception at endpoints since this post
> >> >
> >> >
> >>
> http://camel.465427.n5.nabble.com/Endpoint-exception-handling-td5504378.html
> >> >
> >> > w/kindest regards
> >> >  marco
> >>
> >>
> >>
> >> --
> >> Claus Ibsen
> >> -----------------
> >> CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
> >> FuseSource
> >> Email: cibsen@fusesource.com
> >> Web: http://fusesource.com
> >> Twitter: davsclaus, fusenews
> >> Blog: http://davsclaus.blogspot.com/
> >> Author of Camel in Action: http://www.manning.com/ibsen/
> >>
>
>
>
> --
> Claus Ibsen
> -----------------
> CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>

Re: handling exception at endpoints

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Apr 11, 2012 at 9:15 PM, Marco Mistroni <mm...@gmail.com> wrote:
> Hello Claus
>  thanks for the reply!
> mm i may be confusing the terminology sorry :(
>
> my camelapp consists of few routes.
> Most of the routes have as  <camel:to uri="bean:endpointBean?method=handle"
> />
>
> i want to be able to handle exceptions in my endpointBean....
>

So you want to have endpointBean being invoked, calling the handle
method, when any exception occurs during processing messages in Camel?

You can define an onException to do that

Something a like. You can add before your routes in the XML file.

  <onException>
    <exception>java.lang.Exception</exception>
    <handled>
      <constant>true</constant>
    </handled>
    <to uri="bean:endpointBean?method=handle">
  </onException>

See more details here:
http://camel.apache.org/exception-clause.html


And if you got a copy of the Camel in Action book, I suggest to read
chapter 5, which is all about error handling.


> apart from the post below (i see you commented on that as well) are there
> any other approaches to handle
> exceptions in endpoints?
>
> w/kindest regards
>  marco
>
>
>
> On Wed, Apr 11, 2012 at 6:47 AM, Claus Ibsen <cl...@gmail.com> wrote:
>
>> On Tue, Apr 10, 2012 at 10:46 PM, Marco Mistroni <mm...@gmail.com>
>> wrote:
>> > Hello all
>> >  i'd like to be able to handle exceptions at Endpoints in my app (as most
>> > of the exceptions happen when endpoints are processing data).
>> > as i plan to deploy my camel app remotely, i'd like to handle the
>> exception
>> > so that an email with the exception is sent to me.
>> >
>>
>> Can you tell a bit more what you mean by your endpoints process data.
>> Its  the consumer or producers of the endpoints that process data.
>>
>> > i found out this thread with regards to exception handling at endpoints,
>> > and was wondering if any changes have been introduced in camel to handle
>> > exception at endpoints since this post
>> >
>> >
>> http://camel.465427.n5.nabble.com/Endpoint-exception-handling-td5504378.html
>> >
>> > w/kindest regards
>> >  marco
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
>> FuseSource
>> Email: cibsen@fusesource.com
>> Web: http://fusesource.com
>> Twitter: davsclaus, fusenews
>> Blog: http://davsclaus.blogspot.com/
>> Author of Camel in Action: http://www.manning.com/ibsen/
>>



-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: handling exception at endpoints

Posted by Marco Mistroni <mm...@gmail.com>.
Hello Claus
  thanks for the reply!
mm i may be confusing the terminology sorry :(

my camelapp consists of few routes.
Most of the routes have as  <camel:to uri="bean:endpointBean?method=handle"
/>

i want to be able to handle exceptions in my endpointBean....

apart from the post below (i see you commented on that as well) are there
any other approaches to handle
exceptions in endpoints?

w/kindest regards
 marco



On Wed, Apr 11, 2012 at 6:47 AM, Claus Ibsen <cl...@gmail.com> wrote:

> On Tue, Apr 10, 2012 at 10:46 PM, Marco Mistroni <mm...@gmail.com>
> wrote:
> > Hello all
> >  i'd like to be able to handle exceptions at Endpoints in my app (as most
> > of the exceptions happen when endpoints are processing data).
> > as i plan to deploy my camel app remotely, i'd like to handle the
> exception
> > so that an email with the exception is sent to me.
> >
>
> Can you tell a bit more what you mean by your endpoints process data.
> Its  the consumer or producers of the endpoints that process data.
>
> > i found out this thread with regards to exception handling at endpoints,
> > and was wondering if any changes have been introduced in camel to handle
> > exception at endpoints since this post
> >
> >
> http://camel.465427.n5.nabble.com/Endpoint-exception-handling-td5504378.html
> >
> > w/kindest regards
> >  marco
>
>
>
> --
> Claus Ibsen
> -----------------
> CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>

Re: handling exception at endpoints

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Apr 10, 2012 at 10:46 PM, Marco Mistroni <mm...@gmail.com> wrote:
> Hello all
>  i'd like to be able to handle exceptions at Endpoints in my app (as most
> of the exceptions happen when endpoints are processing data).
> as i plan to deploy my camel app remotely, i'd like to handle the exception
> so that an email with the exception is sent to me.
>

Can you tell a bit more what you mean by your endpoints process data.
Its  the consumer or producers of the endpoints that process data.

> i found out this thread with regards to exception handling at endpoints,
> and was wondering if any changes have been introduced in camel to handle
> exception at endpoints since this post
>
> http://camel.465427.n5.nabble.com/Endpoint-exception-handling-td5504378.html
>
> w/kindest regards
>  marco



-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/