You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by deepak_a <an...@gmail.com> on 2013/02/14 14:24:36 UTC

How to use throwExceptionOnFailure=false to differentiate HTTP Status codes

All,

I am using the option
throwExceptionOnFailure=false
to ensure I Camel doesn't throw exceptions for HTTP Status code 500 and
above (since I want to retry)

By default Camel throws HttpOperationFailedException for all HTTP responses
where status code is 400+

Pls see below for snippet from my Routes.xml

	<route id="XXXXX" name="XXXXX" reform:systemName="AMP MarginCall Dispute">
		<from uri="jms:queue:queue.XXXXXXX"/>
		<onException>
        <exception>java.lang.Throwable</exception>
        <process ref="errorHandle"/>
    </onException>
    <onCompletion>
        <process ref="completeHandle"/>
    </onCompletion>		
		<setHeader headerName="CamelHttpUri">
			
			
		
<simple>http://localhost:8181/SimpleServlet/simple-servlet?throwExceptionOnFailure=false</simple>
		</setHeader>
		<setHeader headerName="CamelHttpMethod">
			<constant>PUT</constant>
		</setHeader>
		<setHeader headerName="Content-Type">
			<constant>application/xml</constant>
		</setHeader>
        <setHeader headerName="Accept">
			<constant>application/xml</constant>
		</setHeader>
		<to uri="http://www.google.com"/>
		<setHeader headerName="JMSCorrelationID">
			<simple>123456789</simple>
		</setHeader>
		<to uri="log:com.replies?level=WARN"/>
		<to uri="jms:queue:queue.incomingReplies"/>
	</route>	



However i still see Camel throwing HttpOperationFailedException exception.
Can some one point out where I am going wrong.

regards.



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-use-throwExceptionOnFailure-false-to-differentiate-HTTP-Status-codes-tp5727591.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to use throwExceptionOnFailure=false to differentiate HTTP Status codes

Posted by deepak_a <an...@gmail.com>.
Hi,

I took an *ugly* approach.
Capture the HTTP exception (OnExeption) - then find out what type of
ShatusCode it is.
If its between 400..499 then just simply log the exception, if Status Code
is between 500..599 then i manually publish the message back into my
ActiveMQ Queue (for camel to again pull the message and make the HTTP call)
This goes into a loop with a maxRetry of 5 and on the 5th attempt I simply
log the 500..599 exception. 

I do get the expected functionality bu 
Would need to revisit this at a later point in time to make it more
efficient.



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-use-throwExceptionOnFailure-false-to-differentiate-HTTP-Status-codes-tp5727591p5727855.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to use throwExceptionOnFailure=false to differentiate HTTP Status codes

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Feb 14, 2013 at 6:27 PM, deepak_a <an...@gmail.com> wrote:
> Hi,
> Thanks, works fine now after setting the field to false in
>
>                 <to uri="http://www.google.com?throwExceptionOnFailure=false"/>
>
> My aim is to segregate HTTP response status 400 and 500.
> i.e. for HTTP Statuses: 400-499, there should not be any retries while
> status 500+ - we need to retry
> n number of times.
>
> Will post further as I make some progress.
>

Did you figure this out?

There is onWhen and retryWhile which can allow you to plugin custom
code to decide if its an error and/or to retry.


>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-use-throwExceptionOnFailure-false-to-differentiate-HTTP-Status-codes-tp5727591p5727623.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: How to use throwExceptionOnFailure=false to differentiate HTTP Status codes

Posted by deepak_a <an...@gmail.com>.
Hi, 
Thanks, works fine now after setting the field to false in

		<to uri="http://www.google.com?throwExceptionOnFailure=false"/>

My aim is to segregate HTTP response status 400 and 500.
i.e. for HTTP Statuses: 400-499, there should not be any retries while
status 500+ - we need to retry 
n number of times.

Will post further as I make some progress.



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-use-throwExceptionOnFailure-false-to-differentiate-HTTP-Status-codes-tp5727591p5727623.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to use throwExceptionOnFailure=false to differentiate HTTP Status codes

Posted by deepak_a <an...@gmail.com>.
Hi,

Do you mean to say - point to www.google.com instead of my servlet?
But I have set up my servlet in such a way it always sends back a 500 0r 501
as Status Code.




--
View this message in context: http://camel.465427.n5.nabble.com/How-to-use-throwExceptionOnFailure-false-to-differentiate-HTTP-Status-codes-tp5727591p5727599.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to use throwExceptionOnFailure=false to differentiate HTTP Status codes

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

Try configuring it on
  <to uri="http://www.google.com"/>


On Thu, Feb 14, 2013 at 2:24 PM, deepak_a <an...@gmail.com> wrote:
> All,
>
> I am using the option
> throwExceptionOnFailure=false
> to ensure I Camel doesn't throw exceptions for HTTP Status code 500 and
> above (since I want to retry)
>
> By default Camel throws HttpOperationFailedException for all HTTP responses
> where status code is 400+
>
> Pls see below for snippet from my Routes.xml
>
>         <route id="XXXXX" name="XXXXX" reform:systemName="AMP MarginCall Dispute">
>                 <from uri="jms:queue:queue.XXXXXXX"/>
>                 <onException>
>         <exception>java.lang.Throwable</exception>
>         <process ref="errorHandle"/>
>     </onException>
>     <onCompletion>
>         <process ref="completeHandle"/>
>     </onCompletion>
>                 <setHeader headerName="CamelHttpUri">
>
>
>
> <simple>http://localhost:8181/SimpleServlet/simple-servlet?throwExceptionOnFailure=false</simple>
>                 </setHeader>
>                 <setHeader headerName="CamelHttpMethod">
>                         <constant>PUT</constant>
>                 </setHeader>
>                 <setHeader headerName="Content-Type">
>                         <constant>application/xml</constant>
>                 </setHeader>
>         <setHeader headerName="Accept">
>                         <constant>application/xml</constant>
>                 </setHeader>
>                 <to uri="http://www.google.com"/>
>                 <setHeader headerName="JMSCorrelationID">
>                         <simple>123456789</simple>
>                 </setHeader>
>                 <to uri="log:com.replies?level=WARN"/>
>                 <to uri="jms:queue:queue.incomingReplies"/>
>         </route>
>
>
>
> However i still see Camel throwing HttpOperationFailedException exception.
> Can some one point out where I am going wrong.
>
> regards.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-use-throwExceptionOnFailure-false-to-differentiate-HTTP-Status-codes-tp5727591.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen