This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.14.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.14.x by this push:
new 19effd6 CAMEL-17751: Extracting Camel-Saga-Compensate &
Camel-Saga-Complete f… (#7118)
19effd6 is described below
commit 19effd67092f5968b2a362490736af481a489ddf
Author: Vangelis Papanastasatos <[email protected]>
AuthorDate: Sun Mar 6 20:12:26 2022 +0200
CAMEL-17751: Extracting Camel-Saga-Compensate & Camel-Saga-Complete f…
(#7118)
* CAMEL-17751: Extracting Camel-Saga-Compensate & Camel-Saga-Complete from
CamelHttpQuery header if not present as individual headers
* CAMEL-17751: Comments addressing - Usage of URISupport.parseQuery for
extraction of query params into a Map
Co-authored-by: Vangelis Papanastasatos <[email protected]>
---
.../apache/camel/service/lra/LRASagaRoutes.java | 29 +++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git
a/components/camel-lra/src/main/java/org/apache/camel/service/lra/LRASagaRoutes.java
b/components/camel-lra/src/main/java/org/apache/camel/service/lra/LRASagaRoutes.java
index b333965..70bac76 100644
---
a/components/camel-lra/src/main/java/org/apache/camel/service/lra/LRASagaRoutes.java
+++
b/components/camel-lra/src/main/java/org/apache/camel/service/lra/LRASagaRoutes.java
@@ -16,11 +16,15 @@
*/
package org.apache.camel.service.lra;
+import java.net.URISyntaxException;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeCamelException;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.util.URISupport;
import static
org.apache.camel.service.lra.LRAConstants.PARTICIPANT_PATH_COMPENSATE;
import static
org.apache.camel.service.lra.LRAConstants.PARTICIPANT_PATH_COMPLETE;
@@ -59,7 +63,8 @@ public class LRASagaRoutes extends RouteBuilder {
}
/**
- * Check if the request is pointing to an allowed URI to prevent
unauthorized remote uri invocation
+ * Check if the request is pointing to an allowed URI to prevent
unauthorized
+ * remote uri invocation
*/
private void verifyRequest(Exchange exchange) {
if (exchange.getIn().getHeader(Exchange.SAGA_LONG_RUNNING_ACTION) ==
null) {
@@ -76,6 +81,28 @@ public class LRASagaRoutes extends RouteBuilder {
usedURIs.add(completionURI);
}
+ // CAMEL-17751: Extract URIs from the CamelHttpQuery header
+ if (usedURIs.isEmpty()) {
+ try {
+ Map<String, Object> queryParams =
URISupport.parseQuery(exchange.getIn().getHeader(Exchange.HTTP_QUERY,
String.class));
+ if (!queryParams.isEmpty()) {
+ if (queryParams.get(URL_COMPENSATION_KEY) != null) {
+ compensationURI =
queryParams.get(URL_COMPENSATION_KEY).toString();
+ usedURIs.add(compensationURI);
+ exchange.getIn().setHeader(URL_COMPENSATION_KEY,
compensationURI);
+ }
+
+ if (queryParams.get(URL_COMPLETION_KEY) != null) {
+ completionURI =
queryParams.get(URL_COMPLETION_KEY).toString();
+ usedURIs.add(completionURI);
+ exchange.getIn().setHeader(URL_COMPLETION_KEY,
completionURI);
+ }
+ }
+ } catch (URISyntaxException ex) {
+ throw new RuntimeCamelException("URISyntaxException during " +
Exchange.HTTP_QUERY + " header parsing");
+ }
+ }
+
for (String uri : usedURIs) {
if (!sagaService.getRegisteredURIs().contains(uri)) {
throw new IllegalArgumentException("URI " + uri + " is not
allowed");