You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Alban Joly <al...@groupemoniteur.fr> on 2013/03/05 19:05:46 UTC
Sending a custom HTTP Response in case of exception
Hi all,
I am trying to send to the caller an http response with a fixed message in
the body (an an error status code of course)
My route is :
<from uri="servlet:///XXX?matchOnUriPrefix=true" />
<inOnly uri="activemq:queue:YYYY" />
...
In case of exception (ActiveMq not connected for example), I received an
response with an error status code but with the stack trace in the body. I
would like to replace this body with a fixed message.
I have tried with OnException and doens't work at all ...
I have tried with doTry doCatch, and the result is different (not really
better): Now, if handled : true I receive an 200 status response with no
Body. If not handled, no change ...
My code
<camel:doCatch>
<exception>java.lang.Exception</exception>
<camel:handled>
<camel:constant>true</camel:constant>
</camel:handled>
<camel:transform>
<camel:constant>TESTTTTTT</camel:constant>
</camel:transform>
<camel:log message="AAAAAAAAAAAAAAAAAAAAAAAAAA"></camel:log>
</camel:doCatch>
I have tried some different case : with setBody, with setFaultBody, ... and
i have never successed to display a custom message in the http error status
response
Anyone can help me please ?
Thank you
--
View this message in context: http://camel.465427.n5.nabble.com/Sending-a-custom-HTTP-Response-in-case-of-exception-tp5728589.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Sending a custom HTTP Response in case of exception
Posted by Christian Müller <ch...@gmail.com>.
In case something went wrong you want to return an HTTP status code not
equal to 200 and custom message, right?
We do this by using onException... What did you tried?
Sent from a mobile device
Am 05.03.2013 11:06 schrieb "Alban Joly" <al...@groupemoniteur.fr>:
> Hi all,
>
>
> I am trying to send to the caller an http response with a fixed message in
> the body (an an error status code of course)
>
> My route is :
>
> <from uri="servlet:///XXX?matchOnUriPrefix=true" />
> <inOnly uri="activemq:queue:YYYY" />
> ...
>
> In case of exception (ActiveMq not connected for example), I received an
> response with an error status code but with the stack trace in the body. I
> would like to replace this body with a fixed message.
>
> I have tried with OnException and doens't work at all ...
>
> I have tried with doTry doCatch, and the result is different (not really
> better): Now, if handled : true I receive an 200 status response with no
> Body. If not handled, no change ...
>
> My code
>
> <camel:doCatch>
> <exception>java.lang.Exception</exception>
> <camel:handled>
> <camel:constant>true</camel:constant>
> </camel:handled>
> <camel:transform>
> <camel:constant>TESTTTTTT</camel:constant>
> </camel:transform>
> <camel:log
> message="AAAAAAAAAAAAAAAAAAAAAAAAAA"></camel:log>
> </camel:doCatch>
>
> I have tried some different case : with setBody, with setFaultBody, ... and
> i have never successed to display a custom message in the http error status
> response
>
> Anyone can help me please ?
>
> Thank you
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Sending-a-custom-HTTP-Response-in-case-of-exception-tp5728589.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>