Mule4 当 json 数组 "contains" 的表达式检查失败时
Mule4 when expression failing for json array "contains" check
正在处理 Mule 3.9 到 Mule 4.x 的迁移工作,API 收到 json 输入负载,如下所示,我正在尝试检查我是否有 DFU
字符串此数组中存在的值 payload.sec_entities
。观察到在日志语句中条件检查工作得很好,请参阅下面错误日志中显示 debug-8、debug-9、debug-10 的日志语句。 问题是 when 表达式中的同一条语句不起作用 谁能提出 when 表达式的问题所在??
尝试过这个,当表达式失败时:
<when expression="#[payload.sec_entities != null and payload.sec_entities contains 'DFU']">
尝试过这个,即使表达式失败:
<when expression="#[%dw 2.0 output application/java --- payload.sec_entities != null and payload.sec_entities contains 'DFU' as String]">
输入载荷:
{
"primary_entities": [
"DMDUNIT",
"LOC"
],
"sec_entities": [
"DFU",
"STOCK"
]
}
代码:
<flow name="Orchestrator-DFU-Flow">
<logger message="debug-8 expression check: payload.sec_entities: #[payload.sec_entities]"/>
<logger message="debug-9 expression check: payload.sec_entities not null check: #[payload.sec_entities != null]"/>
<logger message="debug-10 expression check: payload.sec_entities contains: #[payload.sec_entities contains 'DFU']"/>
<choice doc:name="Choice">
<when expression="#[%dw 2.0 output application/java --- payload.sec_entities != null and payload.sec_entities contains 'DFU' as String]">
<set-payload value="DFU" doc:name="Set Payload" />
<set-variable variableName="filterJson" value="#[%dw 2.0
import java!com::jda::cd::util::StringUtil
output application/json
---
StringUtil::getFilterExpression(vars.modifiedJsonInPayload, payload)]" doc:name="Set dfuFilterJson Session Variable" doc:id="8f20824e-b4eb-431c-a2e3-bdaf155f3367"/>
<set-variable variableName="entityMapForBatch" value='#[{"sec_entities":[payload]}]' doc:name="Variable - entityMapForBatch" doc:id="928fa7d9-b620-4e9f-9a30-caea11dd5d04"/>
<logger message="#['Posting Filter $(payload)']" level="INFO" doc:name="Log_DFU_Filter" />
<flow-ref name="Create_Batch" doc:name="Create_Batch" />
<flow-ref name="post_masterdata_to_messaging_system" doc:name="post_masterdata_to_messaging_system" />
</when>
<otherwise>
<logger level="INFO" doc:name="Logger" message="DFU flows will not be triggered." />
</otherwise>
</choice>
<error-handler ref="Global_Errorflow_Choice_Exception_Strategy" doc:name="Reference Exception Strategy" />
</flow>
错误日志:
INFO 2019-04-03 18:47:20,113 [[MuleRuntime].cpuLight.11: [jda-demand-adapter].Orchestrator-DFU-Flow.CPU_LITE @5011b8c6] [event: 0-cd4e4691-5612-11e9-ae40-0a0027000005] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: debug-8 expression check: payload.sec_entities: ["DFU","STOCK"]
INFO 2019-04-03 18:53:30,181 [[MuleRuntime].cpuLight.09: [jda-demand-adapter].Orchestrator-DFU-Flow.CPU_LITE @36218376] [event: 0-aaaca7c1-5613-11e9-ae40-0a0027000005] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: debug-9 expression check: payload.sec_entities not null check: true
INFO 2019-04-03 18:53:30,183 [[MuleRuntime].cpuLight.09: [jda-demand-adapter].Orchestrator-DFU-Flow.CPU_LITE @36218376] [event: 0-aaaca7c1-5613-11e9-ae40-0a0027000005] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: debug-10 expression check: payload.sec_entities contains: true
ERROR 2019-04-03 18:53:30,187 [[MuleRuntime].cpuLight.09: [jda-demand-adapter].Orchestrator-DFU-Flow.CPU_LITE @36218376] [event: 0-aaaca7c1-5613-11e9-ae40-0a0027000005] org.mule.runtime.core.internal.exception.OnErrorContinueHandler:
********************************************************************************
Message : "Cannot coerce Array (["DFU", "STOCK"]) to Boolean
Trace:
at main (line: 1, column: 91)" evaluating expression: "%dw 2.0 output application/java --- payload.sec_entities != null and payload.sec_entities contains 'DFU' as String".
Error type : MULE:EXPRESSION
Element : Orchestrator-DFU-Flow/processors/3 @ jda-demand-adapter:orchestrator-flow.xml:125 (Choice)
Element XML : <choice doc:name="Choice">
<when expression="#[%dw 2.0 output application/java --- payload.sec_entities != null and payload.sec_entities contains 'DFU' as String]">
找到上述问题的解决方案:
<when expression="#[output application/json
---
((payload.sec_entities != null) and (payload.sec_entities contains 'DFU'))]">
正在处理 Mule 3.9 到 Mule 4.x 的迁移工作,API 收到 json 输入负载,如下所示,我正在尝试检查我是否有 DFU
字符串此数组中存在的值 payload.sec_entities
。观察到在日志语句中条件检查工作得很好,请参阅下面错误日志中显示 debug-8、debug-9、debug-10 的日志语句。 问题是 when 表达式中的同一条语句不起作用 谁能提出 when 表达式的问题所在??
尝试过这个,当表达式失败时:
<when expression="#[payload.sec_entities != null and payload.sec_entities contains 'DFU']">
尝试过这个,即使表达式失败:
<when expression="#[%dw 2.0 output application/java --- payload.sec_entities != null and payload.sec_entities contains 'DFU' as String]">
输入载荷:
{
"primary_entities": [
"DMDUNIT",
"LOC"
],
"sec_entities": [
"DFU",
"STOCK"
]
}
代码:
<flow name="Orchestrator-DFU-Flow">
<logger message="debug-8 expression check: payload.sec_entities: #[payload.sec_entities]"/>
<logger message="debug-9 expression check: payload.sec_entities not null check: #[payload.sec_entities != null]"/>
<logger message="debug-10 expression check: payload.sec_entities contains: #[payload.sec_entities contains 'DFU']"/>
<choice doc:name="Choice">
<when expression="#[%dw 2.0 output application/java --- payload.sec_entities != null and payload.sec_entities contains 'DFU' as String]">
<set-payload value="DFU" doc:name="Set Payload" />
<set-variable variableName="filterJson" value="#[%dw 2.0
import java!com::jda::cd::util::StringUtil
output application/json
---
StringUtil::getFilterExpression(vars.modifiedJsonInPayload, payload)]" doc:name="Set dfuFilterJson Session Variable" doc:id="8f20824e-b4eb-431c-a2e3-bdaf155f3367"/>
<set-variable variableName="entityMapForBatch" value='#[{"sec_entities":[payload]}]' doc:name="Variable - entityMapForBatch" doc:id="928fa7d9-b620-4e9f-9a30-caea11dd5d04"/>
<logger message="#['Posting Filter $(payload)']" level="INFO" doc:name="Log_DFU_Filter" />
<flow-ref name="Create_Batch" doc:name="Create_Batch" />
<flow-ref name="post_masterdata_to_messaging_system" doc:name="post_masterdata_to_messaging_system" />
</when>
<otherwise>
<logger level="INFO" doc:name="Logger" message="DFU flows will not be triggered." />
</otherwise>
</choice>
<error-handler ref="Global_Errorflow_Choice_Exception_Strategy" doc:name="Reference Exception Strategy" />
</flow>
错误日志:
INFO 2019-04-03 18:47:20,113 [[MuleRuntime].cpuLight.11: [jda-demand-adapter].Orchestrator-DFU-Flow.CPU_LITE @5011b8c6] [event: 0-cd4e4691-5612-11e9-ae40-0a0027000005] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: debug-8 expression check: payload.sec_entities: ["DFU","STOCK"]
INFO 2019-04-03 18:53:30,181 [[MuleRuntime].cpuLight.09: [jda-demand-adapter].Orchestrator-DFU-Flow.CPU_LITE @36218376] [event: 0-aaaca7c1-5613-11e9-ae40-0a0027000005] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: debug-9 expression check: payload.sec_entities not null check: true
INFO 2019-04-03 18:53:30,183 [[MuleRuntime].cpuLight.09: [jda-demand-adapter].Orchestrator-DFU-Flow.CPU_LITE @36218376] [event: 0-aaaca7c1-5613-11e9-ae40-0a0027000005] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: debug-10 expression check: payload.sec_entities contains: true
ERROR 2019-04-03 18:53:30,187 [[MuleRuntime].cpuLight.09: [jda-demand-adapter].Orchestrator-DFU-Flow.CPU_LITE @36218376] [event: 0-aaaca7c1-5613-11e9-ae40-0a0027000005] org.mule.runtime.core.internal.exception.OnErrorContinueHandler:
********************************************************************************
Message : "Cannot coerce Array (["DFU", "STOCK"]) to Boolean
Trace:
at main (line: 1, column: 91)" evaluating expression: "%dw 2.0 output application/java --- payload.sec_entities != null and payload.sec_entities contains 'DFU' as String".
Error type : MULE:EXPRESSION
Element : Orchestrator-DFU-Flow/processors/3 @ jda-demand-adapter:orchestrator-flow.xml:125 (Choice)
Element XML : <choice doc:name="Choice">
<when expression="#[%dw 2.0 output application/java --- payload.sec_entities != null and payload.sec_entities contains 'DFU' as String]">
找到上述问题的解决方案:
<when expression="#[output application/json
---
((payload.sec_entities != null) and (payload.sec_entities contains 'DFU'))]">