You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Ranabroto <ra...@globalcharge.com> on 2017/07/12 15:41:44 UTC

${header.CamelHttpResponseCode} getting lost?

Hello I have below route  
<route id="route-send" autoStartup="true">
	<from uri="direct:send-test"/>
	<onException>
	
<exception>org.apache.camel.http.common.HttpOperationFailedException</exception>
		<handled>
			<constant>true</constant>
		</handled>
		<log message="ALL HEADER: ${headers}"/>
		<log message="HTTP RESPONSE: ${header.CamelHttpResponseCode}"/>
		<choice>
			<when>
				<simple>${header.CamelHttpResponseCode} == '400' </simple>
				do something
			</when>
		</choice>
	</onException>
	<to uri="bean:notProcessVeoo?method=preppareRequest"/>
	<to
uri="https4:{{LIVE_AUTH_RESPONSE_HOST}}:{{LIVE_AUTH_RESPONSE_PORT}}/{{LIVE_AUTH_RESPONSE_CONTEXT_PATH}}"/>
</route>

This giveing me below exception  
Failed delivery for (MessageId:
ID-rgdev-globalcharge-com-57715-1499872966816-3-10 on ExchangeId:
ID-rgdev-globalcharge-com-57715-1499872966816-7-1). Exhausted after delivery
attempt: 1 caught:
org.apache.camel.http.common.HttpOperationFailedException: HTTP operation
failed invoking https://api.example.com/send?param=value with statusCode:
400

So i am catching that exception and want to do something when HTTP Response
code is 400. But unfortunately ${header.CamelHttpResponseCode} is printing
nothing :(, in-fact notice i have printed all header and dont see any HTTP
response code header. Could you please point where i am going wrong why that
header is getting lost, because from exception its clear that its failing
with HTTP Response code 400, why camel is not storing that in header?





--
View this message in context: http://camel.465427.n5.nabble.com/header-CamelHttpResponseCode-getting-lost-tp5806828.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: [EXTERNAL] Re: ${header.CamelHttpResponseCode} getting lost?

Posted by "Vanshul.Chawla" <Va...@target.com>.
Yes that’s correct.
If we disable default throw exception behavior, then we can capture the http error code.
Else we will get only original message and exception stack.

Still in exception stack, you will get http error code also.

Vanshul

-----Original Message-----
From: Doug Douglass [mailto:douglass.doug@gmail.com] 
Sent: Wednesday, July 12, 2017 11:48 AM
To: users@camel.apache.org
Subject: [EXTERNAL] Re: ${header.CamelHttpResponseCode} getting lost?

My understanding after reading http://camel.apache.org/http4.html is, if you want to handle all HTTP status response codes yourself using message headers, you should add throwExceptionOnFailure=false to your endpoint.
Otherwise you can get the status code from the exception itself e.g.
exception.statusCode == 400.

HTH,
Doug


On Wed, Jul 12, 2017 at 8:41 AM, Ranabroto <ranabroto.ghosh@globalcharge.com
> wrote:

> Hello I have below route
> <route id="route-send" autoStartup="true">
>         <from uri="direct:send-test"/>
>         <onException>
>
> <exception>org.apache.camel.http.common.HttpOperationFailedException</
> exception>
>                 <handled>
>                         <constant>true</constant>
>                 </handled>
>                 <log message="ALL HEADER: ${headers}"/>
>                 <log message="HTTP RESPONSE: ${header.
> CamelHttpResponseCode}"/>
>                 <choice>
>                         <when>
>                                 
> <simple>${header.CamelHttpResponseCode}
> == '400' </simple>
>                                 do something
>                         </when>
>                 </choice>
>         </onException>
>         <to uri="bean:notProcessVeoo?method=preppareRequest"/>
>         <to
> uri="https4:{{LIVE_AUTH_RESPONSE_HOST}}:{{LIVE_AUTH_
> RESPONSE_PORT}}/{{LIVE_AUTH_RESPONSE_CONTEXT_PATH}}"/>
> </route>
>
> This giveing me below exception
> Failed delivery for (MessageId:
> ID-rgdev-globalcharge-com-57715-1499872966816-3-10 on ExchangeId:
> ID-rgdev-globalcharge-com-57715-1499872966816-7-1). Exhausted after 
> delivery
> attempt: 1 caught:
> org.apache.camel.http.common.HttpOperationFailedException: HTTP 
> operation failed invoking https://api.example.com/send?param=value with statusCode:
> 400
>
> So i am catching that exception and want to do something when HTTP 
> Response code is 400. But unfortunately 
> ${header.CamelHttpResponseCode} is printing nothing :(, in-fact notice 
> i have printed all header and dont see any HTTP response code header. 
> Could you please point where i am going wrong why that header is 
> getting lost, because from exception its clear that its failing with 
> HTTP Response code 400, why camel is not storing that in header?
>
>
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/header-
> CamelHttpResponseCode-getting-lost-tp5806828.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: ${header.CamelHttpResponseCode} getting lost?

Posted by Ranabroto <ra...@globalcharge.com>.
Spot on, many thanks, silly me skipped that part. 



--
View this message in context: http://camel.465427.n5.nabble.com/header-CamelHttpResponseCode-getting-lost-tp5806828p5806877.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ${header.CamelHttpResponseCode} getting lost?

Posted by Doug Douglass <do...@gmail.com>.
My understanding after reading http://camel.apache.org/http4.html is, if
you want to handle all HTTP status response codes yourself using message
headers, you should add throwExceptionOnFailure=false to your endpoint.
Otherwise you can get the status code from the exception itself e.g.
exception.statusCode == 400.

HTH,
Doug


On Wed, Jul 12, 2017 at 8:41 AM, Ranabroto <ranabroto.ghosh@globalcharge.com
> wrote:

> Hello I have below route
> <route id="route-send" autoStartup="true">
>         <from uri="direct:send-test"/>
>         <onException>
>
> <exception>org.apache.camel.http.common.HttpOperationFailedException</
> exception>
>                 <handled>
>                         <constant>true</constant>
>                 </handled>
>                 <log message="ALL HEADER: ${headers}"/>
>                 <log message="HTTP RESPONSE: ${header.
> CamelHttpResponseCode}"/>
>                 <choice>
>                         <when>
>                                 <simple>${header.CamelHttpResponseCode}
> == '400' </simple>
>                                 do something
>                         </when>
>                 </choice>
>         </onException>
>         <to uri="bean:notProcessVeoo?method=preppareRequest"/>
>         <to
> uri="https4:{{LIVE_AUTH_RESPONSE_HOST}}:{{LIVE_AUTH_
> RESPONSE_PORT}}/{{LIVE_AUTH_RESPONSE_CONTEXT_PATH}}"/>
> </route>
>
> This giveing me below exception
> Failed delivery for (MessageId:
> ID-rgdev-globalcharge-com-57715-1499872966816-3-10 on ExchangeId:
> ID-rgdev-globalcharge-com-57715-1499872966816-7-1). Exhausted after
> delivery
> attempt: 1 caught:
> org.apache.camel.http.common.HttpOperationFailedException: HTTP operation
> failed invoking https://api.example.com/send?param=value with statusCode:
> 400
>
> So i am catching that exception and want to do something when HTTP Response
> code is 400. But unfortunately ${header.CamelHttpResponseCode} is printing
> nothing :(, in-fact notice i have printed all header and dont see any HTTP
> response code header. Could you please point where i am going wrong why
> that
> header is getting lost, because from exception its clear that its failing
> with HTTP Response code 400, why camel is not storing that in header?
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/header-
> CamelHttpResponseCode-getting-lost-tp5806828.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>