基于内容的文件随Mule移动

时间:2011-11-28 06:00:44

标签: file ftp esb mule

我的mule配置文件包含以下流程:

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

我能够移动文件,但我需要的是读出文件内容并根据该内容将其放在特定目录中。

例如,如果我的文件内容有“Vendor1”,那么它应该将文件放在Vendor1下。仅供参考:Vendor1不是静态的。它可能是Vendor1000。关于这个的任何想法?

1 个答案:

答案 0 :(得分:1)

您想要做的是:

  • 使用转换器从文件中提取所需的值(不是表达式,因为没有一个支持您的特定文件格式),
  • 在出站端点的路径属性中使用此属性。

类似的东西:

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