【问题标题】:why Multipart/form-data removing Nill in response Mule Dataweave为什么 Multipart/form-data 删除 Nill 以响应 Mule Dataweave
【发布时间】:2020-06-04 23:40:20
【问题描述】:

请发现我的请求带有标签<Date xsi:nil="true"/>,当它穿过Multipart/form-data 数据编织时,它正在删除xsi:nil="true 部分,这在我的场景中是不期望的。我希望它是一样的。

此外,它正在删除不是预期情况的命名空间。如果我尝试在第一个数据编织中声明 ns xsi http://www.w3.org/2001/XMLSchema-instance。在响应根元素中,它以 xsi:Locations 为前缀。 我正在为此苦苦挣扎。

想要下面提到的响应,无论输入相同,都应该在不改变的情况下出来。

使用writeNilOnNull=true 会在我不想要的所有字段上置零,只想要日期。

有人可以帮忙吗?谢谢。

输入:

<Locations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Location>
    <Id>2</Id>
    <CarId>78</CarId>
    <Packages>1</Packages>
    <Date xsi:nil="true"/>
   </Location>
</Locations>

预期响应:

 <Locations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Location>
    <Id>2</Id>
    <CarId>78</CarId>
     <Packages/>
    <Date xsi:nil="true"/>
   </Location>
</Locations>

流程:

        <flow name="question" doc:id="8c836a85-9d0a-47a8-8e5a-f670b16f91eb" >
        <http:listener doc:name="Listener" doc:id="52ffdb08-9587-4cb2-8232-9467e85ea0dc" config-ref="HTTP_Listener_config" path="/question"/>
        <ee:transform doc:name="Transform Message" doc:id="da995adf-196b-4c7b-a265-874f059ed1bb" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/xml 
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <ee:transform doc:name="Transform Message" doc:id="75e5d876-855e-4d38-8468-3484c859f36e" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output multipart/form-data 
---
{
  "parts": {
    "file": {
      "headers": {
        "Content-Disposition": {
          "name": "file",
          "filename": "",
          "subtype": "form-data"
        },
        "Content-Type": "application/xml"
      },
      "content": payload
    }
  }
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
</mule>

【问题讨论】:

  • 问题不在于表单数据转换,而在于第一次转换。

标签: mule dataweave mulesoft mule4


【解决方案1】:

在您的转换中添加 writeNilOnNull=true。像这样

%dw 2.0
var x=read('<Locations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Location>
    <Id>2</Id>
    <CarId>78</CarId>
    <Packages>1</Packages>
    <Date xsi:nil="true"/>
   </Location>
</Locations>','application/xml')
output application/xml writeNilOnNull=true
---
x

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-22
    • 1970-01-01
    • 2022-06-25
    • 2013-09-03
    • 1970-01-01
    • 2018-04-07
    • 2010-11-05
    • 2023-04-03
    相关资源
    最近更新 更多