oscerd commented on code in PR #27772:
URL: https://github.com/apache/camel/pull/27772#discussion_r4257210408
##########
components/camel-lra/src/main/java/org/apache/camel/service/lra/LRASagaService.java:
##########
@@ -75,17 +84,107 @@ 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() {
+ List<URI> coordinators = new ArrayList<>();
+ coordinators.add(URI.create(new
LRAUrlBuilder().host(coordinatorUrl).path(coordinatorContextPath).build()));
+ coordinators.addAll(additionalCoordinators());
+ return coordinators;
+ }
Review Comment:
Thanks. This backport keeps the code of #27725 as merged on `main`, where
the same point came up and the list stays computed per call: every accepted
lookup is followed by an HTTP request to the coordinator (join, close or
cancel), so building the list from one or two URLs is noise next to it, and
reading the current options avoids a cache to keep in sync with the setters.
Changing it only on `camel-4.18.x` would make the branches differ, so if
caching turns out to be worth it, it would go to `main` first and be backported
from there.
_Claude Code on behalf of oscerd_
--
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]