camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [camel] branch camel-2.19.x updated: CAMEL-11951: Fixed rest-dsl uri matching when using matchOnUriPrefix to match more broadly should take in account http request method in use.
Date Tue, 31 Oct 2017 10:24:41 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/camel-2.19.x by this push:
     new 2993142  CAMEL-11951: Fixed rest-dsl uri matching when using matchOnUriPrefix to
match more broadly should take in account http request method in use.
2993142 is described below

commit 2993142cfdb05cd1580fcf5790829f1f3ea4a309
Author: Claus Ibsen <claus.ibsen@gmail.com>
AuthorDate: Tue Oct 31 11:22:06 2017 +0100

    CAMEL-11951: Fixed rest-dsl uri matching when using matchOnUriPrefix to match more broadly
should take in account http request method in use.
---
 .../common/HttpServletResolveConsumerStrategy.java | 23 ++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpServletResolveConsumerStrategy.java
b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpServletResolveConsumerStrategy.java
index 027aca1..e55e650 100644
--- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpServletResolveConsumerStrategy.java
+++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpServletResolveConsumerStrategy.java
@@ -16,7 +16,11 @@
  */
 package org.apache.camel.http.common;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
 import java.util.Map;
+import java.util.stream.Collectors;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.camel.support.RestConsumerContextPathMatcher;
@@ -35,6 +39,7 @@ public class HttpServletResolveConsumerStrategy implements ServletResolveConsume
         HttpConsumer answer = consumers.get(path);
 
         if (answer == null) {
+            List<HttpConsumer> candidates = new ArrayList<>();
             for (String key : consumers.keySet()) {
                 //We need to look up the consumer path here
                 String consumerPath = consumers.get(key).getPath();
@@ -42,8 +47,17 @@ public class HttpServletResolveConsumerStrategy implements ServletResolveConsume
                 boolean matchOnUriPrefix = consumer.getEndpoint().isMatchOnUriPrefix();
                 // Just make sure the we get the right consumer path first
                 if (RestConsumerContextPathMatcher.matchPath(path, consumerPath, matchOnUriPrefix))
{
-                    answer = consumers.get(key);
-                    break;
+                    candidates.add(consumer);
+                }
+            }
+
+            if (candidates.size() == 1) {
+                answer = candidates.get(0);
+            } else {
+                // extra filter by restrict
+                candidates = candidates.stream().filter(c -> matchRestMethod(request.getMethod(),
c.getEndpoint().getHttpMethodRestrict())).collect(Collectors.toList());
+                if (candidates.size() == 1) {
+                    answer = candidates.get(0);
                 }
             }
         }
@@ -51,4 +65,9 @@ public class HttpServletResolveConsumerStrategy implements ServletResolveConsume
         return answer;
     }
 
+    private static boolean matchRestMethod(String method, String restrict) {
+        return restrict == null || restrict.toLowerCase(Locale.ENGLISH).contains(method.toLowerCase(Locale.ENGLISH));
+    }
+
+
 }

-- 
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <commits@camel.apache.org>'].

Mime
View raw message