首页 > 解决方案 > 您使用这些参数调用了函数“值选择器”

问题描述

我正在使用 Mulesoft 实施 LoanBroker,但在发送请求时出现错误消息。我从 Postman 和 Mulesoft Anypoint Studio 收到以下错误消息:

ERROR 2021-06-27 15:20:51,133 [[MuleRuntime].uber.04: [loanbroker].LoanBrokerFlow_Gr7.CPU_LITE @254be3ee] [processor: LoanBrokerFlow_Gr7/processors/0; event: 7e49f560-d74a-11eb-b598-b66921dc5aa5] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler: 
********************************************************************************
Message: "You called the function 'Value Selector' with these arguments: 
  1: Binary ("" as Binary {base: "64"})
  2: Name ("amount")

But it expects one of these combinations:
  (Array, Name)
  (Array, String)
  (Date, Name)
  (DateTime, Name)
  (LocalDateTime, Name)
  (LocalTime, Name)
  (Object, Name)
  (Object, String)
  (Period, Name)
  (Time, Name)

1| payload.amount
   ^^^^^^^^^^^^^^
Trace:
  at main (line: 1, column: 1)" evaluating expression: "payload.amount".
Element               : LoanBrokerFlow_Gr7/processors/0 @ loanbroker:bi_gruppe7.xml:34 (Copy_of_setAmount)
Element DSL           : <set-variable value="#[payload.amount]" doc:name="Copy_of_setAmount" doc:id="cbcca557-1a69-4cf2-80b1-64333175589d" variableName="amount"></set-variable>
Error type            : MULE:EXPRESSION
FlowStack             : at LoanBrokerFlow_Gr7(LoanBrokerFlow_Gr7/processors/0 @ loanbroker:bi_gruppe7.xml:34 (Copy_of_setAmount))

  (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

谁能帮我?

谢谢

标签: postmananypoint-studiomulesoft

解决方案


这通常发生在尝试访问像 json 这样的有效负载的内部值但传入的有效负载实际上不是 json 类型时。

可以检查有效负载mediaType,然后尝试访问金额以避免值选择器异常。

%dw 2.0
output application/java
---
if( !isEmpty(payload) and payload.^mediaType contains "json" )
   payload.amount
else
   read(payload, "application/json").amount //best effort

建议创建一个单独的 dataweave 文件dwl/set-amount.dwl并引用它。


推荐阅读