[
https://issues.apache.org/jira/browse/CAMEL-24629?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18113317#comment-18113317
]
Torsten Mielke commented on CAMEL-24629:
----------------------------------------
[~cfitzwater] thanks for the additional test case. I had a deeper look.
My environment is Camel 4.22.0 and Quarkus 3.39.0.
First of all your testcase does not work for me with Camel JBang using the
Camel Main runtime but succeeds on the Quarkus runtime.
I get "{{{}Invalid url: https:/posts?lean=1{}}}" as property {{my.host}} is not
resolved to a value at runtime.
But let's unpack this step by step.
I will start with the most simple Camel route definition for this use case and
go through the various combinations
{code:java}
- route:
from:
uri: timer:test
parameters:
period: "2000"
repeatCount: 1
steps:
- to:
uri: "https://{{my.host}}/posts"
parameters:
lean: "1"
throwExceptionOnFailure: true
- log: ${body}
{code}
and this simple {{{}application.properties{}}}:
{code:java}
my.host = ${HOST}
{code}
In my shell I first of all run
{{export HOST=jsonplaceholder.typicode.com}}
---
1. Running the route with
{{ camel run test.yaml application.properties}}
raises the error
{{ Caused by: [java.lang.IllegalArgumentException - Invalid url:
https:/posts?lean=1.}}
---
2. However, running the route with
{{ camel run test.yaml application.properties --runtime=quarkus}}
succeeds.
*The reason:* using {{{}$\{ENV_VAR{}}}} is not Camel syntax. Camel property
placeholders use {{{{{}...{}}}}}. The {{{}$\{...{}}}} syntax in
application.properties is only processed by frameworks like Spring Boot or
Quarkus that pre-process property files. In plain Camel JBang, {{{}$\{HOST{}}}}
is stored as a literal string.
----
3. Changing the Camel yaml file from
{code:java}
steps:
- to:
uri: "https://{{my.host}}/posts"
{code}
to
{code:java}
steps:
- toD:
uri: "https://{{my.host}}/posts"
{code}
and running the route via
{{ camel run test.yaml application.properties -runtime=quarkus}}
also succeeds. It fails as well when omitting the argument {{-runtime=quarkus}}
for the reason outlined above.
---
4. I then export to a Camel Quarkus project via
{{ camel export --dir=quarkus-app --clean-dir --runtime=quarkus
--gav=com.domain.integrations:issue:24629 application.properties *.camel.yaml}}
and run the same route there via {{mvn package quarkus:dev}} and it succeeds as
well.
---
Bottom line, I see no difference when using {{-to:}} vs {{-toD:}} on either
runtime, Camel Main or Quarkus. It fails each time on Camel Main and succeeds
on Camel Quarkus.
While the Quarkus runtime pre-processes property files, Camel Main does not,
and hence referencing ${HOST} in application.properties does not work with
Camel Main.
If you know you gonna work with the Quarkus runtime always, then it is okay to
use
{code:java}
my.host = ${HOST}
{code}
But another syntax, that is working across all runtimes would be to use this in
application.properties
{code:java}
my.host = {{env:HOST}}
{code}
This is the [Camel
way|https://camel.apache.org/components/4.22.x/properties-component.html#_using_system_and_environment_variables_in_locations]
of resolving environment variables.
Please confirm my findings, perhaps by following the exact the same steps as
above.
> toD not taking into account substituted properties with env variables
> ---------------------------------------------------------------------
>
> Key: CAMEL-24629
> URL: https://issues.apache.org/jira/browse/CAMEL-24629
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 4.22.0
> Reporter: Cameron Fitzwater
> Assignee: Torsten Mielke
> Priority: Minor
> Attachments: camel-24629.zip
>
>
> I have a .env file that has:
> MY_HOST=abc
>
> My application.properties file has:
> my.host=${MY_HOST}
>
> When using {*}toD{*}:
> - toD:
> uri:
> "https://{{{{{}my.host{}}}}}.domain.com/${exchangeProperty.location}"
> parameters:
> lean: 1
> bridgeEndpoint: true
> throwExceptionOnFailure: false
> This is failing when using *quarkus* runtime. I've sourced my .env before
> running camel run/export, still fails.
>
> It does NOT fail when using it in *to:* component.
>
> I use this convention to wire the application so that it can more easily be
> consumable by K8s to set the environment variables.
>
>
> Error:
> {code:java}
> org.apache.camel.FailedToCreateRouteException: Failed to create route:
> get-location at: >>>
> DynamicTo[toD[https://{{my.host}}.domain.com/${exchangeProperty.location}?bridgeEndpoint=true&lean=1&throwExceptionOnFailure=false]]
> <<< in route:
> Route(get-location)[From[rest:get:/:/locations/{id}?routeId=... because:
> Unknown function: MY_HOST at location 8
> https://${MY_HOST}.domain.com/${exchangeProperty.location}?bridgeEndpoint=true&lean=1&throwExceptionOnFailure=false
> *{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)