进行从Mule 3.9到Mule 4.x的迁移工作,API接收到json输入有效载荷,如下所示,我试图检查数组DFU
中是否存在payload.sec_entities
字符串值。观察到在日志语句中条件检查正常运行良好,请参阅下面的“错误日志”中显示debug-8,debug-9,debug-10的日志语句。 问题是在表达式何时使用不正确的语句有人可以建议表达式何时出现问题吗?
尝试此操作,当表达式失败时:
<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]">
答案 0 :(得分:0)
找到了上述问题的解决方案:
<when expression="#[output application/json
---
((payload.sec_entities != null) and (payload.sec_entities contains 'DFU'))]">