Mule expression compare the value of variable with a string #['${forwardAddress}'.startsWith('http://')]

StackOverflow https://stackoverflow.com/questions/22719395

  •  23-06-2023
  •  | 
  •  

سؤال

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top