I am new to Mule4 and Dataweave 2.0 and I am having a hard time trying to convert an HTTP Request response into a Base64 value. In a few steps here is what I am doing:
- Send a request to an API and outputting the response as "application/pdf"
- Converting the payload to an string
- "Encoding" the payload to Base64
- Adding the result to an array
Here is the XML involved on the actions before:
<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>
The problem? The values added to documentsArray are NULL. What I am missing here? I am running out of ideas and Google/Internet hasn't been helpful on this topic.
Any help/ideas?