(solved) Mule 4 - Sending Payload After Transform to Azure File Share - azure-storage

Simple flow to fetch xml and send it back to Azure File Share after adding date to it. I'm using Azure Storage Connector.
Upload file in root directory with stream fails with following error:
ERROR 2020-07-30 10:44:15,756 [[MuleRuntime].uber.03: [azure_test].azure_testFlow.BLOCKING #7dde3fa] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler:
********************************************************************************
Message : File length must be greater than 0 bytes.
Element : azure_testFlow/processors/6 # azure_test:azure_test.xml:33 (Upload file in root directory with stream)
Element DSL : <azure-storage:upload-file-in-root-directory-with-stream doc:name="Upload file in root directory with stream" doc:id="93b6bb01-c42c-454a-aaca-3c3325534b5d" config-ref="Azure_Storage_Config" target="payload">
<azure-storage:rootfile fileName="output" fileStream="#[payload]" shareName="dev"></azure-storage:rootfile>
</azure-storage:upload-file-in-root-directory-with-stream>
Error type : MULE:UNKNOWN
FlowStack : at azure_testFlow(azure_testFlow/processors/6 # azure_test:azure_test.xml:33 (Upload file in root directory with stream))
--------------------------------------------------------------------------------
As the pictures show the payload is in quotes after the first two processors (not counting loggers). After Transform Message however the quotes are gone and when I click Update value... it's empty. Does this mean the output payload after Transform Message isn't in the stream anymore? If so how can I make transform output a stream if possible at all? The Logger after the transform writes the new payload in the console though.
Edit:
Here's the input file:
<data>DATA</data>
XML of the flow:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:azure-storage="http://www.mulesoft.org/schema/mule/azure-storage"
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/azure-storage http://www.mulesoft.org/schema/mule/azure-storage/current/mule-azure-storage.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<azure-storage:config name="Azure_Storage_Config" doc:name="Azure Storage Config" doc:id="ced6e7d8-da1c-4d1e-b02c-fb990de78ed1" >
<azure-storage:sas-token-config-connection accountName="account" sasToken="token"/>
</azure-storage:config>
<flow name="azure_testFlow" doc:id="bcb34135-5d34-4fd8-b794-1a6a668d6f53" >
<azure-storage:download-file-from-root-directory doc:name="Download file from root directory" doc:id="c3893681-5489-4ee0-8058-38b189895a01" config-ref="Azure_Storage_Config">
<azure-storage:root-file fileName="input" shareName="dev" />
</azure-storage:download-file-from-root-directory>
<logger level="INFO" doc:name="Logger" doc:id="183d3636-9ef6-4fb0-b144-c880949dda36" message='#[payload]'/>
<set-payload value="#[payload]" doc:name="Set Payload" doc:id="20769233-90e1-4c5c-9556-b8e582cd638c" mimeType="application/xml" encoding="UTF-8"/>
<logger level="INFO" doc:name="Logger" doc:id="62d02465-952a-4de2-9c9d-a8319f3ddb96" message="#[payload]" />
<ee:transform doc:name="Transform Message" doc:id="04150311-2a96-4215-b252-07a36c3b133e" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/xml writeDeclaration=false
---
{
data: payload.data ++ now() as String {format: "yyyyMMddHHmm"}
}]]></ee:set-payload>
</ee:message>
<ee:variables >
</ee:variables>
</ee:transform>
<azure-storage:upload-file-in-root-directory-with-stream doc:name="Upload file in root directory with stream" doc:id="9a2f25b6-270f-4cff-bc87-141d7e30147e" config-ref="Azure_Storage_Config">
<azure-storage:rootfile fileName="outputStream" fileStream="#[payload]" shareName="dev" />
</azure-storage:upload-file-in-root-directory-with-stream>
<file:write doc:name="Write" doc:id="f3dc6f68-06aa-4755-b9a6-09cad8224fb7" path="C:\Users\jespe\outputFile" />
<azure-storage:upload-file-in-root-directory doc:name="Upload file in root directory" doc:id="2ccac879-d196-41e1-8a64-58494421ee68" config-ref="Azure_Storage_Config">
<azure-storage:file fileName="outputFile" shareName="dev" path="C:\Users\jespe\outputFile" />
</azure-storage:upload-file-in-root-directory>
<file:delete doc:name="Delete" doc:id="852758e7-94e6-43e2-9421-285f1bb85f26" path="C:\Users\jespe\outputFile" />
</flow>
</mule>
Removed the logger before Upload file with stream. Debugger still shows the payload like that after the transform.
Edit 2:
The answer by #jan-h was indeed the solution. Setting deferred=true in the Transform Message doesn't work for me though. Had to set in the File Upload with Stream.

