diff --git a/camel-k-loader-yaml/impl-common/src/main/java/org/apache/camel/k/loader/yaml/support/StepParserSupport.java b/camel-k-loader-yaml/impl-common/src/main/java/org/apache/camel/k/loader/yaml/support/StepParserSupport.java index f4a8c361e..9f9a94a94 100644 --- a/camel-k-loader-yaml/impl-common/src/main/java/org/apache/camel/k/loader/yaml/support/StepParserSupport.java +++ b/camel-k-loader-yaml/impl-common/src/main/java/org/apache/camel/k/loader/yaml/support/StepParserSupport.java @@ -76,54 +76,65 @@ public static String createEndpointUri(CamelContext context, String uri, Map map = new TreeMap<>(parameters); - for (String secretParameter : factory.secretPropertyNames()) { - Object val = map.get(secretParameter); - if (val instanceof String) { - String newVal = (String) val; - if (!newVal.startsWith("#") && !newVal.startsWith("RAW(")) { - map.put(secretParameter, "RAW(" + val + ")"); + try { + if (factory != null && factory.isEnabled(scheme)) { + if (scheme.equals(uri)) { + // + // if the uri is expressed as simple scheme, then we can use the + // discovered EndpointUriFactory to build the uri + // + answer = factory.buildUri(scheme, parameters, false); + } else { + // + // otherwise we have to compose it but we can still leverage the + // discovered EndpointUriFactory to properly handle secrets + // + Map options = new TreeMap<>(parameters); + + for (String secretParameter : factory.secretPropertyNames()) { + Object val = options.get(secretParameter); + if (val instanceof String) { + String newVal = (String) val; + if (!newVal.startsWith("#") && !newVal.startsWith("RAW(")) { + options.put(secretParameter, "RAW(" + val + ")"); + } + } } - } - } - try { - String queryString = URISupport.createQueryString(map, false); - if (ObjectHelper.isNotEmpty(queryString)) { - answer += "?" + queryString; + answer += "?" + URISupport.createQueryString(options, false); } - } catch (URISyntaxException e) { - throw new IllegalArgumentException(e); - } - } else { - try { - answer = getEndpointUriFactory(context, uri).buildUri(uri, parameters); - } catch (URISyntaxException e) { - throw new IllegalArgumentException(e); + } else { + answer += "?" + URISupport.createQueryString(parameters, false); } + } catch (URISyntaxException e) { + throw new IllegalArgumentException(e); } return answer; } - - public static EndpointUriFactory getEndpointUriFactory(CamelContext context, String scheme) { - final EndpointUriFactory factory = context.adapt(ExtendedCamelContext.class).getEndpointUriFactory(scheme); - - if (factory == null) { - throw new IllegalArgumentException("Cannot compute endpoint URI: unable to find an EndpointUriFactory for scheme " + scheme); - } - if (!factory.isEnabled(scheme)) { - throw new IllegalArgumentException("Cannot compute endpoint URI: scheme " + scheme + " is not enabled"); - } - - return factory; - } } diff --git a/components/camel-kamelet-reify/src/generated/resources/org/apache/camel/component/kameletreify/kamelet-reify.json b/components/camel-kamelet-reify/src/generated/resources/org/apache/camel/component/kameletreify/kamelet-reify.json index 19bbb5894..c446dfd6f 100644 --- a/components/camel-kamelet-reify/src/generated/resources/org/apache/camel/component/kameletreify/kamelet-reify.json +++ b/components/camel-kamelet-reify/src/generated/resources/org/apache/camel/component/kameletreify/kamelet-reify.json @@ -11,7 +11,7 @@ "supportLevel": "Preview", "groupId": "org.apache.camel.k", "artifactId": "camel-kamelet-reify", - "version": "1.6.0-SNAPSHOT", + "version": "1.7.0-SNAPSHOT", "scheme": "kamelet-reify", "extendsScheme": "", "syntax": "kamelet-reify:delegateUri", diff --git a/components/camel-kamelet/src/generated/resources/org/apache/camel/component/kamelet/kamelet.json b/components/camel-kamelet/src/generated/resources/org/apache/camel/component/kamelet/kamelet.json index 4ed8146da..3e813a2d4 100644 --- a/components/camel-kamelet/src/generated/resources/org/apache/camel/component/kamelet/kamelet.json +++ b/components/camel-kamelet/src/generated/resources/org/apache/camel/component/kamelet/kamelet.json @@ -11,7 +11,7 @@ "supportLevel": "Preview", "groupId": "org.apache.camel.k", "artifactId": "camel-kamelet", - "version": "1.6.0-SNAPSHOT", + "version": "1.7.0-SNAPSHOT", "scheme": "kamelet", "extendsScheme": "", "syntax": "kamelet:templateId\/routeId", diff --git a/components/camel-knative/camel-knative/src/generated/resources/org/apache/camel/component/knative/knative.json b/components/camel-knative/camel-knative/src/generated/resources/org/apache/camel/component/knative/knative.json index d7753a914..59e3ee8fb 100644 --- a/components/camel-knative/camel-knative/src/generated/resources/org/apache/camel/component/knative/knative.json +++ b/components/camel-knative/camel-knative/src/generated/resources/org/apache/camel/component/knative/knative.json @@ -11,7 +11,7 @@ "supportLevel": "Preview", "groupId": "org.apache.camel.k", "artifactId": "camel-knative", - "version": "1.6.0-SNAPSHOT", + "version": "1.7.0-SNAPSHOT", "scheme": "knative", "extendsScheme": "", "syntax": "knative:type\/typeId", diff --git a/itests/camel-k-itests-kamelet/src/main/java/org/apache/camel/k/quarkus/it/Application.java b/itests/camel-k-itests-kamelet/src/main/java/org/apache/camel/k/quarkus/it/Application.java index 2e111c587..0636b57d1 100644 --- a/itests/camel-k-itests-kamelet/src/main/java/org/apache/camel/k/quarkus/it/Application.java +++ b/itests/camel-k-itests-kamelet/src/main/java/org/apache/camel/k/quarkus/it/Application.java @@ -58,10 +58,10 @@ public JsonObject inspect() { } @GET - @Path("/execute") + @Path("/execute/{id}") @Produces(MediaType.TEXT_PLAIN) - public String execute() { - return template.to("direct:process").request(String.class); + public String execute(@PathParam("id") String id) { + return template.to("direct:" + id).request(String.class); } @POST diff --git a/itests/camel-k-itests-kamelet/src/test/java/org/apache/camel/k/quarkus/it/RuntimeTest.java b/itests/camel-k-itests-kamelet/src/test/java/org/apache/camel/k/quarkus/it/RuntimeTest.java index 5d44732c7..165a60e74 100644 --- a/itests/camel-k-itests-kamelet/src/test/java/org/apache/camel/k/quarkus/it/RuntimeTest.java +++ b/itests/camel-k-itests-kamelet/src/test/java/org/apache/camel/k/quarkus/it/RuntimeTest.java @@ -49,10 +49,20 @@ public void inspect() { } @Test - public void execute() { + public void invokeProcess() { RestAssured.given() .accept(MediaType.TEXT_PLAIN) - .get("/test/execute") + .get("/test/execute/process") + .then() + .statusCode(200) + .body(is("template")); + } + + @Test + public void invokeProcessWithParams() { + RestAssured.given() + .accept(MediaType.TEXT_PLAIN) + .get("/test/execute/process-params") .then() .statusCode(200) .body(is("template")); diff --git a/itests/camel-k-itests-kamelet/src/test/resources/routes.properties b/itests/camel-k-itests-kamelet/src/test/resources/routes.properties index f8882db92..8ffa3bd53 100644 --- a/itests/camel-k-itests-kamelet/src/test/resources/routes.properties +++ b/itests/camel-k-itests-kamelet/src/test/resources/routes.properties @@ -30,4 +30,6 @@ camel.k.sources[1].property-names[0] = message # camel-k - sources (routes) # camel.k.sources[2].location = file:{{env:ROUTES_DIR}}/process.yaml -camel.k.sources[2].type = source \ No newline at end of file +camel.k.sources[2].type = source +camel.k.sources[3].location = file:{{env:ROUTES_DIR}}/process-params.yaml +camel.k.sources[3].type = source \ No newline at end of file diff --git a/itests/camel-k-itests-kamelet/src/test/resources/routes/process-params.yaml b/itests/camel-k-itests-kamelet/src/test/resources/routes/process-params.yaml new file mode 100644 index 000000000..a0f932997 --- /dev/null +++ b/itests/camel-k-itests-kamelet/src/test/resources/routes/process-params.yaml @@ -0,0 +1,24 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +- from: + uri: "direct:process-params" + steps: + - to: + uri: "kamelet:set-body" + parameters: + bodyValue: "template" \ No newline at end of file