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