I am using the MuleSoft Transform Message component to initialize variables testIP and testDomain. It works well when the payload is not empty, but throws an exception when the payload is null or empty.
The payload is received from an HTTP Listener with content type application/json and the body of the request is empty.
How can I make testIP or testDomain to false when the payload is null?
<ee:transform doc:name="init vars" doc:id="9f281802-c37b-4730-9932-4031337f4a23" >
<ee:message >
</ee:message>
<ee:variables >
<ee:set-variable variableName="testIP" ><![CDATA[%dw 2.0
output application/java
---
if (payload != null and payload.ip? and !(payload.ip is String and payload.ip == ""))
true
else
false]]></ee:set-variable>
<ee:set-variable variableName="testDomain" ><![CDATA[%dw 2.0
output application/java
---
if (payload != null and payload.domain? and !(payload.domain is String and payload.domain == ""))
true
else
false
]]></ee:set-variable>
</ee:variables>
</ee:transform>
Error I got is
"Unable to parse empty input, while reading `payload` as Json.
1|
^" evaluating expression: "%dw 2.0
output application/java
---
if (payload != null and payload.ip? and !(payload.ip is String and payload.ip == ""))
true
else
false".