You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/03/06 18:14:03 UTC

[camel] branch main updated: CAMEL-17751: Extracting Camel-Saga-Compensate & Camel-Saga-Complete f… (#7118)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 00dcdd9  CAMEL-17751: Extracting Camel-Saga-Compensate & Camel-Saga-Complete f… (#7118)
00dcdd9 is described below

commit 00dcdd9931947247eca31fbb058309e2a71fe314
Author: Vangelis Papanastasatos <va...@gmail.com>
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 <pa...@unisystems.gr>
---
 .../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 23b7c68..fc8688c 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;
@@ -58,7 +62,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) {
@@ -75,6 +80,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");