davsclaus opened a new pull request, #29027: URL: https://github.com/apache/camel/pull/29027
Fixes [CAMEL-26200](https://issues.apache.org/jira/browse/CAMEL-26200). ### 1 and 4. The registry `LdapConnection` bean is closed after each message, and reconnects without the bind `LdifProducer.processLdif` closes the connection after each message. That is the documented contract (the bean should be a `prototype`, so each message gets a new connection). But a singleton bean (a YAML bean, `@BindToRegistry`, a non-prototype Spring bean) was then reused closed. The client reconnected by itself without a bind, so every change of every later message returned `modifications require authentication`, with no exception. Change: before the changes are applied, a connection that is not authenticated is bound again with `LdapConnection.bind()`, which uses the name and credentials of its `LdapConnectionConfig`. That is the same bind that `DefaultLdapConnectionFactory.newLdapConnection()` does. A prototype connection is already bound, so nothing changes for it. The connection is still closed after each message, so prototype users do not leak connections. In the same method: the connection and the readers are now closed in a `finally` block (before, a failing change, for example a runtime exception, left them open). A missing connection bean now fails with `NoSuchBeanException` instead of a `NullPointerException`. ### 2. A failure status is only the root cause message OpenLDAP sends no message for "entry already exists" or "no such object", so the status was an empty String. The status of a failed change is now `<result code> (<number>) on <DN>[: <message>]`, for example `entryAlreadyExists (68) on uid=test3,ou=test,dc=example,dc=org`. The message part is left out when there is none. A successful change is still `success`. ### 3. An empty or null body ended up `null` The producer set `""` and then overwrote it with the `null` result. It now returns right after setting `""`. ### Tests - New `LdifConnectionTest` (no server): a fake connection that behaves like `LdapNetworkConnection` against a server that refuses anonymous changes. It checks three messages on the same singleton bean, the failure status, the empty and null body, that the connection is closed when a change throws, and the missing bean. All 5 tests failed before the fix. - `LdifRouteIT` (OpenLDAP container): new `twoMessagesWithTheSameConnection`. Without the fix the second message returned `[modifications require authentication]`. `addDuplicate` now checks the exact status, and the setup accepts `entryAlreadyExists (68)` instead of `""`. All 7 ITs pass locally. - `LdifModDnTest`: its stub now answers `isAuthenticated`. ### Docs and generated files - `ldif-component.adoc`: the Result and LdapConnection sections. The YAML example no longer needs the `bind()` step before each message. - `@BodyTypes` producerOut is now `LIST, TEXT` with the new status text, plus the `ldapConnectionName` description. Regenerated `ldif.json`, the catalog copies and the endpoint DSL. - Upgrade guide: a `camel-ldif` entry for the new status format, the `""` result of an empty body and the rebind. ### Not changed - The connection is still closed after each message. Keeping a singleton connection open would leak a connection per message for prototype beans, which is the documented setup. A shared singleton connection is still not safe for concurrent messages, as the docs say. - An empty body gives `""`, as the code meant, not an empty `List`. _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]
