【问题标题】:Mulesoft Dataweave expression throwing an errorMulesoft Dataweave 表达式引发错误
【发布时间】:2020-07-13 02:03:24
【问题描述】:

Check image to view mule4 screen 我正在使用 mule4 构建集成流、用于数据转换的 Dataweave 表达式和用于测试 HTTP 调用的邮递员,我正在尝试从 Dataweave 中的 XML 下面获取 0011x000014VegoAAC 并插入到 Salesforce 记录中 一切正常,直到我添加了这两行(他们应该从 XML 中提取 0011x000014VegoAAC)

PBSI__Customer__c: (payload.ns0#order.ns0#"custom-attributes".*ns0#"custom-attribute") 
    filter (item) -> (item.@"attribute-id" == "sscAccountid") 

XML

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order order-no="00000907" xmlns="http://www.demandware.com/xml/impex/order/2006-10-31">
    <order-date>2020-07-10T08:57:05.076Z</order-date>
    <current-order-no>00000907</current-order-no>
    <product-lineitems>
        <product-lineitem>
            <net-price>54.17</net-price>
        </product-lineitem>
    </product-lineitems>
    <custom-attributes>
        <custom-attribute attribute-id="Adyen_pspReference">852594371442812G</custom-attribute>
        <custom-attribute attribute-id="Adyen_value">7099</custom-attribute>
        <custom-attribute attribute-id="sscAccountid">0011x000014VegoAAC</custom-attribute>
    </custom-attributes>
</order>

完整的 Dataweave 代码

 %dw 2.0
    output application/java
    ns ns0 http://www.demandware.com/xml/impex/order/2006-10-31
    ---
    [{  
        Ascent4Ecomm__Ecomm_Order_ID__c: payload.ns0#order.ns0#"original-order-no",
        Ascent4Ecomm__Ecomm_Order_Name__c: payload.ns0#order.ns0#"original-order-no",
        Ascent4Ecomm__Ecomm_Order_Number__c: payload.ns0#order.ns0#"original-order-no", 
        attributes: {
            "type": "PBSI__PBSI_Sales_Order__c",
            "referenceId": "SO"
        },
        PBSI__Sales_Order_Lines__r: {
            records: payload.ns0#order.ns0#"product-lineitems".*ns0#"product-lineitem" map ( e , empindex ) -> {
                "attributes": {
                    "type": "PBSI__PBSI_Sales_Order_Line__c",
                    "referenceId": e.ns0#"product-id"
                },
                "PBSI__Item__c": e.ns0#"custom-attributes".ns0#"custom-attribute",
                "PBSI__ItemDescription__c": e.ns0#"product-name"
            }
        },
***These two lines throws error:***
        PBSI__Customer__c: (payload.ns0#order.ns0#"custom-attributes".*ns0#"custom-attribute")
            filter (item) -> (item.@"attribute-id" == "sscAccountid")
    }]

错误

:Invalid status code: 400, response body: [{"message":"Cannot deserialize instance of reference from START_ARRAY value [line:1, column:423]","errorCode":"JSON_PARSER_ERROR"}]

在这两行之前一切正常[Mule4 screen][2]

我正在使用邮递员对该流进行 HTTP 调用

【问题讨论】:

  • 提供更多详细信息,例如,您能否确定哪个处理器在您的流程中引发错误?你能分享一下配置 XML 或者一个能说明问题的项目吗?
  • 那是 HTTP 错误,日志中完整的 DataWeave 错误是什么?
  • 我用更多信息更新了我的帖子,我正在使用 mule4 构建集成流程和邮递员来测试 HTTP 调用

标签: dataweave mulesoft


【解决方案1】:

这是一个 HTTP 400 错误。该描述表明某些应用程序正在尝试解析 JSON 输入。目前尚不清楚与您的 DataWeave 转换的关系,但是它输出的是 Java,而不是 JSON。可能您需要将输出更改为 application/JSON。

更新:基于 cmets,您从 PBSI__Customer__c 返回一个带有一些 id 的单个字符串,它从问题中的 DataWeave 表达式返回一个列表,您需要获取第一个元素。您可以使用索引选择器[0] 来获得它,但我不知道是否可以保证有效负载将始终具有单个元素。

PBSI__Customer__c: ((payload.ns0#order.ns0#"custom-attributes".*ns0#"custom-attribute")
        filter (item) -> (item.@"attribute-id" == "sscAccountid")) [0]

【讨论】:

  • 更改为 Java 没有帮助,我现在已经更新了我的帖子,有帮助吗?也不知何故,我无法使用 flow 和 dataweave 代码上传我的 mule4 屏幕的图像
  • 你的意思是改成application/json?该错误不是 DataWeave,而是由其他组件返回的 HTTP 错误。您应该从 Mule 应用程序的日志中粘贴完整的错误。流程的屏幕截图不是很有用。最好将流的文本 XML 粘贴到问题中。
  • 是的,也尝试了 application/json,Full Mule 错误::无效状态代码:400,响应正文:[{"message":"无法反序列化来自 START_ARRAY 值的引用实例 [line:1,列:423]","errorCode":"JSON_PARSER_ERROR"}]。错误类型:SALESFORCE-COMPOSITE:UNKNOWN 元素:http-basic-authFlow/processors/5 @ 000005107-http-basic-auth:http-basic-auth.xml:59(创建对象树)
  • 元素 XML:
  • 以上 2 cmets 涵盖 mule 控制台错误,PBSI__Customer__c 是对象 PBSI__PBSI_Sales_Order_Line__c 上的查找字段,我正在尝试从 XML 获取 ID 并更新查找字段
猜你喜欢
  • 2019-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多