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/16 16:34:28 UTC

Rest DSL - how to pass PUT body as method argument

Camel Rest DSL

Want to ask how can one pass the body of a PUT request to a method positional argument.
Eg, with bindingMode=json will the magic ${body} work?

     <rest path="/order">
       <put uri="/{id}" type="MyOrder">
         <to uri="bean:orders?method=update(${header.id},${body})" />
       </put>
     </rest>

with the method in Java as

     update(String id, MyOrder myOrder)

Searched the docs (including Camel in Action, 2nd ed), but can't find an example anywhere.

Thanks
- Martin


.

Re: Rest DSL - how to pass PUT body as method argument

Posted by Martin Lichtin <li...@yahoo.com.INVALID>.
To answer my question, yes this works.
The JSON body is deserialized and passed on as a MyOrder object to the update() method.

One issue with Rest PUT/POST is that Camel will use the request body also for the HTTP response.
Usually this is not wanted, so best to empty the out body, e.g. with <setBody><simple>null</simple></setBody>

On 16.09.2017 18:34, Martin Lichtin wrote:
> Camel Rest DSL
>
> Want to ask how can one pass the body of a PUT request to a method positional argument.
> Eg, with bindingMode=json will the magic ${body} work?
>
>     <rest path="/order">
>       <put uri="/{id}" type="MyOrder">
>         <to uri="bean:orders?method=update(${header.id},${body})" />
>       </put>
>     </rest>
>
> with the method in Java as
>
>     update(String id, MyOrder myOrder)
>
> Searched the docs (including Camel in Action, 2nd ed), but can't find an example anywhere.