Reputation: 137
I want to create an arrayList and iterate over its entries to check if my message has the set properties
<set-variable variableName="ex" value="#[{'A', 'User-Agent', 'Application-ID', 'API-Key', 'P', 'Organization-ID'}]" doc:name="Set Variable" />
<for-each collection="#[ex]" doc:name="Foreach">
<choice doc:name="Choice">
<when expression="#[message.inboundProperties.contains([payload]) == false]">
<set-variable variableName="isRequestValid" value="false" doc:name="Variable"/>
</when>
</choice>
</for-each>
I am getting an error at the for-each expression (Invalid content was found starting with element 'for-each'). Further can we use choice block without otherwise option?
Upvotes: 0
Views: 7017
Reputation: 1401
foreach
#[['A','B']]
expression-filter
inside foreach - <set-variable variableName="ex" value="#[['A', 'User-Agent', 'Application-ID', 'API-Key', 'P', 'Organization-ID']]" doc:name="Set Variable" />
<foreach collection="#[ex]" doc:name="Foreach">
<expression-filter expression="#[message.inboundProperties.contains([payload]) == false]" doc:name="Expression"/>
<set-variable variableName="isRequestValid" value="false" doc:name="Variable"/>
</foreach>
Upvotes: 1
Reputation: 2415
As you have already resolved the issue with for-each, remaining issue can be resolved using following expression
#[message.inboundProperties[payload] !=null]
If it returns true
then header present otherwise not.
Hope this helps.
Upvotes: 0
Reputation: 1277
It shall be foreach
instead of for-each
.
We can use Choice block without otherwise option. But it will introduce runtime error when the value does not match with the logic in when option.
Upvotes: 0
Reputation: 2039
You are probably using an old Mule version, for-each construct was included in 3.4 (see release notes), I cannot think of an other reason for that error. Unfortunately you cannot use choice without otherwise, but there is an improvement reported: https://www.mulesoft.org/jira/browse/MULE-6129
Upvotes: 0