gnodet commented on code in PR #26845:
URL: https://github.com/apache/camel/pull/26845#discussion_r4094741839
##########
components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlComponent.java:
##########
@@ -151,6 +158,51 @@ protected Endpoint createEndpoint(String uri, String
remaining, Map<String, Obje
return endpoint;
}
+ @Override
+ public void onSecretRotation(Object source) throws Exception {
+ // Collect all DataSources this component can reach: the one injected
directly (if any)
+ // plus all DataSource beans registered in the registry. The registry
beans are typically
+ // not recreated during a route reload, so their connection pools
still hold connections
+ // that were authenticated with the old credentials.
+ Set<DataSource> dataSources =
getCamelContext().getRegistry().findByType(DataSource.class);
+ if (this.dataSource != null) {
+ dataSources.add(this.dataSource);
+ }
+
+ for (DataSource ds : dataSources) {
+ evictDataSourceConnections(ds, source);
+ }
+ }
+
+ /**
+ * Evicts stale connections from the given DataSource so that the pool
rebuilds them with the rotated credentials.
+ * <p/>
+ * HikariCP is tried first via reflection (so camel-sql does not need a
compile-time dependency on it). Any
+ * DataSource that does not expose a {@code softEvictConnections()} method
is left untouched — the pool will pick up
+ * the new credentials on its own reconnect cycle when existing
connections expire.
+ */
+ static void evictDataSourceConnections(DataSource ds, Object source) {
+ // HikariCP: softEvictConnections() marks all current connections for
eviction while
+ // allowing in-flight queries to complete; the pool then recreates
them with the new credentials.
+ try {
+ Method softEvict = ds.getClass().getMethod("softEvictConnections");
Review Comment:
The code does not call `softEvictConnections()` on `HikariDataSource`
directly — you're right that the method is not on `HikariDataSource`. The
approach is a two-step reflection call:
1. Call `getHikariPoolMXBean()` on the `HikariDataSource` instance — this
method *is* public on `HikariDataSource` (see
[HikariDataSource.java](https://github.com/brettwooldridge/HikariCP/blob/dev/src/main/java/com/zaxxer/hikari/HikariDataSource.java#L281)),
and it returns a `HikariPoolMXBean`.
2. Call `softEvictConnections()` on that `HikariPoolMXBean` — this method
*is* on `HikariPoolMXBean` (see
[HikariPoolMXBean.java](https://github.com/brettwooldridge/HikariCP/blob/dev/src/main/java/com/zaxxer/hikari/HikariPoolMXBean.java#L46)).
The test creates a dummy class with `getHikariPoolMXBean()` returning a mock
object with `softEvictConnections()`, which mirrors exactly what the real
HikariCP API does. This avoids a compile-time dependency on HikariCP in
camel-jdbc/camel-sql.
--
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]