2016-03-03 19 views
2

我有一个电子邮件文件场景。该电子邮件包含多个附件,我需要逐一处理它们以传递给另一个流程,并且我需要原始文件名。我可以在每个作用域之前获取附件名称,但我无法将其作为目标文件的文件名。任何帮助或建议将真正赞赏。你可以在mulesoft上获得每个语句的附件文件名吗?

<?xml version="1.0" encoding="UTF-8"?> 

<mule xmlns:batch="http://www.mulesoft.org/schema/mule/batch" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:pop3="http://www.mulesoft.org/schema/mule/pop3" 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.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/pop3 http://www.mulesoft.org/schema/mule/pop3/current/mule-pop3.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/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd 
http://www.mulesoft.org/schema/mule/batch http://www.mulesoft.org/schema/mule/batch/current/mule-batch.xsd"> 
    <file:connector name="File" autoDelete="true" streaming="true" validateConnections="true" doc:name="File"/> 
    <flow name="Knauf_Load_List"> 
     <pop3:inbound-endpoint host="mailhost" user="exampleuser" password="examplepass" responseTimeout="10000" doc:name="Poll Email PDF"/> 
     <set-session-variable variableName="State" value="#[message.inboundProperties.To]" doc:name="Session Variable"/> 
     <set-variable variableName="filename()" value="#[message.inboundAttachments.keySet()]" doc:name="Variable"/> 
     <expression-transformer doc:name="Expression"> 
      <return-argument evaluator="attachments-list" expression="*.pdf"/> 
     </expression-transformer> 
     <foreach doc:name="For Each"> 
      <set-payload value="#[payload.getContent()]" doc:name="Set Payload"/> 
      <logger message="#[flowVars.filename]" level="INFO" doc:name="Logger"/> 
      <file:outbound-endpoint path="\\HO-AWH-OCRPROD1\CustomerOrders\Knauff" outputPattern="Knauf_Bunnings_Orders-#[message.id].pdf" connector-ref="File" responseTimeout="10000" doc:name="File"/> 
      <set-session-variable variableName="PDF" value="#[flowVars.counter]" doc:name="Session Variable"/> 
     </foreach> 
     <logger message="#[sessionVars.PDF] for #[sessionVars.State]" level="INFO" doc:name="Logger"/> 
    </flow> 
    <flow name="ocr_app_test_edi_flow"> 
     <file:inbound-endpoint path="\\HO-AWH-OCRPROD1\Output\Knauff\EDIEnterprise" moveToPattern="OCR_Archive-#[server.dateTime.format('dd-MM-yy_HH-mm-ss')].xml" moveToDirectory="S:\AWHMan\IT\IT Middleware Project\Ocr To EDI Archive" responseTimeout="10000" doc:name="File" connector-ref="File"/> 
     <file:file-to-string-transformer doc:name="File to String"/> 
     <set-variable variableName="order" value="#[xpath3('/Payload/WhsDockets/WhsDocket/Reference')]" doc:name="Variable"/> 
     <logger level="INFO" doc:name="Logger"/> 
     <file:outbound-endpoint path="\\HO-AWH-FS6\ediEnterprise Import Files" outputPattern="Knauf-#[flowVars.order].xml" connector-ref="File" responseTimeout="10000" doc:name="File"/> 
    </flow> 
</mule> 
+2

你能更好地指出你的问题吗?如果你可以在foreach之前得到它,这意味着你可以存储它们,为什么你不能使用它? –

+0

嗨,毛罗,我需要分配相同的文件名输出一个文件,同时处理它并行数据库。 –

回答

0

好,

不知道这是否会成为,但我已经实现了下面的代码为IMAP帐户:

<choice doc:name="Choice between mail with and without attachments"> 
     <when expression="#[message.dataType.mimeType == &quot;multipart/alternative&quot;]"> 
      <set-variable variableName="hasAttachment" value="false" doc:name="Set hasAttachment"/> 
      <set-payload value="#[message.inboundAttachments['0'].getContent()]" doc:name="Set Payload from Body"></set-payload> 
      <set-variable variableName="fileName" value="" doc:name="Set fileName"/> 
     </when> 
     <when expression="#[message.dataType.mimeType == &quot;multipart/mixed&quot;]"> 
      <set-variable variableName="hasAttachment" value="true" doc:name="Set hasAttachment"/> 
      <expression-transformer doc:name="Set Payload from Attachments"> 
       <return-argument evaluator="attachments" expression="*.*"/> 
      </expression-transformer> 
      <set-variable variableName="fileName" value="#[payload.keySet().iterator().next()]" doc:name="Set fileName"/> 
      <set-payload value="#[payload[flowVars.fileName].getContent()]" doc:name="Set Payload from firts Attachment content"></set-payload> 
      <object-to-byte-array-transformer doc:name="Object to Byte Array"></object-to-byte-array-transformer> 
     </when> 
     <when expression="#[message.dataType.mimeType == &quot;text/plain&quot;]"> 
      <set-variable variableName="hasAttachment" value="false" doc:name="Set hasAttachment"/> 
      <set-payload value="#[payload.getContent()]" doc:name="Set Payload from Text"/> 
      <set-variable variableName="fileName" value="" doc:name="Set fileName"/> 
     </when> 
     <otherwise> 
      <logger message="La informaci&#243;n del EMail no es v&#225;lida" level="INFO" doc:name="Logger"/> 
     </otherwise> 
    </choice> 

正如你可以在在“#[见message.dataType.mimeType == " multipart/mixed "]“,检索所有附件,在我的情况下,其中第一个附件的迭代器的第一个值为:

#[payload.keySet().iterator().next()] 

使用此名称,您可以直接访问此附件的内容,或者您​​可以使用相应的密钥访问它们。

问候。

0

使用#[键],这会给foreach语句中的文件名。 我正在使用3.8版本

相关问题