How to pass java.io.File from Mule 3 inbound file endpoint - mule

Using Mule 3, how can I pass a java.io.File object payload from an inbound file endpoint to a Groovy script rather than the file's content?

You need to turn streaming off and override the default message factory on the file connector:
<file:connector name="fileConnector" streaming="false" autoDelete="false">
<service-overrides messageFactory="org.mule.transport.file.FileMuleMessageFactory" />
</file:connector>
Note that it is up to you to move / delete the file either before you start or once you've done processing it, otherwise Mule will poll it again and again.

Related

How do you "accept" a file upload in Mule 3.8? (Not deprecated)

How does one upload a file using an API in Mule 3.8? Can someone provide an example for a multipart/form-field POST using an example log file? Here's an old way but the connector is deprecated.
<http:connector name="httpConnector" doc:name="HTTP\HTTPS">
<service-overrides
messageFactory="org.mule.transport.http.HttpMultipartMuleMessageFactory" />
</http:connector>
I'm testing a process API that creates an import and then "will" call another service to upload itself. I'm modeling my own file upload using Mule and I can't seem to get anything to work. I have a Spring Boot servlet that uses Apache Commons Upload but I would prefer to have my upload prototype in Mule with my real projects until our Mule servers are installed.

How to attach file in Munit for functional test cases- Mule ESB

I need to do end to end (Functional Testing)testing via Munit. For that, I need to attach actual payload which is Image. How can I attach the image in Inbound message processor( Munit - Set Message, there is no option for attachment) or any other way we can achieve this.
<flow name="TestImage">
<file:inbound-endpoint path="tmp\imageUpload" responseTimeout="10000" doc:name="ImageFlow" connector-ref="fileConn" fileAge="100" pollingFrequency="500"></file:inbound-endpoint>
............. many processor..... Logic involved...
<file:outbound-endpoint path="tmp\Upload" responseTimeout="10000" doc:name="Flow" connector-ref="fileConn" fileAge="100" pollingFrequency="500"></file:outbound-endpoint>
Mule Studio Version: 5.3.1
The file inbound endpoint will by default return a input stream as payload with the content of the file you want to read.
Now MUnit disable inbound endpoints by default so to test this flow you'll have to do a flow-ref to your flow "TestImage".
In this case you can use the set message processor and load the test file you want to use in the following way:
<munit:set payload="#[getResource('test_image.jpeg').asStream()]" doc:name="Set Message"/>
This'll create a message with a payload that's an input stream for your image.
HTH.

File endpoint in MULE

How to use Move to Pattern & File Age property of File EndPoint in MULE.
I tried to give moveToPattern="#[function:datestamp]-#[message.inboundProperties['originalFilename']]" but it is not working as expected.
For File Age, I provided 50000. According to my understanding, if the last modified date of the file is 22.01.2015:20:07:20, then the file should be moved from this folder to another folder at 22.01.2015:20:12:20. But it is not happening. Please explain by giving an example.
What is the difference between connector reference & endpoint reference.
The 'file age' property defines the time a file must wait before it's processed. Once it's processed, it is going to move to the directory specified in the 'moveToDirectory'.
The file connector is a global connector where you can specify some properties that can be applied to all of your file endpoint configuration.
<file:connector name="File" autoDelete="true"
outputAppend="true" streaming="true" validateConnections="true"
doc:name="File" />
A file endpoint is a generic endpoint that can be referred from all your endpoints. For example, you have different endpoints with the same configuration, thus you can specify all the properties on a global endpoint, so when you need to change something, you only change the global one.
<file:endpoint name="fileEndpoint"
path="${file.path}" outputPattern="${file.outputPattern}" moveToDirectory="${file.moveToDir}"
connector-ref="File" doc:name="File" fileAge="5000"/>
The file inbound/outbound endpoints can then refer the global endpoints.
<file:outbound-endpoint responseTimeout="10000"
ref="fileEndpoint" doc:name="File - Log" />
The documentation for fileAge in the file transport reference is:
Setting this value (minimum age in milliseconds for a file to be processed) is useful when consuming large files, as Mule waits before reading this file until the file last modification timestamp indicates that the file is older than this value
In your case 50000 milliseconds would be 50 seconds, thus a file dropped at 22.01.2015:20:07:20 should be picked as soon as 22.01.2015:20:08:10.
Since it is not happening, there must be something wrong in your configuration. Please share your file transport configuration (if any) and your full endpoint configuration.

how to make file endpoint in mule configerable

I have a flow with file endpoint and groovy.
I want to make the file path configerable.
Please suggest.
I am using file node to trigger the flow. So if anybody can suggest me that how to trigger groovy alone then there will be no need to use file endpoint.
Please suggest any solution.
What you want to do here is configure a file endpoint like so and use this as your inbound endpoint to trigger the flow:
<file:endpoint name="inputFile" path="${input.path}">
<!-- Add any filters (e.g. regex) here -->
</file:endpoint>
Then, you should create a mule-app.properties file inside of src/main/resources that will include something like the following:
# Input Properties
input.path=/path/to/file
Lastly, include the following at the top of your Mule config file (after <mule> but before your flow):
<spring:beans>
<context:property-placeholder location="classpath:mule-app.properties" />
</spring:beans>
Doing this should allow you to achieve what you've outlined above. Hope this helps!

Does Mule have the ability to simply move/rename a file?

Is there a way to simply "move/rename" a file in Mule as opposed to a copy? The flow below performs a copy, but what I really want is to simply rename the file. The file can be quite large.
<file:connector name="Global-StageToInput" fileAge="10000" autoDelete="true" pollingFrequency="30000"/>
<file:connector name="Global-FileInput" outputPattern="#[header:originalFilename]" />
<flow name="Global-MoveInputFiles">
<file:inbound-endpoint connector-ref="Global-StageToInput" path="${stage}"/>
<file:outbound-endpoint connector-ref="Global-FileInput" path="${input}"/>
</flow>
When you want to move a file from one directory to another the file aparently vanishes from the directory you are moving .
Back up of this file can be taken using the moveToDirectory in Inbound endpoint
In order to rename the backup file you can use moveToPattern in Inbound endpoint
In order to rename in the destination you can use outputPattern in Outbound endpoint
You can use the following links to have more ideas
<file:inbound-endpoint connector-ref="input" path="/tmp/input" moveToDirectory="/tmp/backup" moveToPattern="#[header:originalFilename].backup"/>
<file:outbound-endpoint connector-ref="output" path="/tmp/output" outputPattern="#[function:datestamp]-#[header:originalFilename]"/>
http://www.mulesoft.org/documentation/display/current/File+Transport+Reference
http://www.mulesoft.org/documentation-3.2/display/32X/File+Transport+Reference
http://www.mulesoft.org/connectors/file-connector
If you need only to move a file from a folder to another where you need to rename the file name.
Then use the following code
<file:inbound-endpoint connector-ref="input" path="/tmp/input"/>
<file:outbound-endpoint connector-ref="output" path="/tmp/output" outputPattern="#[function:datestamp]-#[header:originalFilename]"/>
Just only the pattern in the outbound endpoint.
Only the path in the input and output is required .Rest all is not necessary and with mix and match of the option that is there links can be used. Even the connector-ref is not required for a basic requirement