You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Willem Jiang <wi...@gmail.com> on 2013/12/02 08:38:19 UTC

Re: Getting http status code from cxfrs in onException handler

Hi,

I just checked the code of CxfRsProducer, if you set the throwExceptionOnFailure to be true, you can only get the Http status code from the exception.
If you set the throwExceptionOnFailure option to be false, you can find the Http status code from the out message header with the key of “CamelHttpResponseCode”.

-- 
Willem Jiang
Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
          http://jnn.iteye.com (Chinese)
Twitter: willemjiang 
Weibo: 姜宁willem


On November 29, 2013 at 3:44:09 PM, Preben.Asmussen (pras@dr.dk) wrote:
>
>Hi
>
>I have a onException block where i want to handle
>org.apache.camel.component.cxf.CxfOperationException
>but only when the status is 404. other status codes should fail and
>rollback.
>
>The route is ->
>
>>uri="hubTopic:topic:CMS_CONTENT_HUB?clientId=NEWS&durableSubscriptionName=NEWS"
>/>
>
>
>org.apache.camel.component.cxf.CxfOperationException
>
>
>
>true
>
>
>
>>uri="cxfrs:bean:allnews?synchronous=true&throwExceptionOnFailure=true"/>
>
>
>the HttpExceptionInterpreter is kind of simple ->
>public static boolean is404(@ExchangeException CxfOperationException
>exception) {
>return exception.getStatusCode() == 404;
>}
>
>I would guess that I could avoid the bean, and that the http status code
>would be set on the exchange header (in or out) so that i could use the
>simple language to do something like out.header.xxxx == 404 in the
>onWhen.
>
>Is that possible ?
>
>There is no http status code on the in.header btw.
>
>I'm using Camel version 2.11.1
>
>Best,
>Preben
>
>
>
>
>--
>View this message in context: http://camel.465427.n5.nabble.com/Getting-http-status-code-from-cxfrs-in-onException-handler-tp5744066.html
>Sent from the Camel - Users mailing list archive at Nabble.com.
>


Re: Getting http status code from cxfrs in onException handler

Posted by "Preben.Asmussen" <pr...@dr.dk>.
Thanks Willem

Of course it was quite simple in the end. Just do

<onException>
	<exception>org.apache.camel.component.cxf.CxfOperationException</exception>
	<onWhen>
		<simple>${exception.statusCode} == 404</simple>
	</onWhen>
	<handled><constant>true</constant></handled>
</onException>

I was just focusing on getting the http status code from the header, when I
just could have used the ${exception}.

best,
Preben



--
View this message in context: http://camel.465427.n5.nabble.com/Getting-http-status-code-from-cxfrs-in-onException-handler-tp5744066p5744290.html
Sent from the Camel - Users mailing list archive at Nabble.com.