Content based file moving with Mule

2019-07-10 11:04发布

My mule config file contains the below flow:

<flow name="HTTP input1">
  <ftp:inbound-endpoint user="username" password="secret" host="host" path="location" port="21">
    <file:filename-wildcard-filter pattern="." />
  </ftp:inbound-endpoint>
  <file:outbound-endpoint path="E:/Mule/Inbound" outputPattern="#[header:originalFilename]" >
  </file:outbound-endpoint>
</flow>

I'm able to move the files but what I need is to read out the file content and based on that content place it in specific directory.

For example if my file content has "Vendor1" then it should place the file under Vendor1. FYI: Vendor1 is not static. It may Vendor1000. Any ideas on this?

标签: file ftp esb mule
1条回答
ゆ 、 Hurt°
2楼-- · 2019-07-10 11:50

What you want to do is:

  • Extract the desired value from the file using a transformer (not an expression because none support your specific file format),
  • Use this property in the path attribute of the outbound endpoint.

Something like:

<flow name="HTTP input1">
  <ftp:inbound-endpoint user="username"
                        password="secret"
                        host="host"
                        path="location"
                        port="21">
    <file:filename-wildcard-filter pattern="." />
  </ftp:inbound-endpoint>
  <script:transformer name="stringReplaceWithParams">
    <script:script engine="groovy">
        <script:text>
          // here the payload variable should contain a byte[] from the remote FTP file
          // ... munch-munch the byte[] with Groovy to find the value to put in targetSubDir
          var targetSubDir = ...

          message.setOuboundProperty('targetSubDir', targetSubDir) 
          // return the payload unchanged, we just changed a message property
          return payload 
        </script:text>
    </script:script>
  </script:transformer>
  <file:outbound-endpoint path="E:/Mule/Inbound/#[header:targetSubDir]"
                          outputPattern="#[header:originalFilename]" />
</flow>
查看更多
登录 后发表回答