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/14 16:35:30 UTC

Re: handling exception at endpoints / solved

Hello
  ok i got the error. wrong signature in my handleException method.
it should be handleException(Exchange exchange)

i think Claus might have mentioned me the correct signature in some past
email, but somehow that mail got lost

Good thing i m pleased about is that i spotted the signature error while
learning how to test routes offline :)

I m starting to love camel :)

thanks and  sorry for my noise
rgds
 marco


On Sat, Apr 14, 2012 at 12: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);
> }
>
>
> 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 <mmistroni@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 / solved

Posted by Christian Müller <ch...@gmail.com>.
Good to know you could figure it out by yourself. I would response later to
your question with the solution you mentioned (I'm on a shopping tour with
my girl friend at present... ;-) ).

There are also others. Have a look at the parameter binding annotations:
http://camel.apache.org/parameter-binding-annotations.html

Happy Camel ride,
Christian

Sent from a mobile device
Am 14.04.2012 16:35 schrieb "Marco Mistroni" <mm...@gmail.com>:

> Hello
>  ok i got the error. wrong signature in my handleException method.
> it should be handleException(Exchange exchange)
>
> i think Claus might have mentioned me the correct signature in some past
> email, but somehow that mail got lost
>
> Good thing i m pleased about is that i spotted the signature error while
> learning how to test routes offline :)
>
> I m starting to love camel :)
>
> thanks and  sorry for my noise
> rgds
>  marco
>
>
> On Sat, Apr 14, 2012 at 12:11 PM, Marco Mistroni <mmistroni@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);
> > }
> >
> >
> > 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 <mmistroni@gmail.com
> >wrote:
> >
> >> thaks Claus for the useful advices
> >>
> >> rgds
> >>  marco
> >>
> >>
> >> On Thu, Apr 12, 2012 at 8:40 AM, Claus Ibsen <claus.ibsen@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 <
> mmistroni@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/
> >>>
> >>
> >>
> >
>