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

   Fixes [CAMEL-26221](https://issues.apache.org/jira/browse/CAMEL-26221), 
found while adding the catalog body types (CAMEL-24961).
   
   This builds on CAMEL-26220 (#28974), which manages `com.ibm.cloud:sdk-core` 
at 9.24.3 for the camel-ibm modules: its commit is the first of this branch, so 
the change of this PR is the second commit. Merge this PR after #28974.
   
   ## 1. getAllColumns always fails with NoClassDefFoundError for Gson 
$Gson$Types
   
   **Was:** the watsonx.data SDK 0.9.0 brings `com.ibm.cloud:sdk-core` 9.18.4, 
whose `DynamicModelTypeAdapterFactory` uses the Gson internal class 
`$Gson$Types`, which Gson 2.13.0 renamed to `GsonTypes` (camel-parent manages 
Gson 2.15.0). `getAllColumns` answers a `ColumnsCollection` whose columns are 
`TableColumDetailColumnsItems`, the only model of the SDK with dynamic 
properties, so parsing every response failed with 
`InvalidServiceResponseException` caused by `NoClassDefFoundError: 
com/google/gson/internal/$Gson$Types`. The other operations were not affected.
   
   **Now:** with sdk-core 9.24.3 from CAMEL-26220 the module builds and tests 
with an sdk-core that uses `GsonTypes`, and `getAllColumns` gives the 
`ColumnsCollection`. The module also declares `sdk-core` (with the managed 
version) next to the watsonx.data SDK, so that applications get 9.24.3 too: 
Maven applies the dependency management of camel-ibm-parent when it builds 
Camel, but not when it resolves the dependencies of an application that uses 
the component, which would otherwise still get 9.18.4.
   
   ## 2. updateTable accepts only a java.util.Map body
   
   **Was:** `updateTable` read the patch with `getBody(Map.class)`. JSON text, 
such as a String from HTTP or a file, gave null and failed with `Request body 
with table patch data is required for updateTable operation`, which did not say 
which bodies are accepted.
   
   **Now:** a body that the type converters do not turn into a `Map` is read as 
text and parsed as a JSON object, with the Gson of the IBM SDK, which also 
writes the patch back to JSON for the request, so numbers and nulls are sent as 
written. A String, byte[], InputStream or file with a JSON object works like 
the `Map`. No body or an empty patch fails as before, and the message now names 
the accepted bodies: `a java.util.Map, or a JSON object as text (a String, 
byte[], InputStream or file)`. A body that is not a JSON object (a JSON array, 
other text, bytes that are not UTF-8 text, or a POJO whose text is not JSON) 
fails with an `IllegalArgumentException` that says so, before any request is 
sent.
   
   ## Tests
   
   - New `WatsonxDataProducerTest` (11 tests), with a JDK `HttpServer` as the 
watsonx.data service and as the IAM token service: `getAllColumns` parses a 
response whose column has a property the model does not declare and sends the 
catalog and schema; `updateTable` sends the same merge patch (method, path, 
`engine_id`, `application/merge-patch+json` and body) for a `Map`, a String, a 
byte[], an InputStream and a file; no body, and a body that is not a JSON 
object (a JSON array, other text, bytes `0xff 0xfe`, a POJO), fail with a 
message that names the accepted bodies, and send nothing.
   - With the `src/main` changes reverted, 9 of the 10 updateTable tests fail: 
the String, byte[], InputStream and file bodies with the old `Request body with 
table patch data is required for updateTable operation`, and the tests for no 
body and for the 4 bodies that are not a JSON object on the message, which 
named no accepted body. The one that passes is the `Map` body, which already 
worked.
   - With the sdk-core alignment reverted (the `pom.xml` changes of this 
branch), the `getAllColumns` test fails with `InvalidServiceResponseException` 
caused by `NoClassDefFoundError: com/google/gson/internal/$Gson$Types`; the 
updateTable tests pass, as `Table` has no dynamic properties.
   - Module tests: 20 run (9 existing, 11 new), 0 failures.
   
   ## Docs and generated files
   
   - `@BodyTypes`: updateTable takes a Map, text, bytes, a stream or a file; 
regenerated `ibm-watsonx-data.json` and copied it into the catalog.
   - Component doc: the `updateTable` row names the accepted bodies, and a new 
example renames a table with a JSON body in Java, XML and YAML; copied into the 
catalog.
   - No upgrade guide entry: a `Map` body works as before, and the bodies that 
now work used to fail.
   
   Main only for now, as the other fixes of the CAMEL-24961 follow-ups. 
getAllColumns fails the same way on camel-4.22.x (Gson 2.14.0, watsonx.data SDK 
0.9.0); camel-4.18.x has no camel-ibm-watsonx-data.
   
   _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