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
Related
I am using React and would like to use the data within the .env file and insert it into my .xml file.
Is this achievable somehow, could not find anything useful on the net?
The file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="TaskPaneApp">
<!--IMPORTANT! Id must be unique for each add-in. If you copy this manifest ensure that you change this id to your own GUID. -->
<Id>c6890c26-5bbb-40ed-a321-37f07909a2f0</Id>
<Version>1.0</Version>
<ProviderName>Contoso, Ltd</ProviderName>
<DefaultLocale>en-US</DefaultLocale>
<DisplayName DefaultValue="Northwind Traders Excel" />
<Description DefaultValue="Search Northwind Traders data from Excel"/>
<SupportUrl DefaultValue="[Insert the URL of a page that provides support information for the app]" />
<AppDomains>
<AppDomain>https://www.northwindtraders.com</AppDomain>
</AppDomains>
<DefaultSettings>
<SourceLocation DefaultValue="https://www.contoso.com/search_app/Default.aspx" />
</DefaultSettings>
<Permissions>ReadWriteDocument</Permissions>
</OfficeApp>
And instead of the lets say Id property i would like to have some preset value from .env.
I am trying to create records in Salesforce using a CSV file in Mule 4. However, after the first batch is created successfully, instead of ending the program, Mule goes back and creates the same batches an infinite amount of times.
How do I get Mule to stop after the first batch is created? Here is my code:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:batch="http://www.mulesoft.org/schema/mule/batch" xmlns:db="http://www.mulesoft.org/schema/mule/db"
xmlns:salesforce="http://www.mulesoft.org/schema/mule/salesforce"
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/salesforce
http://www.mulesoft.org/schema/mule/salesforce/current/mule-salesforce.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/batch http://www.mulesoft.org/schema/mule/batch/current/mule-batch.xsd">
<salesforce:sfdc-config name="Salesforce_Config" doc:name="Salesforce Config" doc:id="8e29192b-953e-499f-a34b-584b34bd6e9c" >
<salesforce:basic-connection username="gregory.palios#ohrsdev2.com" password="1luvL!zzy" securityToken="6QgMUnwuaNM9rgX5HQbiwIdv" url="https://vha-gov--ohrsdev2.my.salesforce.com/services/Soap/u/48.0" />
</salesforce:sfdc-config>
<flow name="addendumFlow" doc:id="4df7a2c4-3d56-4e00-a65a-62f579f43880" >
<file:listener doc:name="On New or Updated File" doc:id="7ea260b4-02a9-429c-82a9-87cf924c6ef1" directory="C:\Users\GregoryPalios\AnypointStudio\studio-workspace\legacyohrstestmigration\Table Files\ADDENDUM">
<scheduling-strategy >
<fixed-frequency />
</scheduling-strategy>
</file:listener>
<ee:transform doc:name="Transform Message" doc:id="93744a3d-5945-4688-af87-afaf90677469">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/java
---
[payload map{
ADDENDUM_ID__c: $.ADDENDUM_ID as Number,
ENCOUNTER_ID__c: $.ENCOUNTER_ID as Number,
OH_STD_ENCOUNTER_STATUS_ID__c: $.OH_STD_ENCOUNTER_STATUS_ID as Number,
NOTE__c: $.NOTE,
ADDENDUM_DESCRIPTION__c: $.ADDENDUM_DESCRIPTION,
VIEWED_DATE__c: $.VIEWED_DATE,
VIEWED_DATE_TZ__c: $.VIEWED_DATE_TZ,
DELETED_DATE__c: $.DELETED_DATE,
DELETED_DATE_TZ__c: $.DELETED_DATE_TZ,
DELETED_BY__c: $.DELETED_BY,
CO_SIGNATURE_REQUIRED_IND__c: $.CO_SIGNATURE_REQUIRED_IND,
CO_SIGNER_ACTIVE_DIRECTORY_NAME__c: $.CO_SIGNER_ACTIVE_DIRECTORY_NAME,
ADMIN_LEVEL__c: $.ADMIN_LEVEL,
RECORD_CREATED_BY__c: $.RECORD_CREATED_BY,
RECORD_CREATED_DATE__c: $.RECORD_CREATED_DATE,
RECORD_MODIFIED_BY__c: $.RECORD_MODIFIED_BY,
RECORD_MODIFIED_DATE__c: $.RECORD_MODIFIED_DATE,
RECORD_MODIFIED_COUNT__c: $.RECORD_MODIFIED_COUNT as Number,
RECORD_CREATED_DATE_TZ__c: $.RECORD_CREATED_DATE_TZ,
RECORD_MODIFIED_DATE_TZ__c: $.RECORD_MODIFIED_DATE_TZ,
OH_STD_INACTIVE_ACTIVITY_REASON_ID__c: $.OH_STD_INACTIVE_ACTIVITY_REASON_ID as Number
}]]]></ee:set-payload>
</ee:message>
</ee:transform>
<foreach doc:name="For Each" doc:id="9ab8acaf-988e-4a02-bb72-3150f9688a4a" >
<salesforce:create doc:name="Create" doc:id="2865a2fd-2559-401e-a365-93950717d3a7" config-ref="Salesforce_Config" type="ADDENDUM__c" />
</foreach>
</flow>
In your file listener, you need to set the autoDelete to "true" or move the file to a backup director other than the directory you are listening to.
You can also enable watermarking so file will not be picked up again and again.
I am doing a simple file read using WSO2 ESB File connection 2. I try to read a .OUT file from the given directory. It reads the first file (alphabetical order?) well but I have no idea which file is read. Is there a (transport?) property that gets populated when a file is read?
Here is my code in a proxy service
<fileconnector.read>
<source>file:///D:/temp</source>
<filePattern>.*\.OUT</filePattern>
<contentType>text/plain</contentType>
</fileconnector.read>
<log level="full"/>
I get the following response
INFO - LogMediator To: /services/SampleProxy.SampleProxyHttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:f5737693-6a51-4044-9134-95cd61eaeaa4, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><text xmlns="http://ws.apache.org/commons/ns/payload">abc,123
qwe,456
</text></soapenv:Body></soapenv:Envelope>
Give it a try like this. (Just a suggestion. I didn't try.)
<log level="custom">
<property name="FileName" expression="$trp:FILE_NAME" />
</log>
If you want to read a particular file, you can pass the full path as a value in source and you can skip the file pattern value.
<fileconnector.read>
<source>file:///D:/temp/abc.OUT</source>
<filePattern></filePattern>
<contentType>text/plain</contentType>
</fileconnector.read>
This is a valid requirement. We will consider this in our future release. Please use [1] to track the progress.
[1] https://wso2.org/jira/browse/ESBCONNECT-192
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/
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"/>