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 6433f232127 Fix for RestOpenApiProcessor for parsing path variables 
from the http request uri succesfully.  (#16220)
6433f232127 is described below

commit 6433f23212705718f6dd8b0b412e7463f331f44f
Author: egekaraosmanoglu <[email protected]>
AuthorDate: Mon Nov 11 14:43:42 2024 +0100

    Fix for RestOpenApiProcessor for parsing path variables from the http 
request uri succesfully.  (#16220)
    
    * Update RestOpenApiProcessor.java
    
    if uri is not starting with slash then remove the slash in the consumerPath 
from the openApi spec, because if there is any path variables (/../{id}) in the 
consumerPath and the uri does not start with "/" then  
HttpHelper.evalPlaceholders method throws an ArrayIndexOutOfBoundsException.
    
    * code style fixes and added null check the uri.
---
 .../camel/component/rest/openapi/RestOpenApiProcessor.java       | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiProcessor.java
 
b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiProcessor.java
index d1ca7b98c73..d52dfdd1fc4 100644
--- 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiProcessor.java
+++ 
b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiProcessor.java
@@ -109,8 +109,15 @@ public class RestOpenApiProcessor extends 
DelegateAsyncProcessor implements Came
         if (m instanceof RestOpenApiConsumerPath rcp) {
             Operation o = rcp.getConsumer();
 
+            String consumerPath = rcp.getConsumerPath();
+
+            //if uri is not starting with slash then remove the slash in the 
consumerPath from the openApi spec
+            if (consumerPath.startsWith("/") && uri != null && 
!uri.startsWith("/")) {
+                consumerPath = consumerPath.substring(1);
+            }
+
             // map path-parameters from operation to camel headers
-            HttpHelper.evalPlaceholders(exchange.getMessage().getHeaders(), 
uri, rcp.getConsumerPath());
+            HttpHelper.evalPlaceholders(exchange.getMessage().getHeaders(), 
uri, consumerPath);
 
             // process the incoming request
             return restOpenapiProcessorStrategy.process(openAPI, o, verb, uri, 
rcp.getBinding(), exchange, callback);

Reply via email to