我有一个Mule工作流,可以接收响应消息或业务错误消息作为转换消息连接器的输入。
当它从转换消息连接器移动到对象到字符串时,它会遇到此错误:
ERROR 2016-10-07 18:08:40,187 [[userprocess].userprocess-httpListenerConfig.worker.01] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Exception while executing:
}) when ((payload[0].userResponse != null and payload[0].userResponse.category == "SUCCESS")) and
^
Type mismatch
found :name, :string
required :name, :object
Type : com.mulesoft.weave.mule.exception.WeaveExecutionException
Code : MULE_ERROR--2
********************************************************************************
Exception stack is:
1. Type mismatch
found :name, :string
required :name, :object (com.mulesoft.weave.engine.ast.dynamic.DynamicDispatchException)
com.mulesoft.weave.engine.ast.dynamic.DynamicDispatchNode:65 (null)
2. Exception while executing:
}) when ((payload[0].userResponse != null and payload[0].userResponse.category == "SUCCESS")) and
^
Type mismatch
found :name, :string
required :name, :object (com.mulesoft.weave.mule.exception.WeaveExecutionException)
com.mulesoft.weave.mule.WeaveMessageProcessor$WeaveOutputHandler:166 (null)
********************************************************************************
Root Exception stack trace:
com.mulesoft.weave.engine.ast.dynamic.DynamicDispatchException: Type mismatch
found :name, :string
required :name, :object
我认为这是因为当转换消息处理消息时,它会根据不同的字段执行逻辑,因此我需要做的就是在返回业务错误消息时忽略任何响应消息逻辑,反之亦然。
我该怎么做?
Dataweave代码(JSON到XML):
%dw 1.0
%output application/xml
---
{
(Data: {
userId: flowVars.queryParams.userId,
Message: "User created successfully"
}) when (payload[0].userResponse.category == "SUCCESS") and
(payload[1].userResponse.category == "SUCCESS"),
(Exception: {
userId: flowVars.queryParams.userId,
Message: payload[1].exception.message
}) when (payload.exception?) and
(payload[1].exception.action == "createUser") and
(payload[0].exception.code != "-1"),
(Exception: {
userId: flowVars.queryParams.userId,
Message: payload[0].exception.message
}) when (payload.exception?) and
(payload[0].exception.action == "amendUser") and
(payload[1].exception.replyStatus.code != "-1"),
}
答案 0 :(得分:0)
您可以在这种情况下使用/何时使用。你很亲密,只需使用 {和} 而不是parens。有点像:
%dw 1.0
%input payload application/json
%output application/xml
---
{
Data: {
userId: flowVars.queryParams.userId,
Message: "User created successfully"
}
}
when (payload[0].userResponse.category == "SUCCESS") and
(payload[1].userResponse.category == "SUCCESS"))
otherwise
{
Exception: {
userId: flowVars.queryParams.userId,
Message: payload[1].exception.message
}
}