From 7f8d41e574d8a886c0f5846a14b62621657019ef Mon Sep 17 00:00:00 2001 From: egekaraosmanoglu Date: Mon, 11 Nov 2024 14:43:42 +0100 Subject: [PATCH] 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. --- .../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 a947a2505cb35..d1c5d356500b8 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 @@ -127,8 +127,15 @@ public boolean process(Exchange exchange, AsyncCallback callback) { 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);