我想在 Dataweave 转换中设置为 http.status 代码。为此,我使用以下代码http.status
在选项卡上进行设置:Outbound Property
出站属性 ===> http.status
%dw 1.0
%output application/java
---
"404" when payload[0] == null
otherwise "200"
但即使有效载荷为空,也不会反映出来。有什么建议吗?
编辑:
作为参考,这里是完整的 Dataweave 代码
<dw:transform-message doc:name="buildResponse">
<dw:set-payload>
<![CDATA[%dw 1.0
%input payload application/java
%output application/json
---
{
"customer": {
"id": payload[0].ID,
"name": payload[0].NAME,
"age": payload[0].AGE,
"address": {
"line1": payload[0].LINE1,
"line2": payload[0].LINE2,
"city": payload[0].CITY,
"state": payload[0].STATE,
"pincode": payload[0].PINCODE
}
}
} when (sizeOf payload) > 0
otherwise
{
"customer" : "not found"
}]]>
</dw:set-payload>
<dw:set-property propertyName="http.status">
<![CDATA[%dw 1.0
%output application/java
---
"404" when (sizeOf payload) == 0
otherwise "200"]]>
</dw:set-property>
</dw:transform-message>