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

   Fixes [CAMEL-26234](https://issues.apache.org/jira/browse/CAMEL-26234), 
found while adding the catalog body types (CAMEL-24961).
   
   ## 1. SEARCH ignores a JSON query in the body
   
   **Was:** `search` used the `CamelElasticsearchSearchQuery` header, else a 
`Map` body of fields to match. A JSON text body could not be converted to a 
`Map`, so the request went out with no query and every document matched.
   
   **Now:** when the header is not set and the body is not a `Map`, the text of 
the body (a `String`, bytes, a stream or a file) is sent as the JSON query, as 
the header would be. The header still wins over the body, a `Map` body is still 
turned into a match query, and with no body (or an empty `Map`) every document 
still matches.
   
   ## 2. GET_BY_ID and DELETE: a leftover body wins over CamelElasticsearchId
   
   **Was:** `getById` and `delete` read the id from the body first and used the 
`CamelElasticsearchId` header only when the body was empty, so a body left by a 
previous step was used as the id.
   
   **Now:** the header comes first and the body is used only when the header is 
not set, as `INDEX_OR_UPDATE` does. With neither, the call still fails with "id 
value is mandatory".
   
   ## 3. extractDocument found=false branch is unreachable
   
   **Was:** `extractDocument` returned null when `found` was false, but the 
low-level client fails a 404 with a `ResponseException` before the response 
reaches it, so the branch could never run.
   
   **Now:** the branch is removed, and the behaviour stays as documented and as 
the integration test expects: a `GET_BY_ID` of a missing id fails with the 404 
of the server. The doc of the operation says so.
   
   ## 4. The doc names the headers INDEX_NAME and ID
   
   **Was:** the operations table and the update and delete examples said to set 
the headers `INDEX_NAME` and `ID`.
   
   **Now:** they name `CamelElasticsearchIndexName` and `CamelElasticsearchId`, 
the constants of `ElasticSearchRestClientConstant`.
   
   ## Tests
   
   - `ElasticsearchRestClientProducerBodyTest` (new, 9 tests) runs the producer 
against a JDK `HttpServer` that records the requests: a JSON text and a JSON 
stream body as the search query, the query header over the body, a `Map` body, 
no body, the id header over a leftover body for GET_BY_ID and DELETE, the id of 
the body without header, and a missing id that fails with the 404 of the server.
   - With the fix reverted, 4 of the 9 fail for the issue's reasons: the search 
request goes out with an empty body, and GET_BY_ID and DELETE use the leftover 
body as the id. The 5 that pass check behaviour that does not change: the 
header over the body for SEARCH, a `Map` body, no body, the id of the body 
without header, and the 404 of a missing id.
   - Module: 25 tests, 0 failures. The integration test needs a container and 
was not run; it does not rely on the changed behaviour.
   
   ## Docs and generated files
   
   - The `@BodyTypes` of the endpoint: SEARCH takes text, bytes, a stream or a 
file as well as a `Map` or no body, and the description of the id of GET_BY_ID 
and DELETE.
   - `elasticsearch-rest-client-component.adoc`: the header names, the search 
body with a Java example, and the order of the id header and the body. The 
catalog copies of the JSON and the doc are updated.
   
   ## Not changed
   
   - For item 3 the issue offered to catch the 404 and return null instead. 
That would change the result of a missing id from an error to a null body, 
which the integration test and the documented body types rely on, so the dead 
branch is removed and the 404 stays. Returning null can be a follow-up if 
wanted; DELETE of a missing id fails with 404 the same way.
   - A body that is neither a `Map` nor empty is sent as the query without 
checking it is JSON: the server reports a query it cannot parse, as it does for 
the header.
   
   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