I tried to create a Data-Mapper example in mule in which both inbound and outbound endpoints are File, Looks some thing like.
When i execute this program output folder of file remains empty, Logically i assume that i need to put and HashMap to XML transformer between Data Mapper and Output File. More Over i created a csv file to xml file selecting from example option in data mapper.
Initially i tried to use FTP endpoint it started resulting into error so i replaced FTP with file endpoint.
Here I am Sharing configuration.xml file
<mule xmlns:file="....>
<data-mapper:config name="sample_mapper_grf" transformationGraphPath="sample_mapper.grf" doc:name="DataMapper"/>
<flow name="CSV_to_XML_Data_MapperFlow1" doc:name="CSV_to_XML_Data_MapperFlow1">
<file:inbound-endpoint path="/home/jay/CSV_XML_/input" responseTimeout="10000" doc:name="Input File"/>
<data-mapper:transform config-ref="sample_mapper_grf" doc:name="DataMapper"/>
<file:outbound-endpoint path="/home/jay/CSV_XML_/output/" responseTimeout="10000" doc:name="Output File"/>
</flow>
</mule>
Data-Mapper configuration image is here
Add a Groovy component after the data mapper and try and dump the contents
println "post mapping payload " + payload
return payload
I got it resolved using.
here is the configuration.xml
<mule ....>
<data-mapper:config name="sample_mapper_grf"transformationGraphPath="sample_mapper.grf" doc:name="DataMapper"/>
<flow name="CSV_to_XML_Data_MapperFlow1" doc:name="CSV_to_XML_Data_MapperFlow1">
<file:inbound-endpoint path="/home/jay/CSV_XML_/input" responseTimeout="10000" doc:name="Input File"/>
<data-mapper:transform config-ref="sample_mapper_grf" doc:name="DataMapper"/>
<object-to-string-transformer doc:name="Object to String"/>
<file:outbound-endpoint path="/home/jay/Output" responseTimeout="10000" doc:name="File" outputPattern="#[function:dateStamp].xml"/>
</flow>
</mule>
Related
I'm trying to use mule inbound file connector with poll scope got error saying couldn't start endpoint. If I remove poll scope and use file connector with default polling and its working fine without any file path changes.
I was wondering why is Poll scope giving error? If file inbound connector not allowed to wrapped in poll scope, why anypoint studio showing poll scope in the wrap in option ?
I found similar question, but I didn't see detailed explanations.
Mule won't allow POLL message processor to read file using file Inbound?
Advance thanks for your response.
Use mule-module-requester https://github.com/mulesoft/mule-module-requester, together with the Poll Scheduler.
relevant posts: http://blogs.mulesoft.com/dev/mule-dev/introducing-the-mule-requester-module/
Another way is,
Set the FTP flow initialState="stopped", and let the poll scheduler start the flow. After the FTP processing, stop the flow again.
see sample code:
<ftp:connector name="FTP" pollingFrequency="1000"
validateConnections="true" moveToDirectory="/work/ftp/processed"
doc:name="FTP" />
<flow name="scheduleStartFTPFlow">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="1"
timeUnit="MINUTES" />
<expression-component doc:name="START FTP FLOW"><![CDATA[if(app.registry.processFTPFlow.isStopped()){
app.registry.processFTPFlow.start();
}]]></expression-component>
</poll>
<logger message="Poll Logging: #[payload]" level="INFO"
doc:name="Logger" />
</flow>
<flow name="processFTPFlow" initialState="stopped">
<ftp:inbound-endpoint host="localhost" port="21"
path="/data/ftp" user="Sanjeet" password="sanjeet123" responseTimeout="10000"
doc:name="FTP" connector-ref="FTP" />
<logger message="Logging FTP #[payload]" level="INFO" doc:name="Logger" />
<expression-component doc:name="STOP FTP FLOW"><![CDATA[app.registry.processFTPFlow.stop();]]></expression-component>
</flow>
Please, provide SSCCE.
Based on your question you do not need Poll at all. File Connector already has this feature to check file periodically. Here is example which polls file every 0.123 seconds
<file:inbound-endpoint path="/tmp" responseTimeout="10000" doc:name="File" pollingFrequency="123"/>
My suggestion is to use the quartz connector beside the file connector and set the interval in the quartz connector. Or use the file connector itself having the poll frequency so no need to wrap the file in poll scope.
you can create a file endpoint in the global element section and then use mule requester to invoke that endpoint inside a poll scope.
<file:connector name="File1" autoDelete="true" streaming="true" validateConnections="true" doc:name="File"/>
<file:endpoint connector-ref="File1" name="File" responseTimeout="10000" doc:name="File" path="/"/>
<flow name="pocforloggingFlow1">
<poll doc:name="Poll">
<mulerequester:request resource="File" doc:name="Mule Requester"/>
</poll>
</flow>
<flow name="testFlow1" doc:name="testFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="${hostname}" port="${port}" path="dbtest" doc:name="HTTP"/>
<db:select config-ref="PostgreSQL" doc:name="Database">
<db:parameterized-query><![CDATA[SELECT id, name, int_status FROM test]]></db:parameterized-query>
</db:select>
<!--line 6 --> <!-- <set-payload value="==no downlaod=#[payload]" doc:name="Set Payload"/>-->
</flow>
when I run the application with url: host:port/dbtest, I am getting file downloaded. How can I avoid downloading file? If i enable line 6, I don't get file downloaded, instead it displays in browser.
Since you have used HTTP inbound 'exchange-pattern' as request-response. When you enable setpayload(line 6) it is returning to brower. If you dont want that, make HTTP exchange-pattern as one- way.
I tried the flow by adding an 'Object-to-String' transformer. It is working for me. The file is not downloading. Here is the flow.
<flow name="sampleflow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/"doc:name="HTTP></http:listener>
<db:select config-ref="MySQL_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[select id,name,designation,address from myrest]]></db:parameterized-query>
</db:select>
<object-to-string-transformer doc:name="Object to String"/>
</flow>
</mule>
<mulerequester:request config-ref="Mule_Requester1" resource="file:///#[flowVars.filename]" doc:name="Mule Requester"/>
<object-to-byte-array-transformer/>
<file:outbound-endpoint path="C:\OUTPUT" responseTimeout="10000" doc:name="Filewrite" outputPattern="#[flowVars.inpfilename]"/>
Please note below points
the above flow will create files (pdf,ppt,image ) with corrupted format in C:\OUTPUT folder
the file i want to move like pdf,ppt,image etc.
anyone suggest solution for that
If your requirement is to just move the files with some particular extenstions, this can be done by using File inbound and file outbound endpoints. Your flow should look like as follows
<flow name="testFlow1" doc:name="testFlow1">
<file:inbound-endpoint path="C:\Input" responseTimeout="10000" doc:name="File">
<file:filename-regex-filter pattern="*.pdf" caseSensitive="true"/>
</file:inbound-endpoint>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<file:outbound-endpoint path="C:\Output" responseTimeout="10000" doc:name="File"/>
</flow>
In Mule, I am downloading files from FTP server. I want to pass all the files in this directory to my java class which should be performing actions after Download_ZIP_File in my flow. I need to perform actions like reading text files and unzip the zipped files using Java.
There should be a Java class in my flow, for which a function call should be raised when download is complete.. Object of this class must know all the information about downloaded files.
Can someone please help on this.? Here is my current flow;
My XML for this flow is like this;
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:ftp="http://www.mulesoft.org/schema/mule/ee/ftp"
xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
... >
<file:endpoint name="Download_File_KBB" responseTimeout="10000" doc:name="File" path="E:\csv\output"/>
<file:connector name="Global_File_Connector" autoDelete="false" streaming="false" validateConnections="true" doc:name="File"/>
<flow name="ftp_kbb_download_fileFlow1" doc:name="ftp_kbb_download_fileFlow1">
<ftp:inbound-endpoint host="${ftp.host}" port="${ftp.port}" path="${ftp.pathInbound}" user="${ftp.user}" password="${ftp.password}" responseTimeout="10000" doc:name="KBB_FTP">
</ftp:inbound-endpoint>
<logger message="KBBUsedVehiclesNoSpecTabFormat-#[server.dateTime.year]-W#[server.dateTime.weekOfYear]" level="INFO" doc:name="Logger"/>
<file:outbound-endpoint path="${file.inboundEndpoint}" outputPattern="#[header:originalFilename]" responseTimeout="10000" doc:name="Donwload_ZIP_FILE" connector-ref="Global_File_Connector"/>
</flow>
</mule>
One option is to create a class that implements org.mule.api.lifecycle.Callable then configure it with a component element in your config.
Then, you will have full access to the MuleEventContext in the onCall method of this Callable class.
I have a mule flow as under
<flow name="flow1" doc:name="f1">
<file:inbound-endpoint path="C:\input" responseTimeout="10000"
doc:name="File" />
</flow>
<flow name="flow2" doc:name="f2">
<http:inbound-endpoint address="http://localhost:8080"
doc:name="HTTP" exchange-pattern="request-response" />
<flow-ref name="flow1" doc:name="Flow Reference" />
<file:outbound-endpoint path="C:\outputfile"
responseTimeout="10000" doc:name="File" />
</flow>
I am trying to move/upload multiple files from source to destination (can be anything e.g. FTP or File outbound etc..) by using the flow.
The reason for doing in this way is that I want to invoke the job from CLI(Command Line Interface) using CURL.
But it is not working....
Edited
I need to pick up some files(multiple files) from a particular folder located in my hard drive. And then move those to some outbound process which can be FTP site or some other hard drive location.
But this flow needs to be invoked from CLI.
Edited (Based on David's answer)
I now have the flow as under
<flow name="filePickupFlow" doc:name="flow1" initialState="stopped">
<file:inbound-endpoint path="C:\Input" responseTimeout="10000" doc:name="File"/>
<logger message="#[message.payloadAs(java.lang.String)]" level="ERROR" />
</flow>
<flow name="flow2" doc:name="flow2">
<http:inbound-endpoint address="http://localhost:8080/file-pickup/start" doc:name="HTTP" exchange-pattern="request-response"/>
<expression-component>
app.registry.filePickupFlow.start();
</expression-component>
<file:outbound-endpoint path="C:\outputfile" responseTimeout="10000" doc:name="File"/>
</flow>
I am getting couple of problems
a) I am getting an error that - Attribute initialState is not defined as a valid property of flow
However, if I remove that attribute, the flow continues without waiting for "http://localhost:8080/file-pickup/start" to fire up.
b) The files are not moved to the destination folder
So how can I do so?
You can't reference a flow that has an inbound endpoint in it because such a flow is already active and consuming events from its inbound endpoint so you can't invoke it on demand.
The following, tested on Mule 3.3.1, shows how to start a "file pickup flow" on demand from an HTTP request.
<flow name="filePickupFlow" initialState="stopped">
<file:inbound-endpoint path="///tmp/mule/input" />
<!-- Do something with the file: here we just log its content -->
<logger message="#[message.payloadAs(java.lang.String)]" level="ERROR" />
</flow>
<flow name="filePickupStarterFlow">
<http:inbound-endpoint address="http://localhost:8080/file-pickup/start"
exchange-pattern="request-response" />
<expression-component>
app.registry.filePickupFlow.start();
</expression-component>
<set-payload value="File Pickup successfully started" />
</flow>
HTTP GETting http://localhost:8080/file-pickup/start would then start the filePickupFlow, which in turn will process the files in /tmp/mule/input.
Note that it is up to you to configure the file:connector for what behavior it must have for files it processes, either deleting them or moving them to another directory are two main options.
I guess in this case a File inbound to read a file on demand will not be helpful.
Please try if the follwoing way.
<flow name="flow1" doc:name="f2">
<http:inbound-endpoint address="http://localhost:8080"
doc:name="HTTP" exchange-pattern="request-response" />
<component>
<spring-object bean="fileLoader"></spring-object>
</component>
<file:outbound-endpoint path="C:\outputfile"
responseTimeout="10000" doc:name="File" />
</flow>
So the Custom component will be a Class which reads the file from your specified location.
Hope this helps.
You can use Mule Requester for a clean solution. See the details in the blog entry Introducing the Mule Requester.