I get a file path as an input to mule inside xml. Using XPATH expression, I am able to extract the path. I want to read a particular file from that path. I tried to define file inbound endpoint as below. But it doesn't seem to be working.
<flow name="flow1">
....
....
<set-session-variable variableName="filePath" value="#[xpath://filePath]" />
<flow-ref name="fileFlow"/>
</flow>
<flow name="fileFlow">
<file:inbound-endpoint path="#[header:SESSION:filePath]" />
</flow>
My understanding here is that no code can be placed before an inbound-endpoint. Hence I defined it in another flow. Please suggest if there is a way to read the file from a specified path.
Unfortunately, you cannot programmatically call an inbound-endpoint like that.
However the same functionality can be achieved using the Mule requester module:
Example:
<flow name="RequestFile" doc:name="RequestFile">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="requestfile" doc:name="HTTP"/>
<mulerequester:request config-ref="Mule_Requester" resource="file:///s/tmp/demorequester/read/#[message.inboundProperties['filename']]" returnClass="java.lang.String" doc:name="Request a file"/>
</flow>
Instructions here: https://github.com/mulesoft/mule-module-requester and https://blogs.mulesoft.com/dev/mule-dev/introducing-the-mule-requester-module/
Related
Below is the configuration xml of my small program in Anypoint Studio. What i am trying to do is copying one text file data(pipe delimited) to another text file. The execution goes well but stops at status as "Deployed". I have tried other transformations as well but the result is same. Help is highly appreciable. Thanks in advance.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd">
<flow name="texttoexcelFlow" doc:id="42aaa83a-e26a-4f6d-8d2f-da3613a8d232" initialState="started">
<file:read doc:name="Read" doc:id="89fa46c9-aa14-4a79-b7ab-e609b9fad501" path="D:\Mulesoft Input\Name.txt" outputMimeType="application/json" outputEncoding="UTF-8">
<repeatable-in-memory-stream />
</file:read>
<ee:transform doc:name="Transform Message" doc:id="86dc86b8-99ed-4bee-b5bc-e07616e44431" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/csv headerLineNumber = 0 , header = false , separator = "|"
---
payload map ( payload01 , indexOfPayload01 ) -> {
FirstName: payload01.FirstName ,
LastName: payload01.LastName
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<file:write doc:name="Write" doc:id="3884725e-3870-4ef1-9e05-b10a2274dfa6" path="C:\Users\aseem\Desktop\Mulesoft Output\Excel.txt">
</file:write>
</flow>
</mule>
"
You need something to trigger the flow to run. file:read doesn’t do this automatically.
All flows need a ‘Source’ to trigger them unless you are calling them from other flows using flow-ref (or from dataweave using a lookup()).
If you know the exact file you want then you can put a scheduler before your file:read to trigger the flow:
<scheduler>
<scheduling-strategy>
<fixed-frequency startDelay="5" frequency="10" timeUnit="SECONDS"/>
</scheduling-strategy>
</scheduler>
Or you can use a file:listener to listen for new files in a directory etc as the source directly:
<flow name="onNewFile">
<file:listener config-ref="file" directory="test-data/in" autoDelete="true">
<scheduling-strategy>
<fixed-frequency frequency="1000"/>
</scheduling-strategy>
</file:listener>
...
</flow>
You can use fixed frequency or cron. More details here: https://docs.mulesoft.com/mule-runtime/4.1/scheduler-xml-reference
I need to set the file name without extension in header. While searching I got the below blueprint/spring code snippet. I want to achieve the same through Java DSL. can any one help me?
<camel:route>
<camel:from uri="file://input/orders" />
<camel:setHeader headerName="FileNameWithoutExtension">
<camel:simple>${file:onlyname.noext}</camel:simple>
</camel:setHeader>
I found out. We have to follow the below syntax
.setHeader("FileNameWithoutExtension",simple("${file:onlyname.noext}"))
I have the following Camel context XML. I set a header named MediaType. But, when I set a breakpoint in RenamerProcessor I don't see the header (I've also tried using setProperty with the same results. Being very new to Camel, I've found several examples that make it seem like the below should work.
What is wrong?
<camel:route>
<camel:from uri="file://c:/CamelTVInput" />
<camel:setHeader headerName="MediaType">
<camel:constant>T</camel:constant>
</camel:setHeader>
<camel:to uri="file://c:/CamelReadyToRename" />
</camel:route>
<camel:route>
<camel:from uri="file://c:/CamelReadyToRename?move=//c:/CamelBackup" />
<camel:process ref="RenamerProcessor" />
<camel:to uri="file://c:/CamelOutput" />
</camel:route>
You cannot transfer headers using files. eg when you write to a file, then its only the message body that is written as the file content.
But this is component specific if headers is part of the protocol, eg JMS, HTTP support headers.
If you want to keep files then use something else, Camel has some internal components like seda / direct.
I am using Mule 3.4 and I try to send a file from a folder in the mail.
The console displays:
connector.file.mule.default.receiver.01] org.mule.transport.file.FileMessageReceiver: Lock obtained on file: C:\Users\bekbol\Documents\smtp\test.txt
My config file is below:
<flow name="outcomingSmtp" doc:name="outcomingSmtp">
<file:inbound-endpoint path="${file.outcomingSmtp}" responseTimeout="100000" doc:name="File" pollingFrequency="10000" moveToDirectory="${file.outcomingBackupSmtp}">
<file:filename-wildcard-filter
pattern="*.txt" />
<file:file-to-string-transformer doc:name="File to String"/>
</file:inbound-endpoint>
<object-to-byte-array-transformer doc:name="Object to Byte Array"/>
<smtp:outbound-endpoint host="${smtp.host}" port="${smtp.port}" user="${email.username}" password="${email.password}" to="${header.to}" from="${header.from}" subject="${header.subject}" responseTimeout="100000" mimeType="text/plain" doc:name="SMTP">
<email:string-to-email-transformer doc:name="String to Email"/>
</smtp:outbound-endpoint>
</flow>
I don't think you need
<file:file-to-string-transformer doc:name="File to String"/>
nested inside your <file:inbound-endpoint>. Move it outside right after you close </file:inbound-endpoint> and
remove <object-to-byte-array-transformer doc:name="Object to Byte Array"/>
I have a requirement like transferring a file from a inbound directory to a outbound directory using file connector in Mule. While transferring the file it is processed in a working directory configured in the input file connector.
Now, my requirement is , if I place an old file in the file input directory, the file in the working directory should have the current time stamp on the system date modified.
It is something similar like "Touch" command used in Unix to set the system modified date.
Please not I don't want to use any Groovy Script method or any other hack method that can affect the performance in order to achieve this.
Following is my Mule mflow:-
<file:connector name="File" autoDelete="true" streaming="true" validateConnections="true" doc:name="File" outputAppend="true"/>
<file:connector name="File1" autoDelete="false" streaming="false" validateConnections="true" doc:name="File"/>
<flow name="FileReadandDeleteFlow1" doc:name="FileReadandDeleteFlow1">
<file:inbound-endpoint responseTimeout="10000" doc:name="File" connector-ref="File" moveToDirectory="E:\backup\test_workingDir" path="E:\backup\test" moveToPattern="processingFile.xml">
</file:inbound-endpoint>
<file:outbound-endpoint path="E:\backup\test_out" outputPattern="Finaloutput.txt" responseTimeout="10000" connector-ref="File1" doc:name="File"/>
Thanks in advance
You can #[function:dateStamp] or #[function:datestamp:dd-MM-yy] to achieve this as described in this link
An example would be :
<file:outbound-endpoint path="E:\backup\test_out" outputPattern="Finaloutput_[function:dateStamp].txt" responseTimeout="10000" connector-ref="File1" doc:name="File"/>
EDIT:
To always show the current timestamp to your files in working firectory, you can create another flow which reads files from working directory at a specific interval, and just copy them to same directory using file:outbound-endpoint
we have mel using this we cal achieve current date and time
[server.dateTime.format("yyyyMMddhhmmss")].txt
The format u like we can set in the expression.
This worked for me
<file:outbound-endpoint path="YOUR_PATH" outputPattern="#[function:datestamp:yyyyMMdd-HHmmssSSSSSS]
_#[message.inboundProperties.originalFilename]" responseTimeout="10000" doc:name="Backup In Mule"/>