[ 
https://issues.apache.org/jira/browse/CAMEL-26043?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Work on CAMEL-26043 started by Claus Ibsen.
-------------------------------------------
> camel-aws2-ddb - the JSON data type transformer overrides the operation of 
> the endpoint, and takes the operation from the body
> ------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-26043
>                 URL: https://issues.apache.org/jira/browse/CAMEL-26043
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-aws2
>    Affects Versions: 4.18.0, 4.22.0, 4.23.0
>            Reporter: Claus Ibsen
>            Assignee: Claus Ibsen
>            Priority: Major
>             Fix For: 4.24.0
>
>
> The data type transformer {{aws2-ddb:application-json}} 
> ({{Ddb2JsonDataTypeTransformer}}, main 5aac7df76b83) maps a JSON body to the 
> headers of PutItem, UpdateItem or DeleteItem. It takes the operation from the 
> {{CamelAwsDdbOperation}} header, else from the exchange property 
> {{operation}}, else from a top-level {{operation}} field of the JSON body, 
> else PutItem (lines 97-106), and then always sets the 
> {{CamelAwsDdbOperation}} header to it (lines 132, 137 and 143). That header 
> wins over the {{operation}} option of the endpoint 
> ({{Ddb2Producer.determineOperation}}, lines 95-98). So:
> * a route that names the operation on the endpoint, such as 
> {{aws2-ddb:orders?operation=DeleteItem}}, runs PutItem after the transformer, 
> unless it also sets the header or the exchange property;
> * when the route sets neither, the JSON body decides the operation, also over 
> the operation option of the endpoint.
> The aws-ddb-sink Kamelet sets the {{operation}} exchange property, so it is 
> not affected.
> Checked on 4.24.0-SNAPSHOT with {{camel run}} against the AWS emulator of 
> {{camel infra run aws}}, with a table {{orders}} keyed by {{id}}:
> {noformat}
> body {"id": "2", "name": "kamel"}
>   -> transformDataType aws2-ddb:application-json -> 
> aws2-ddb:orders?operation=DeleteItem
>   => item 2 was put
> body {"operation": "DeleteItem", "key": {"id": "1"}}
>   -> transformDataType aws2-ddb:application-json -> 
> aws2-ddb:orders?operation=PutItem
>   => item 1 was deleted
> {noformat}
> The same code is on camel-4.22.x and camel-4.18.x. Found while adding the 
> catalog body types of aws2-ddb (CAMEL-24961).
> *Proposed change*:
> * the transformer takes the operation from the route only: the 
> {{CamelAwsDdbOperation}} header or the {{operation}} exchange property. With 
> neither, it does not set the header, so the operation of the endpoint 
> applies, and it sets the item and key headers that PutItem, UpdateItem and 
> DeleteItem need;
> * a body with an {{operation}} field fails, unless the field names the 
> operation the route set. Ignoring the field would not do: a body meant for 
> DeleteItem, sent to a route that puts, would store an item with only the key 
> over the stored one;
> * note the change in the upgrade guide.
> _Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to