juast add deferred=true to the last dataweave.
Like this : output application/xml deferred=true

It looks like the last DataWeave transformation returned a non repeatable stream, so it was consumed in the logger. Try removing the last logger to see if the payload appears.
It would be better if you shared the XML of the flow. It is not possible to understand what it is doing from the screenshots alone.

Related

Mule 4 - How to do error handling inside a cache scope?

I'm using cache scope and object store to cache data returned from a Salesforce Query using Salesforce Connector.
I've added On error continue to catch any Salesforce Connector exceptions.
If there is an exception in Salesforce Connector (like Salesforce Connectivity), the application throws an exception and executes On error continue block, but when it is called again application hangs at the cache scope and doesn't give any response/error message. Also, On error continue block is executed thrice when the application is executed first time.
It's running fine in debug mode.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:os="http://www.mulesoft.org/schema/mule/os" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:salesforce="http://www.mulesoft.org/schema/mule/salesforce"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/salesforce http://www.mulesoft.org/schema/mule/salesforce/current/mule-salesforce.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/os http://www.mulesoft.org/schema/mule/os/current/mule-os.xsd">
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="6a5b02b3-836d-43b5-9dbe-41719d20258f" >
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<salesforce:sfdc-config name="Salesforce_Config" doc:name="Salesforce Config" doc:id="3facafa3-5d07-4717-901a-487f0cdeabb2" >
<salesforce:basic-connection username="..." password="..." securityToken="..." url="https://login.salesforce.com/services/Soap/u/48.0" />
</salesforce:sfdc-config>
<ee:object-store-caching-strategy name="Caching_Strategy" doc:name="Caching Strategy" doc:id="4ebcc02a-3c51-445b-bee5-0c95e4ce6e01" keyGenerationExpression="#['1']" >
<os:private-object-store persistent="false" maxEntries="1" entryTtl="1" />
</ee:object-store-caching-strategy>
<flow name="test-errorFlow" doc:id="49520788-7379-45cb-9276-cdb6b268398c" >
<http:listener doc:name="Listener" doc:id="ce5faf93-3153-4f93-8313-90d465f920c6" config-ref="HTTP_Listener_config" path="/test" allowedMethods="GET">
<http:response statusCode="#[vars.httpStatus]" />
<http:error-response statusCode="#[vars.httpStatus]" >
<http:body ><![CDATA[#[error]]]></http:body>
</http:error-response>
</http:listener>
<ee:cache doc:name="Cache" doc:id="ae4e7d76-0f98-4202-9a51-59373ea3ee1c" cachingStrategy-ref="Caching_Strategy">
<salesforce:query doc:name="Query" doc:id="1498398a-7b1f-4a27-aff8-3991d4e9cbca" config-ref="Salesforce_Config">
<salesforce:salesforce-query><![CDATA[Select Id, Name from Account]]></salesforce:salesforce-query>
</salesforce:query>
</ee:cache>
<ee:transform doc:name="Transform Message" doc:id="f864be76-86a9-4726-b1f1-586ffeabb0db" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
</ee:message>
</ee:transform>
<error-handler >
<on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="038cd795-2174-4d9a-b759-2921dd12a64e" type="ANY">
<logger level="INFO" doc:name="Logger" doc:id="186587c2-0beb-416a-b589-7239a2cba7dd" message="#[error]"/>
</on-error-continue>
</error-handler>
</flow>
</mule>
'On error continue' means to finish flow even if error occurs. But finishing flow does not mean that it did its job - in particular cache value was not obtained. That's the reason the erst is failing.
Rearrange your flow - if cache value is null - run cache again and again ( for example https://docs.mulesoft.com/mule-runtime/4.3/until-successful-scope ) and only success continue your regular flow with existing real cache value.
The problem is likely that there is nothing to cache, because the error aborted the execution.
You can either use a Try scope to handle the error inside the Cache scope, or call to another flow with a flow-ref, and handle the error inside that other flow.
Example:
<ee:cache doc:name="Cache" cachingStrategy-ref="Caching_Strategy">
<try>
<salesforce:query doc:name="Query" config-ref="Salesforce_Config">
<salesforce:salesforce-query><![CDATA[Select Id, Name from Account]]></salesforce:salesforce-query>
</salesforce:query>
<error-handler>
<on-error-continue>
....
</on-error-continue>
</error-handler>
</try>
</ee:cache>

Need Help for interpretation of Error Handling Scenario for Mulesoft

My Mulesoft POC contains globalErrorHandler as well as localErrorHandler having OnErrorContinue scope, I noticed yet it throws a MULE:EXPRESSION error ,Can anyone let me know the reason for it . The code is below enclosed with the pic of the flow .
Code
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="f8f3f4bb-341a-43ec-acf8-9ed33419f5ef" basePath="/error" >
<http:listener-connection host="0.0.0.0" port="8082" />
</http:listener-config>
<configuration doc:name="Configuration" doc:id="689a9085-287e-43e4-8e3d-5eeac857dc64" defaultErrorHandler-ref="globalError_Handler"/>
<flow name="example-errorFlow" doc:id="c37abd41-2143-4da1-848a-a8c240853b60" >
<http:listener doc:name="Listener" doc:id="9cda3f2d-a48d-40bd-96a4-54d856d0438e" config-ref="HTTP_Listener_config" path="/"/>
<set-payload value='"MAIN"' doc:name="Set Payload" doc:id="a1b3890f-6157-4716-84d3-8f6ccd6e9af5" />
<ee:transform doc:name="Transform Message" doc:id="9fc2571b-7038-4359-82db-be624d48b343" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
["RESPONSE"] ++ payload ]]></ee:set-payload>
</ee:message>
</ee:transform>
<error-handler >
<on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" type= "HTTP:NOT_FOUND" doc:id="e6f2b028-e3ca-4eff-b878-0f41dd53d693" >
<set-payload value='"HTTP:NOT_FOUND"' doc:name='"HTTP:NOT_FOUND"' doc:id="c465edf3-bbac-4fca-bfb1-f2a6678e1173" />
</on-error-continue>
</error-handler>
</flow>
<error-handler name="globalError_Handler" doc:id="05e153b7-d663-4aa1-85c0-8fefbf76c39b" >
<on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="c0e80820-db0f-4b3f-b0e2-c74c47e3a5e7" >
<set-payload value="global Error Handler" doc:name="global Error Handler" doc:id="0055b184-4dd6-4d20-8284-27534570f723" />
</on-error-continue>
</error-handler>
</mule>
FlowImage
The error is coming from your Transform component but you are handling only HTTP:NOT FOUND error.
Handle all exceptions as described here
https://simpleflatservice.com/mule4/OnErrorContinue.html
In particular - simple remove error type and you will see actual message and can fix it.
Post it here and we can help.
In the transform you're trying to use ++ function with an Array and String which is incorrect (in your case its ["RESPONSE"] ++ payload where payload = "MAIN"), coming to flow error handling you're handling a specific error from HTTP namespace, whereas the error you get is from MULE namespace of type EXPRESSION, so thats the reason the local error handler is unable to handle that error.
To handle this either use MULE:EXPRESSION or MULE:ANY which can serve as a parent error type for MULE:EXPRSSION and HTTP:NOT_FOUND errors
The MULE namespace is an implicit namespace you can also call it as a parent namespace which can handle any runtime based error.
To better understand errors, their hierarchy and global error handler consider visiting the resource mentioned below.
https://youtu.be/9WcG9teCrvo

mule : Scatter Gather : How to aggregate variables from different routes if we are setting a target variable in the Scatter gather component?

Using Mule 4, Scatter Gather component, I set the target variable as "result".
I have two more variables
firstVar : Defined outside the Scatter Gather component but updated inside one route
secondVariable : Defined inside the Scatter Gather component.
When I run the code, I expect to see firstVar (updated), secondVariable and result in the vars when Scatter Gather is finished.
But I see only firstVar with the initial value.
Observation: If i remove the target variable result, I see the firstVar (updated), secondVariable and the aggregated payload as well.
Can someone please explain what am I doing wrong?
Code for reference:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<flow name="ScatterGather-ExampleFlow"
doc:id="5dec6c32-4da7-4be0-91e1-26744e6e4761">
<http:listener doc:name="Listener"
doc:id="a75d1ddb-0481-45be-992d-39e397160257"
config-ref="HTTP_Listener_config" path="/api/scattergather" />
<logger level="INFO" doc:name="Logger"
doc:id="9bb44a1f-287f-415c-b19f-87798797cfa8"
message="Starting Scatter Gather Sample" />
<set-variable value='#["First Value"]'
doc:name="First Variable"
doc:id="1eb7430b-f6a8-4366-8594-8f76479148ab" variableName="firstVar" />
<scatter-gather doc:name="Scatter-Gather"
doc:id="ef921649-8269-46ba-b38e-8e55f2694368" target="result">
<route>
<ee:transform doc:name="Transform Message"
doc:id="c5b2717c-5917-4641-aa4c-2283614cc4af">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0 output application/java
--- payload]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="firstVar"><![CDATA[%dw 2.0 output application/java ---
"updated First Value"]]></ee:set-variable>
</ee:variables>
</ee:transform>
<set-payload value='#["First route PAyload"]'
doc:name="Set Payload"
doc:id="8c479443-dd94-410e-9346-fedb7c0d3d71" />
</route>
<route>
<set-variable value='"secondValue"'
doc:name="SecondVariable"
doc:id="6f78c3a7-ae00-4693-93ca-da98217d36d4"
variableName="secondVariable" />
<set-payload value='#["2nd routePayload"]'
doc:name="Set Payload"
doc:id="aad2f059-2a35-4c29-85d7-45e33f317e59" />
</route>
</scatter-gather>
<logger level="INFO" doc:name="Logger"
doc:id="d03caeac-41e3-4dc9-8b67-de1da841011c" message="#[vars]" />
</flow>
</mule>
Without the target variable, after all processing routes have finished execution, the Scatter-Gather component creates a new Mule event that combines all resulting Mule events from each route, and then passes the new Mule event to the next component in the flow.
If Scatter Gather ->General->target is used then it populates the resultant payload (multiple mule events ) into a new target variable and the original mule event and its vars are maintained.
I guess it is related to the event being discarded by the assignment to the target variable. That is probably to be expected. The event contains both the message/payload and the variables. Using target only assigns the resulting payload to the variable. The rest of the modified event is lost.
I would recommend to use a payload that stores all the needed data as additional attributes. You can later use DataWeave to extract the attributes from the rest of the payload.

