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 <jo...@hotmail.com> on 2013/03/05 21:37:32 UTC

Error Handling and HTTP response

Hi all, 


I am trying to send to the caller (HTTP request) an http response with a
fixed message in the body (and 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 stacktrace in the body. I
would like to replace this body with a fixed message, like "error occured". 

I have tried with OnException and doesn't work at all ... 

I have tried with doTry doCatch, and the result is different (not really
better): Now, if handled, 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  response 

Anyone can help me please ? 

Thank you 



--
View this message in context: http://camel.465427.n5.nabble.com/Error-Handling-and-HTTP-response-tp5728599.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Error Handling and HTTP response

Posted by Raúl Kripalani <ra...@evosent.com>.
Can you set the Content-Type explicitly, before or after the transform?

<camel:setHeader headerName="Content-Type"><constant>text/plain</constant></camel:setHeader>

If you want to specify the HTTP response code, in camel-jetty you would set it like this:

<camel:setHeader headerName="CamelHttpResponseCode"><constant>500</constant></camel:setHeader>

Hopefully it's the same for camel-servlet.

Regards,
Raúl.

On Mar 5, 2013, at 20:37, Alban wrote:

> Hi all, 
> 
> 
> I am trying to send to the caller (HTTP request) an http response with a
> fixed message in the body (and 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 stacktrace in the body. I
> would like to replace this body with a fixed message, like "error occured". 
> 
> I have tried with OnException and doesn't work at all ... 
> 
> I have tried with doTry doCatch, and the result is different (not really
> better): Now, if handled, 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  response 
> 
> Anyone can help me please ? 
> 
> Thank you 
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Error-Handling-and-HTTP-response-tp5728599.html
> Sent from the Camel - Users mailing list archive at Nabble.com.