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

   Fixes [CAMEL-26174](https://issues.apache.org/jira/browse/CAMEL-26174).
   
   ### 1. A request Map with `key_names` as a String failed with a 
ClassCastException
   
   `StitchRequestBody.fromMap` cast `key_names` to a `Collection`, so 
`"key_names": "id"` failed.
   
   Changed: a String is now taken as one key name, or as comma separated key 
names (trimmed, empty parts dropped). A Collection works as before.
   
   ### 2. A message Map with an Integer `sequence` failed with "Cannot cast 
java.lang.Integer to java.lang.Long"
   
   `StitchMessage.fromMap` cast `sequence` to `Long`. A Map read from JSON or 
YAML, or written in Groovy, has a small number as an `Integer`.
   
   Changed: any `Number` is accepted (`longValue()`). Other types still go 
through the old cast.
   
   Related bug on the same lines, fixed too: the default sequence was `private 
static final long DEFAULT_SEQUENCE = System.currentTimeMillis()`, so every 
message without a `sequence` got the same value: the time the `StitchMessage` 
class was loaded. The builder javadoc says the default is 
`System.currentTimeMillis()`, and Stitch uses the sequence to order records 
with the same primary key. A message without a sequence now gets the time it is 
built.
   
   ### 3. A response with an empty body left the input body and set no headers
   
   `StitchClientImpl.generateStitchResponse` mapped `bufMono.asString()`, which 
emits nothing for an empty body, so no `StitchResponse` was produced and the 
producer never set the body or the `CamelStitchCode`, `CamelStitchStatus` and 
`CamelStitchHeaders` headers. The same path also meant an error response 
(status 300 or above) with an empty body was silently ignored: the exchange 
completed without an exception.
   
   Changed: `defaultIfEmpty(Collections.emptyMap())` after the JSON parse, so 
an empty body is handled like an empty JSON object. A 2xx gives an empty 
message and the headers; an error status fails the exchange with a 
`StitchException`.
   
   ### Tests
   
   - `StitchRequestBodyTest`: `key_names` as `"id"` and as `"id, name"`.
   - `StitchMessageTest`: an `Integer` sequence; the default sequence is the 
build time (Awaitility waits for the clock to move after class load, no sleep).
   - New `StitchClientImplTest`: the real `StitchClientImpl` against a local 
JDK `HttpServer` that answers 200 and 500 with an empty body, through a 
`stitch:` route.
   
   All 6 new tests fail without the fix and pass with it. Module: 28 tests, 0 
failures (the 7 ITs need a Stitch token and are skipped as before). Adds 
`awaitility` as a test dependency.
   
   ### Docs and generated files
   
   - `@BodyTypes` text of the endpoint: `key_names as a list or a comma 
separated String`; regenerated `stitch.json` and copied it and the component 
doc to the catalog.
   - `stitch-component.adoc`: the Map section says `key_names` can be a String 
and how `sequence` defaults.
   - Upgrade guide 4.24: new `camel-stitch` entry for the empty response 
(headers now set; an empty error response now fails) and the default sequence.
   
   ### Not changed
   
   - The `CamelStitchKeyNames` header and the `keyNames` option are split on 
`,` without trimming, so `"id, name"` there gives the key `" name"`. That is a 
different code path (`StitchProducerOperations.getKeyNames`); left for a 
separate change.
   - `StitchClientImpl.getHeaders` collects the response headers with 
`Collectors.toMap`, which throws on a repeated header name (for example two 
`Set-Cookie`). Not in this issue; how to merge the values is a choice.
   
   _Claude Code on behalf of Claus Ibsen (davsclaus)_
   
   🤖 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