How to read file in middle of the flow

I am trying to read two simultaneously file in middle of the flow and combine them into one payload. To reading the files in middle of the flow I am using mule requester component. While triggering the flow (localhost:8081/requester/requester)I am getting error :
"Exception(s) were found for route(s):
0: The endpoint "src\main\resources\input1\employees.xml" is malformed and cannot be parsed. If this is the name of a global endpoint, check the name is correct, that the endpoint exists, and that you are using the correct configuration (eg the "ref" attribute). Note that names on inbound and outbound endpoints cannot be used to send or receive messages; use a named global endpoint instead. (org.mule.api.endpoint.MalformedEndpointException).
1: The endpoint "src\main\resources\input2\employees2.xml" is malformed and cannot be parsed. If this is the name of a global endpoint, check the name is correct, that the endpoint exists, and that you are using the correct configuration (eg the "ref" attribute). Note that names on inbound and outbound endpoints cannot be used to send or receive messages; use a named global endpoint instead. (org.mule.api.endpoint.MalformedEndpointException)."
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:mulerequester="http://www.mulesoft.org/schema/mule/mulerequester" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/mulerequester http://www.mulesoft.org/schema/mule/mulerequester/current/mule-mulerequester.xsd http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<file:connector name="file-connector-config" autoDelete="false" streaming="true" validateConnections="true" doc:name="File" />
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" basePath="/requester" doc:name="HTTP Listener Configuration" />
<flow name="muleRequester">
<http:listener config-ref="HTTP_Listener_Configuration" path="/requester" doc:name="HTTP" />
<logger message="Invoking Mule Requester" level="INFO" doc:name="Logger" />
<scatter-gather doc:name="Scatter-Gather">
<mulerequester:request resource="src\main\resources\input1\employees.xml" returnClass="java.lang.String" doc:name="Retrieve File1"/>
<mulerequester:request resource="src\main\resources\input2\employees2.xml" returnClass="java.lang.String" doc:name="Retrieve File2"/>
</scatter-gather><dw:transform-message doc:name="Transform Message">
<dw:set-payload>< [CDATA[%dw 1.0 %output application/json
---
{
payload1: payload[0],
payload2: payload[1]
}]]></dw:set-payload>
</dw:transform-message>
<file:outbound-endpoint path="src/main/resources/output" responseTimeout="10000" doc:name="File"/>
<logger message="Payload after file requester #[payload]" level="INFO" doc:name="Logger" />
</flow>
I am not using maven. Do I need to download any other jar or where I can do the correction?
resource needs to be an Mule endpoint url. Mule requester module can work with many transports such as jms, file, ftp. So the path to the file is not enough. Here is an example of an endpoint url for reading a file:
<mulerequester:request resource="file://src/main/resources/in/ReadME.txt?connector=file-connector-config" doc:name="Retrieve File" returnClass="java.lang.String" />
You can also point to a global endpoint like you have defined like so:
<mulerequester:request config-ref="muleRequesterConfig" resource="myFileEndpoint" doc:name="Mule Requester" />

