从AWS S3存储桶转换Excel文件时,Mulesoft工作流程中出现过载错误

时间:2019-01-30 14:17:34

标签: mule anypoint-studio dataweave mule-esb

我正在使用Mule 4和Anypoint Studio 7。

我希望从AWS S3存储桶中获取对象列表,读取每个xlsx文件并转换消息,使其具有一些新的列名。

执行此操作时出现错误:

Unable to call any overload of function `Value Selector` with arguments (Binary, "Sheet 1") overloads

如何解决此错误?

S3存储桶中的Excel文件:

enter image description here

工作流程:

<?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>

1 个答案:

答案 0 :(得分:1)

问题是S3连接器未将mime类型设置为“ application / xlsx”,因此DW而不是将其解析为ExcelFile而是将其作为二进制内容。

有一个简单的解决方案

之后

<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]" />

添加

<set-payload value="#[payload]" mimeType="application/xlsx"/>