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

   JIRA: https://issues.apache.org/jira/browse/CAMEL-26283
   
   ## Problem
   
   The `elasticsearch-rest-client` producer built the path of each REST request 
with `String.format`, for example `/<index>/_doc/<id>`, and put the index name 
and the document id into it as they were. The Elasticsearch low-level client 
then parses that string as a URI, so a document id or index name with a 
reserved character was not sent as the value it was given:
   
   - a `/` in the id added a path segment
   - a `?` or `#` in the id ended the path, so only the part before it was used 
as the id
   - a space or a `%` that is not part of a valid escape made the request fail 
while the URI was parsed
   
   The Elasticsearch Java API client sends the same values as single, encoded 
path segments, so an id such as `a/b?c#d e%` works there but did not work with 
this component.
   
   `GET_BY_ID` also failed with a `NullPointerException` when the response had 
no `_source`.
   
   ## Change
   
   - `ElasticsearchRestClientProducer` percent-encodes the document id and the 
index name (UTF-8, a space as `%20`), so each is sent as one path segment and 
Elasticsearch takes it literally. This applies to all six operations for the 
index name, and to `INDEX_OR_UPDATE`, `GET_BY_ID` and `DELETE` for the id.
   - A document id of `.` or `..` is rejected, as such a segment cannot be sent 
as a value.
   - An index name is checked against the characters Elasticsearch does not 
allow in an index name (`\ / ? " < > | #` and space), and must not be empty, 
`.` or `..`. A comma separated list of index names and wildcard patterns such 
as `logs-*,my_index` keeps working: Elasticsearch decodes the segment before it 
splits the list.
   - `GET_BY_ID` returns a `null` body when the response has no `_source`.
   - The component doc describes the encoding, and the upgrade guides on main 
get a note for 4.24, and for 4.22.3 and 4.18.6 as the change is meant to be 
backported to `camel-4.22.x` and `camel-4.18.x`.
   
   No option or header is added, so there are no generated configurer or JSON 
changes; the catalog copy of the component doc is regenerated.
   
   ## Tests
   
   - New `ElasticsearchRestClientRequestPathTest` (27 tests, against a local 
HTTP node that records the raw request): ids with `/`, `?`, `#`, space, `%` and 
non-ASCII characters are sent as one encoded segment without a query string for 
`GET_BY_ID` (header and body), `INDEX_OR_UPDATE` and `DELETE`; an index without 
an id still lets the server choose the id; `.` and `..` ids are rejected; index 
names with characters Elasticsearch does not allow are rejected before any 
request is sent; a list of index names and patterns reaches the node as that 
list; a `GET_BY_ID` response without `_source` gives no document. 20 of these 
fail on the code before the change.
   - 
`ElasticsearchRestClientComponentIT.documentWhoseIdContainsReservedCharacters`: 
indexes, reads back, searches (with an index pattern and name list) and deletes 
a document whose id is `a/b?c#d e%` on a real Elasticsearch (test-infra).
   - `ElasticsearchRestClientITSupport` now keeps one REST client for the class 
and closes it after all tests: the routes of the class are bound to that client 
once, and closing it after each test made a second test that uses Elasticsearch 
fail.
   - `mvn verify` of the module passes (52 unit tests, 3 integration tests).
   
   _Claude Code on behalf of Claus Ibsen_
   
   🤖 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