I am having problems with a groovy evaluator in mule that gets an invocation property from the message and chekcs if it is null. The code is:
<when expression="#[groovy: (message.getInvocationProperty('firstName', null) != null)]">
This throws"
1.key can not be empty (java.lang.IllegalArgumentException)
javax.script.SimpleBindings:-1 (null)
2. key can not be empty (java.lang.IllegalArgumentException). Message payload is of type: String (org.mule.api.MessagingException)
org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 ( http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html )
At this point i know that firstName property is indeed null - it is not set in the message, but shouldn`t getInvocationProperty('firstName', null) set the property to null as a default value if it is not set?
Any ideas how to solve this?
Thanks
Try using this choice:
<flow name="loan-broker">
<http:inbound-endpoint host="127.0.0.1" port="8080" path="in" exchange-pattern="request-response"/>
<set-variable variableName="prop" value="value" />
<choice>
<when expression="#[flowVars['prop'] != null]" >
<set-payload value="#['prop: ' + flowVars['prop']]"/>
</when>
<otherwise>
<set-payload value="Houston, we have a problem."/>
</otherwise>
</choice>
</flow>
Call it using:
curl http://127.0.0.1:8080/in
You should get value
I finally managed to solve this problem by upgrading mule and using MEL. So the expression now looks like this.
<when expression="#[flowVars.firstName != empty]">
'flowVars' stores all invocation properties and variables assigned in the flow, and if the flow has been called through the
<flow-ref />
all the variables set in the caller flow will be available through the 'flowVars'.
I had same issue, solved with following expression:
<set-variable variableName="firstName" value="${fname}" doc:name="Variable"/>
<when expression="#[flowVars.firstName.isEmpty()]">
<logger message="===== If ===" level="INFO" doc:name="Logger"/>
</when>
<otherwise>
<logger message="===== Else ===" level=" INFO" doc:name="Logger"/>
</otherwise>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.