Content based file moving with Mule

我是研究僧i 提交于 2019-12-24 01:24:12

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/8292038/content-based-file-moving-with-mule

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!