You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by James Green <ja...@gmail.com> on 2015/01/21 12:51:06 UTC

Rest DSL Exception mapping

If Camel can accept and map both JSON and XML inputs to POJOs, is there a
way of reversing this for onException handling purposes?

The only example of onException sets the content-type and formatted content
on the Exchange. But I may not know this.

Within Spring MVC there is @ResponseStatus allowing us to specify the HTTP
response code for a particular Exception without needing to care about the
response content type, which is the bit I'm not spotting an equivalent for.

Am I missing something or is this a bit of a hole?

Thanks,

James

Re: Rest DSL Exception mapping

Posted by Claus Ibsen <cl...@gmail.com>.
You can use the option skipBindingOnErrorCode to control if the
binding should happen or not.

On Wed, Jan 21, 2015 at 1:24 PM, James Green <ja...@gmail.com> wrote:
> Just re-reading the "Binding POJOs" bit, will this also take effect for the
> out part of an exception?
>
> onException(MyException.class).handled(true).setHeader(Exchange.HTTP_RESPONSE_CODE,
> constant(400)).process(myExceptionHandler).end()
>
> Should I expect the Message provided by myExceptionHandler to be formatted
> to JSON/XML according to the HTTP client's choice?
>
>
> On 21 January 2015 at 11:51, James Green <ja...@gmail.com> wrote:
>
>> If Camel can accept and map both JSON and XML inputs to POJOs, is there a
>> way of reversing this for onException handling purposes?
>>
>> The only example of onException sets the content-type and formatted
>> content on the Exchange. But I may not know this.
>>
>> Within Spring MVC there is @ResponseStatus allowing us to specify the HTTP
>> response code for a particular Exception without needing to care about the
>> response content type, which is the bit I'm not spotting an equivalent for.
>>
>> Am I missing something or is this a bit of a hole?
>>
>> Thanks,
>>
>> James
>>
>>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: Rest DSL Exception mapping

Posted by James Green <ja...@gmail.com>.
Just re-reading the "Binding POJOs" bit, will this also take effect for the
out part of an exception?

onException(MyException.class).handled(true).setHeader(Exchange.HTTP_RESPONSE_CODE,
constant(400)).process(myExceptionHandler).end()

Should I expect the Message provided by myExceptionHandler to be formatted
to JSON/XML according to the HTTP client's choice?


On 21 January 2015 at 11:51, James Green <ja...@gmail.com> wrote:

> If Camel can accept and map both JSON and XML inputs to POJOs, is there a
> way of reversing this for onException handling purposes?
>
> The only example of onException sets the content-type and formatted
> content on the Exchange. But I may not know this.
>
> Within Spring MVC there is @ResponseStatus allowing us to specify the HTTP
> response code for a particular Exception without needing to care about the
> response content type, which is the bit I'm not spotting an equivalent for.
>
> Am I missing something or is this a bit of a hole?
>
> Thanks,
>
> James
>
>