【问题标题】:Getting Error while sending json objects as headers in mule 4 http connector在 mule 4 http 连接器中将 json 对象作为标头发送时出错
【发布时间】:2022-11-23 11:59:43
【问题描述】:

我的 Https 标头在 Mule http 请求者中采用这种格式

%dw 2.0 
output application/java
{    "Content-Transfer-Encoding" :"base64",
    "X-do-Authentication" : {"Username": "xxx@yyy.org","Password": "xxxyyy","IntegratorKey": "4xzzzz"}
}

尝试以这种格式发送标头时出现此错误

Message               : "java.lang.IllegalStateException - No read or write handler for Username
java.lang.IllegalStateException: No read or write handler for Username
    at org.mule.weave.v2.module.pojo.reader.PropertyDefinition._type$lzycompute(PropertyDefinition.scala:44)
    at org.mule.weave.v2.module.pojo.reader.PropertyDefinition._type(PropertyDefinition.scala:35)
    at org.mule.weave.v2.module.pojo.reader.PropertyDefinition.classType(PropertyDefinition.scala:70)

我尝试将输出设置为 text/plain 但这仍然不起作用我该如何继续。我正在使用 Mule 4

【问题讨论】:

    标签: dataweave mulesoft mule4


    【解决方案1】:

    HTTP 标头不支持将 JSON 对象作为值。我认为您需要在标头中传递 JSON 字符串。换句话说,您只需要将 JSON 转换为 String。您可以为此使用write 函数

    %dw 2.0 
    output application/java
    ---
    {    "Content-Transfer-Encoding" :"base64",
        "X-do-Authentication" : write({"Username": "xxx@yyy.org","Password": "xxxyyy","IntegratorKey": "4xzzzz"}, "application/json", {indent: false})
    }
    

    【讨论】:

      【解决方案2】:

      您必须重写对象: {"Username": "xxx@yyy.org","Password": "xxxyyy","IntegratorKey": "4xzzzz"} 使用以下命令转换为 JSON: write({"Username": "xxx@yyy.org","Password": "xxxyyy","IntegratorKey": "4xzzzz"}, "application/json")

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-12
        • 2020-05-04
        • 2011-04-05
        • 2020-07-20
        • 2011-02-24
        • 1970-01-01
        相关资源
        最近更新 更多