oscerd opened a new pull request, #28966:
URL: https://github.com/apache/camel/pull/28966

   Fixes [CAMEL-26267](https://issues.apache.org/jira/browse/CAMEL-26267), 
found while adding the catalog body types (CAMEL-24961).
   
   ## 1. A JSON body as bytes or stream fails
   
   **Was:** `updateUser` and `updateGroup` took an `UpdateUserOption` or a 
`KeystoneUpdateGroupOption` of the SDK, or a `String`, only. JSON as a byte[], 
a stream or a file failed with "Exchange body is mandatory and should be a 
valid JSON string or UpdateUserOption object".
   
   **Now:** any other body is converted to text with the type converter 
(`getMandatoryBody(String.class)`) and then parsed, so JSON as a String, 
byte[], InputStream or File works, in the charset of the exchange. A body that 
is not valid JSON still fails with an `IllegalArgumentException`. Its message 
now names the expected type and where the JSON is wrong (line and column, or 
the unknown field, such as `domainId` for `domain_id`). It does not include the 
message of Jackson, which can quote a value of the body, such as the `password` 
of an `UpdateUserOption`. The old message had no detail at all. The catalog 
body types (`producerIn`) are updated.
   
   ## 2. The output JSON uses the SDK's Java field names
   
   **Was:** the results were written with Gson, which uses the Java field names 
of the SDK models (`domainId`, `pwdStatus`, `lastProjectId`, `createTime`). The 
requests were already read with Jackson and the names of the API (`domain_id`), 
and camel-huaweicloud-dms writes the names of the API.
   
   **Now:** the results are written with Jackson: one `ObjectMapper` per 
producer, created when it starts, as in camel-huaweicloud-dms, and also used to 
read the requests. Every field of the SDK result models (`ShowUserResult`, 
`UpdateUserResult`, `KeystoneListUsersResult`, `KeystoneUserResult`, 
`KeystoneGroupResult`, `KeystoneGroupResultWithLinksSelf`; checked in SDK 
3.1.222) has a `@JsonProperty` with the name of the API and 
`@JsonInclude(NON_NULL)`. So the keys are the names of the API, and null fields 
are still left out, as with Gson. The order of the fields does not change. The 
Gson dependency of the module is removed, as nothing uses it any more.
   
   ## Also
   
   - Component doc: the `updateGroup` examples called `updateUser` (with a 
`groupId`), the Java-only examples passed the option object to `setBody` 
without `constant(...)`, which does not compile, and the ServiceKeys example 
named `org.apache.camel.component.huaweicloud.iam.models.ServiceKeys`, which 
does not exist (the class is in 
`org.apache.camel.component.huaweicloud.common.models`). All three are fixed.
   
   ## Tests
   
   - New `IAMProducerJsonTest` (15 tests) with an `IamClient` subclass set on 
the endpoint (`iamClient=#iamClient`). It keeps the update requests and returns 
results with fields whose API name differs from the Java name. It covers JSON 
as a byte[] (with non-ASCII text), an InputStream and a File for both updates, 
and the failures: a text that is not JSON with a password (which the message 
does not quote), bytes that are not JSON (0xff 0xfe), an unknown field, and no 
body. It also covers the field names of the results of getUser, listUsers, 
listGroups and updateGroup.
   - `GetUserTest`, `ListUsersTest`, `UpdateGroupJsonTest` and 
`UpdateGroupTest` now expect `domain_id` instead of `domainId`.
   - With the `src/main` changes and the pom reverted, 11 of the 15 new tests 
fail on the bug: the updates fail on JSON as bytes, a stream or a file, the 
results have the Java names, and the unknown field is not named. The 4 that 
pass are failures that already happened before: a text that is not JSON, bytes 
that are not JSON, and no body for updateUser and updateGroup. The 4 updated 
tests fail too (Java names).
   - Module: 33 tests, 0 failures, 8 skipped (the functional tests, which need 
a Huawei Cloud account).
   
   ## Docs and generated files
   
   Component doc: the update operations read the JSON from text, bytes, a 
stream or a file, a new "JSON of the Results" section says which names the keys 
have, with an example, and the examples above are fixed. The regenerated 
`hwcloud-iam.json` (body types) is copied into the catalog with the doc. 
Upgrade guide entry for 4.24: the field names of the results, with examples of 
renamed fields, and the removed Gson dependency.
   
   ## Not changed
   
   - camel-huaweicloud-obs also writes its results with Gson. Its SDK 
(esdk-obs-java) has no Jackson annotations, so there is no API naming to switch 
to, and it is not part of this issue.
   
   Main only, as the other fixes of the CAMEL-24961 follow-ups.
   
   _Claude Code on behalf of Andrea Cosentino (oscerd)_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to