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 bff054e00a5 Escape OPTIONS from ambiguous path exception (#10428)
bff054e00a5 is described below

commit bff054e00a5b13657752ea67a0a994b4a26cffb6
Author: EvanMi <[email protected]>
AuthorDate: Mon Jun 19 15:12:14 2023 +0800

    Escape OPTIONS from ambiguous path exception (#10428)
    
    * 1. throw exception when duplicate servlet path occur in create stage.
    2. throw exception when ambiguous path occur in rest requesting stage.
    
    * and license
    
    * and license
    
    * rollback wrong commit file
    
    * format the code with camel code formatter
    
    * fix bug in PR https://github.com/apache/camel/pull/10400
    
    * follow the style
    
    * escape OPTIONS from ambiguous path exception
    
    * rename method
    
    ---------
    
    Co-authored-by: mipengcheng3 <[email protected]>
---
 .../apache/camel/support/RestConsumerContextPathMatcher.java | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
 
b/core/camel-support/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
index e096355a5d8..76b74b4fd33 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
@@ -196,7 +196,7 @@ public final class RestConsumerContextPathMatcher {
             OptionalInt min = 
pathMap.keySet().stream().mapToInt(Integer::intValue).min();
             if (min.isPresent()) {
                 List<ConsumerPath> bestConsumerPaths = 
pathMap.get(min.getAsInt());
-                if (bestConsumerPaths.size() > 1) {
+                if (bestConsumerPaths.size() > 1 && 
!canBeAmbiguous(requestMethod, requestMethod)) {
                     String exceptionMsg = "Ambiguous paths " + 
bestConsumerPaths.stream().map(ConsumerPath::getConsumerPath)
                             .collect(Collectors.joining(",")) + " for request 
path " + requestPath;
                     throw new IllegalStateException(exceptionMsg);
@@ -218,6 +218,16 @@ public final class RestConsumerContextPathMatcher {
         return answer;
     }
 
+    /**
+     *
+     * @param  requestMethod The request method
+     * @param  requestPath   The request path
+     * @return               if the request method and path can escape from 
the ambiguous exception
+     */
+    private static boolean canBeAmbiguous(String requestMethod, String 
requestPath) {
+        return requestMethod.equalsIgnoreCase("options");
+    }
+
     /**
      * Matches the given request HTTP method with the configured HTTP method 
of the consumer.
      *

Reply via email to