I need to dynamically set address on an outbound endpoint, and depending on what I receive in forward.url, this outbound URL can be either HTTP or HTTPS. So, I created 2 subflows, one for HTTP and other for HTTPS.
To route the request to appropriate subflow, I am wrote a CHOICE router as shown below
<set-variable value="#[message.inboundProperties['http.query.params']['forward.url']]" variableName="forwardAddress" doc:name="Variable"/>
<logger message="Forward address is #[forwardAddress] , and does it start with http:// ~ #[String.valueOf('${forwardAddress}').startsWith('http://');]" level="INFO" doc:name="Logger"/>
<choice doc:name="Choice">
<when expression="#['${forwardAddress}'.startsWith('http://')]">
<flow-ref name="HttpCall" doc:name="HTTP subflow"/>
</when>
<when expression="#['${forwardAddress}'.startsWith('https://')]">
<flow-ref name="Httpscall" doc:name="HTTPS subflow"/>
</when>
<otherwise>
<set-payload value="The query string forward.url must start with http:// or https://" doc:name="Set Payload"/>
<http:response-builder doc:name="Invalid Request - 400" status="400"/>
</otherwise>
</choice>
However, the expression is not working correctly. What am I doing wrong?
The syntax ${} is for spring property placeholders. Use #[flowVars.forwardAddress] or #[forwardAddress] for flow variables.