gnodet-bot commented on code in PR #27725:
URL: https://github.com/apache/camel/pull/27725#discussion_r4248077157
##########
components/camel-lra/src/main/java/org/apache/camel/service/lra/LRASagaService.java:
##########
@@ -84,17 +89,86 @@ public boolean isLongRunningActionHeaderSupported() {
return true;
}
+ /**
+ * Returns the coordinator of an LRA, which is joined, completed or
compensated by calling its URL. Only an LRA
+ * hosted by the configured coordinator, or by one of the allowed
coordinator URLs, is accepted.
+ */
@Override
public CompletableFuture<CamelSagaCoordinator> getSaga(String id) {
CompletableFuture<CamelSagaCoordinator> coordinator;
try {
- coordinator = CompletableFuture.completedFuture(new
LRASagaCoordinator(this, URI.create(id).toURL()));
+ URI lra = URI.create(id);
+ if (!isHostedByAllowedCoordinator(lra)) {
+ throw new IllegalArgumentException(
+ "The Long-Running-Action " + id + " is not hosted by
the LRA coordinator configured on the LRA"
+ + " saga service. If it is
a trusted coordinator, add its URL to"
+ + "
allowedCoordinatorUrls.");
+ }
+ coordinator = CompletableFuture.completedFuture(new
LRASagaCoordinator(this, lra.toURL()));
} catch (Exception ex) {
coordinator = CompletableFuture.failedFuture(ex);
}
return coordinator;
}
+ private boolean isHostedByAllowedCoordinator(URI lra) {
+ for (URI coordinator : allowedCoordinators()) {
+ if (isHostedBy(lra, coordinator)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * The URLs of the coordinators whose LRAs are accepted: the configured
coordinator, and the allowed coordinator
+ * URLs.
+ */
+ private List<URI> allowedCoordinators() {
Review Comment:
💡 **Minor performance note (no action required):** `allowedCoordinators()`
rebuilds a fresh `ArrayList`, parses URIs, and splits `allowedCoordinatorUrls`
by comma on every call — and it is called on every `getSaga()` invocation via
`isHostedByAllowedCoordinator()`. For a single coordinator the cost is
negligible. If `additionalCoordinators` is ever populated with a long list or
`getSaga()` is on a hot path under load, caching the computed set (e.g. a
`volatile` field, invalidated on config change) would help. Fine to leave as-is
for now — just worth keeping in mind for a follow-up.
--
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]