You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "Vanshul.Chawla" <Va...@target.com> on 2015/05/04 13:56:10 UTC

Camel onException for different HTTP error codes

We have a requirement wherein we need to do different error handling for different error code returned from http external service.

So we have to go for a retry for

"X-Original-HTTP-Status-Code"=404,405,500,401

And no retry for other codes.

What I have learnt so far is onException will do selective handling but that limits to a class only. And here class will be same.

Other option I thought of is setting throwExceptionOnFailure but here I lose the exception and it behaves like a handled response.


Can anyone suggest me with an example on how this can be done in Camel Spring DSL?

Thanks and Regards,

Vanshul Chawla


RE: Camel onException for different HTTP error codes

Posted by "Vanshul.Chawla" <Va...@target.com>.
Trying out "when" now. We can check with statusCode:500 etc in simple then. 
Thanks for your response.

Thanks and Regards,

Vanshul Chawla

-----Original Message-----
From: Claus Ibsen [mailto:claus.ibsen@gmail.com] 
Sent: Monday, May 04, 2015 5:38 PM
To: users@camel.apache.org
Subject: Re: Camel onException for different HTTP error codes

Hi

You can use onWhen to an exception as the predicate to trigger or not.
Then you can use some java code as the predicate to check for those http headers and figure out what to do.

There is also a retryWhile you can use etc.

Camel in Action book chapter 5, in the end of this chapter documents this. And you can find some bits on the Camel web site too.

On Mon, May 4, 2015 at 1:56 PM, Vanshul.Chawla <Va...@target.com> wrote:
> We have a requirement wherein we need to do different error handling for different error code returned from http external service.
>
> So we have to go for a retry for
>
> "X-Original-HTTP-Status-Code"=404,405,500,401
>
> And no retry for other codes.
>
> What I have learnt so far is onException will do selective handling but that limits to a class only. And here class will be same.
>
> Other option I thought of is setting throwExceptionOnFailure but here I lose the exception and it behaves like a handled response.
>
>
> Can anyone suggest me with an example on how this can be done in Camel Spring DSL?
>
> Thanks and Regards,
>
> Vanshul Chawla
>



--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: Camel onException for different HTTP error codes

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

You can use onWhen to an exception as the predicate to trigger or not.
Then you can use some java code as the predicate to check for those
http headers and figure out what to do.

There is also a retryWhile you can use etc.

Camel in Action book chapter 5, in the end of this chapter documents
this. And you can find some bits on the Camel web site too.

On Mon, May 4, 2015 at 1:56 PM, Vanshul.Chawla
<Va...@target.com> wrote:
> We have a requirement wherein we need to do different error handling for different error code returned from http external service.
>
> So we have to go for a retry for
>
> "X-Original-HTTP-Status-Code"=404,405,500,401
>
> And no retry for other codes.
>
> What I have learnt so far is onException will do selective handling but that limits to a class only. And here class will be same.
>
> Other option I thought of is setting throwExceptionOnFailure but here I lose the exception and it behaves like a handled response.
>
>
> Can anyone suggest me with an example on how this can be done in Camel Spring DSL?
>
> Thanks and Regards,
>
> Vanshul Chawla
>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/