Is there an easy way to configure a Flow to read a single file from the classpath one time? I don't need to poll for a file. I just need to read a known file and set its contents as the message payload.
Mule supports reading files at the beginning of a flow and we can use the File Connector to do this as well, but this connector is not suitable for loading the content of a file in the middle of a flow. Sometimes, though, you need to read a file during a flow.
You have to process files on a strict schedule, not as soon as they arrive. You have to read the file name from the DB and then you have to start processing. You need to retry file processing from the beginning of the file. To achieve this goal we need to use the mule-module-requester.
This allows you to get data in the middle of your flow from endpoints that can usually only start a flow (like a file receiver). The intention of this post is to describe, step-by-step, how to install and use the Mule module requester. We will see a working example of this as well.
When I run my application from MuleStudio and dump the java.class.path the /classes directory within the app is included. When I run it on my Linux server it is not. This is causing problems with my application accessing my resource files.
Use the set-payload
message processor and a MEL expression:
<set-payload value="#[Thread.currentThread().getContextClassLoader().getResourceAsStream('my-file.abc')]" />
For some reason I cannot make the solution proposed by David Dossot to work. I was inspired by this answer and came up with another solution
<spring:bean id="myResource" class="org.apache.commons.io.IOUtils" factory-method="toString">
<spring:constructor-arg value="classpath:path/to/myResource.txt" type="java.io.InputStream"/>
</spring:bean>
and then you can use set-payload in the following way
<set-payload value="#[app.registry.myResource]" doc:name="Set Payload"/>
which will result in setting the payload with the content of the file as a String.
This method has the advantage that the content of the resource file is loaded only once into a bean of type String. So if your set-payload statement is executed frequently, this could improve performance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With