Mule ESB:读取二进制文件并在Salesforce

时间:2016-03-11 22:43:17

标签: mule mule-studio

我正在使用Mule ESB开发集成,需要从文件系统中读取二进制文件(.zip)并将其作为Salesforce中的附件创建。但是,我无法完成这项工作,而且我收到以下错误:

INFO  2016-03-11 13:55:47,338 [[sfdc].File.receiver.01]       org.mule.transport.file.FileMessageReceiver: Lock obtained on file: /Users/aaa/Desktop/temp/files/test.zip
INFO  2016-03-11 13:55:47,345 [[sfdc].sfdcFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: Payload = org.mule.transport.file.ReceiverFileInputStream@4f0870aa
INFO  2016-03-11 13:55:47,348 [[sfdc].sfdcFlow.stage1.02] com.mulesoft.weave.mule.utils.MuleWeaveFactory$: MimeType was not resolved 'application/zip' delegating to Java.
ERROR 2016-03-11 13:55:47,367 [[sfdc].sfdcFlow.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy: 
Message               : Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*', encoding='null'}" to "CollectionDataType{type=java.util.List, itemType=java.lang.Object, mimeType='*/*'}".
Type                  : org.mule.api.transformer.TransformerException
Code                  : MULE_ERROR-236
JavaDoc               : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html
Exception stack is:
1. Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*', encoding='null'}" to "CollectionDataType{type=java.util.List, itemType=java.lang.Object, mimeType='*/*'}". (org.mule.api.transformer.TransformerException)
 org.mule.registry.MuleRegistryHelper:248 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
Root Exception stack trace:
org.mule.api.transformer.TransformerException: Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*', encoding='null'}" to "CollectionDataType{type=java.util.List, itemType=java.lang.Object, mimeType='*/*'}".

这是配置文件。

<sfdc:config name="Salesforce__Basic_Authentication" username="test@test.com.staging" password="password" securityToken="token" url="https://test.salesforce.com/services/Soap/u/34.0" doc:name="Salesforce: Basic Authentication"/>
<file:connector name="File" readFromDirectory="/Users/aaa/Desktop/temp/files" autoDelete="true" streaming="true" validateConnections="true" doc:name="File"/>
<flow name="sfdcFlow">
    <file:inbound-endpoint path="/Users/aaa/Desktop/temp/files" connector-ref="File" responseTimeout="10000" doc:name="File"/>
    <logger message="Payload = #[payload]" level="INFO" doc:name="Logger"/>
    <object-to-byte-array-transformer doc:name="Object to Byte Array"/>
    <dw:transform-message doc:name="Transform Message">
        <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
ParentId: "b2U7A0B01054OyZ",
Name: "Test Name",
Description: "Test Descr",
Body: payload
}]]></dw:set-payload>
    </dw:transform-message>

    <sfdc:create config-ref="Salesforce__Basic_Authentication" type="Attachment" doc:name="Salesforce" />
</flow>

我检查了Anypoint交换并用Google搜索,但我得到的所有指针都面向文本文件(如CSV)。感谢是否有人可以共享一个工作示例来读取二进制文件并将其创建为Salesforce中的附件(可以附加到任何对象,如case对象)。

我使用Anypoint Studio 5.4.1和Mule运行时3.7.3 EE。

编辑:我能够解决问题。基本上,正如@david所说,create方法需要一个集合,而我并没有将它作为集合传递。这是更新的代码(只是数据编辑部分):

[
  {
    ParentId: "b2U7AB010540yZ",
    Name: "Test Name",
    Description: "Test Descr",
    Body: payload
  }
]

注意打开和关闭方括号。谢谢@david。

1 个答案:

答案 0 :(得分:1)

我从SFDC Connector文档中了解到,create method需要一组对象。

但是你传递map给它,因此这个例外:

Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*', encoding='null'}" to "CollectionDataType{type=java.util.List, itemType=java.lang.Object, mimeType='*/*'}"

尝试使用变换器将您在dw:transform-message中创建的地图添加到列表中,它应该可以正常工作。