我是Mule4和Dataweave 2.0的新手,我很难将HTTP Request响应转换为Base64值。在几个步骤中,这就是我正在做的事情:
以下是之前的操作所涉及的XML:
<foreach doc:name="For Each Documents in FactIntake" doc:id="6ee1729e-0280-41e6-bc29-039ad404d74d" collection="vars.factIntake.documents">
<set-variable value="#[vars.factIntake.documents[0].documentId]" doc:name="Set documentId" doc:id="c28e1d72-bb82-43af-b340-d91b5cbc428e" variableName="docId"/>
<http:request method="GET" doc:name="GetDocumentMetadata" doc:id="87006616-e519-4f0f-b5e2-be33c6cf5dae" config-ref="HTTP_Request_DocManagement" path="documents/{documentId}" outputMimeType="application/pdf">
<http:uri-params><![CDATA[#[output application/java
---
{
documentId : vars.factIntake.documents[0].documentId
}]]]></http:uri-params>
<http:response-validator>
<http:success-status-code-validator values="200, 404"/>
</http:response-validator>
</http:request>
<choice doc:name="Condition" doc:id="76c0dc6f-3d9c-452f-960d-6bd8a0039ebc">
<when expression="#[attributes.statusCode == 200]">
<ee:transform doc:name="Transform Message" doc:id="ad2a1dd7-0973-4854-b44c-bdfe8eb54778">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/java
---
write(payload, "text/plain")]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="documentsArray"><![CDATA[%dw 2.0
output application/java
---
vars.documentsArray + vars.document]]></ee:set-variable>
</ee:variables>
</ee:transform>
<ee:transform doc:name="Transform Message" doc:id="9ef64824-ffc1-4a56-b97c-d57cc37800a5">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
import * from dw::core::Binaries
output application/java
---
vars.documentsArray + toBase64(payload)]]></ee:set-payload>
</ee:message>
</ee:transform>
</when>
<otherwise>
<flow-ref doc:name="Document Not Found Logging" doc:id="0d6b7df4-fde1-4d77-9257-2ffe1e9f5468" name="IntegrationFabricLogsFlow"/>
</otherwise>
</choice>
</foreach>
有问题吗?添加到documentsArray
的值为NULL。我在这里想念的是什么?我的想法不多了,Google / Internet对此主题没有帮助。
有什么帮助/想法吗?
答案 0 :(得分:0)
好像您的有效载荷是一个Java对象而不是二进制对象,因此在转换为base 64之前将其转换为二进制对象
%dw 2.0
import * from dw::core::Binaries
var binaryPayload = payload as Binary
output application/java
---
vars.documentsArray + toBase64(binaryPayload)