Overload error in Mulesoft workflow when transforming Excel file from an AWS S3 bucket

I am using Mule 4 and Anypoint Studio 7.
I looking to get a list of objects from an AWS S3 bucket, read each xlsx file and transform the message so it is has some new column names.
When I do this I get an error:
Unable to call any overload of function `Value Selector` with arguments (Binary, "Sheet 1") overloads
How can I resolve this error?
Excel File in S3 Bucket:
Workflow:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:s3="http://www.mulesoft.org/schema/mule/s3"
xmlns:sftp="http://www.mulesoft.org/schema/mule/sftp"
xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/sftp http://www.mulesoft.org/schema/mule/sftp/current/mule-sftp.xsd
http://www.mulesoft.org/schema/mule/s3 http://www.mulesoft.org/schema/mule/s3/current/mule-s3.xsd">
<flow name="aws-flow" doc:id="21bd363a-166e-4fc2-9246-dd6f48763db7" >
<scheduler doc:name="Scheduler" doc:id="4e3bf7a7-99ce-44e3-b732-fece4200c5b6" >
<scheduling-strategy >
<fixed-frequency frequency="10000000"/>
</scheduling-strategy>
</scheduler>
<s3:list-objects doc:name="List objects AWS S3 bucket" doc:id="640ed7a3-2e0f-4c5d-99a1-fd503d02f055" config-ref="Amazon_S3_Configuration" bucketName="${aws.s3.bucket.name}"/>
<foreach doc:name="For Each" doc:id="f0989986-2d2e-4cc9-b51e-d61cf9d01210" >
<choice doc:name="Choice" doc:id="9f47cc0e-d784-4dcb-83a6-07e553997aab" >
<when expression='#[payload.key endsWith ".xlsx"]'>
<s3:get-object doc:name="Get object from AWS S3" doc:id="568ed3c4-d7f8-4657-a515-835e5671b72c" config-ref="Amazon_S3_Configuration" bucketName="#[payload.bucketName]" key="#[payload.key]" />
<ee:transform doc:name="Transform Message" doc:id="966cf917-d50d-4858-8e26-9f381bc57de4">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/xlsx
---
{
"Sheet 1": payload[0] map ( sheet1 , indexOfSheet1 ) -> {
EmployeeId: sheet1.EmployeeId default "" as String,
Name: sheet1.Name default "" as String,
}
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Log Payload" doc:id="f3738738-d56d-4930-94f8-763aea3b5dbe" message='#[payload]'/>
</when>
<otherwise >
<logger level="INFO" doc:name="Log File Invalid" doc:id="e3f5c9c2-0b75-4b1c-88dc-cb1ae1e2f249" message="Invalid file"/>
</otherwise>
</choice>
</foreach>
</flow>
</mule>
the problem is that the S3 connector is not setting the mime type to "application/xlsx" so DW instead of parsing it as a ExcelFile it takes it as Binary content.
There is a simple solution
after
<s3:get-object doc:name="Get object from AWS S3" doc:id="568ed3c4-d7f8-4657-a515-835e5671b72c" config-ref="Amazon_S3_Configuration" bucketName="#[payload.bucketName]" key="#[payload.key]" />
add
<set-payload value="#[payload]" mimeType="application/xlsx"/>