[ 
https://issues.apache.org/jira/browse/CAMEL-24629?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18112323#comment-18112323
 ] 

Torsten Mielke commented on CAMEL-24629:
----------------------------------------

I get the same behaviour when following the steps in the description. 

[~cfitzwater] please note: 
Camel only sees *exported* environment variables. 
{{{}echo $\{HOST{}}}} can succeed even when Camel cannot, because the shell and 
the Java process look at different places.

When you {{source .env}} and the file contains:

{{MY_HOST=...}}

the shell creates a shell variable. That lives only in the current shell. 
{{{}echo $\{HOST{}}}} reads the shell’s own variable table, so it prints the 
value.

A child process (the JVM that runs Camel) does not inherit shell variables. It 
inherits the process environment, which is the subset of variables marked for 
export. Camel’s {{{}$\{HOST{}}}} resolution uses that environment 
({{{}System.getenv(){}}} / OS env), so {{HOST}} is missing and resolution fails.

{{export HOST=...}} (or {{set -a}} before sourcing) puts {{HOST}} into the 
environment. Then the Camel process inherits it and {{{}$\{HOST{}}}} in 
{{application.properties}} resolves.

 

You can keep {{.env}} without {{export}} on every line:
{code:java}
set -a
source .env
set +a
{code}

You get the same behaviour using a plain Java application.
I hope that helps as explanation.

> 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
>
> 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)

Reply via email to