You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Martin Lichtin <li...@yahoo.com.INVALID> on 2017/09/25 12:47:38 UTC
OnException - out body length limited by input body length
Using an <onException> to handle an exception, I want to mark the situation as 'handled' and set the body with information from the exception. Eg:
<onException>
<exception>java.lang.Exception</exception>
<handled>
<constant>false</constant>
</handled>
<setHeader headerName="Exchange.HTTP_RESPONSE_CODE">
<constant>500</constant>
</setHeader>
<setBody>
<simple>${exception.stacktrace}</simple>
</setBody>
</onException>
Problem is: the body is only filled up to the existing length of the input body.
For example, if the input body (e.g. of a POST request) is 10 characters, then the output body is also only 10 characters, filled with a little bit of the stack trace :)
Looks like a bug to me (using 2.18.4), or am I missing a way to properly set the output.
Thanks
- Martin
Re: Re: OnException - out body length limited by input body length
Posted by Martin Lichtin <li...@yahoo.com.INVALID>.
Thanks, that did the trick.
About request (and also Camel) headers leaking into the http response, is there support from the framework in some way?
What I currently use is a custom HeaderFilterStrategy to suppress all the various headers that should not be returned to the caller, such as all the Camel* headers, the params from the Url query string, etc...
On 25.09.2017 15:26, Claus Ibsen wrote:
> Remove the Content-Length header when you change the body
>
> On Mon, Sep 25, 2017 at 2:47 PM, Martin Lichtin
> <li...@yahoo.com.invalid> wrote:
>> Using an <onException> to handle an exception, I want to mark the situation as 'handled' and set the body with information from the exception. Eg:
>>
>> <onException>
>> <exception>java.lang.Exception</exception>
>> <handled>
>> <constant>false</constant>
>> </handled>
>> <setHeader headerName="Exchange.HTTP_RESPONSE_CODE">
>> <constant>500</constant>
>> </setHeader>
>> <setBody>
>> <simple>${exception.stacktrace}</simple>
>> </setBody>
>> </onException>
>>
>> Problem is: the body is only filled up to the existing length of the input body.
>>
>> For example, if the input body (e.g. of a POST request) is 10 characters, then the output body is also only 10 characters, filled with a little bit of the stack trace :)
>> Looks like a bug to me (using 2.18.4), or am I missing a way to properly set the output.
>>
>> Thanks
>> - Martin
>
>
Re: OnException - out body length limited by input body length
Posted by Claus Ibsen <cl...@gmail.com>.
Remove the Content-Length header when you change the body
On Mon, Sep 25, 2017 at 2:47 PM, Martin Lichtin
<li...@yahoo.com.invalid> wrote:
> Using an <onException> to handle an exception, I want to mark the situation as 'handled' and set the body with information from the exception. Eg:
>
> <onException>
> <exception>java.lang.Exception</exception>
> <handled>
> <constant>false</constant>
> </handled>
> <setHeader headerName="Exchange.HTTP_RESPONSE_CODE">
> <constant>500</constant>
> </setHeader>
> <setBody>
> <simple>${exception.stacktrace}</simple>
> </setBody>
> </onException>
>
> Problem is: the body is only filled up to the existing length of the input body.
>
> For example, if the input body (e.g. of a POST request) is 10 characters, then the output body is also only 10 characters, filled with a little bit of the stack trace :)
> Looks like a bug to me (using 2.18.4), or am I missing a way to properly set the output.
>
> Thanks
> - Martin
--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2