Mule: How to capture attachment from IMAP connector? - mule

I have my test flow successfully querying an imap inbox. I'm trying to capture the attachments and save them to an output folder. So far, I haven't had any success. I've played around with the "Attachment" transform as well as copying and pasting the example from the documentation for the IMAP transport. I'm not sure if that example is out of date or what, but I keep getting an error.
Here is the code from the "Configuration Example" in the IMAP docs:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:imap="http://www.mulesoft.org/schema/mule/imap"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:email="http://www.mulesoft.org/schema/mule/email"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.6/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/3.6/mule-file.xsd
http://www.mulesoft.org/schema/mule/imap http://www.mulesoft.org/schema/mule/imap/3.6/mule-imap.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/3.6/mule-email.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/3.6/mule-vm.xsd">
<imap:connector name="imapConnector" />
<expression-transformer name="returnAttachments">
<return-argument evaluator="attachments-list" expression="*" optional="false"/> ❶
</expression-transformer>
<file:connector name="fileName">
<file:expression-filename-parser/>
</file:connector>
<flow name="incoming-orders">
<imap:inbound-endpoint user="bob" password="password" host="emailHost"
port="143" transformer-refs="returnAttachments" disableTransportTransformer="true"/> ❷
<collection-splitter/>
<file:outbound-endpoint path="./received" outputPattern="#[function:datestamp].dat"> ❹
<expression-transformer>
<return-argument expression="payload.inputStream" evaluator="groovy" /> ❺
</expression-transformer>
</file:outbound-endpoint>
</flow>
</mule>
And here is the error I get (after changing all the connection details):
Element 'expression-transformer' cannot have character [children], because the type's content type is element-only.
Relevant info:
Mule ESB and Integration Platform
Version: 3.6.0 Build: ed775fdb
JDK: 1.8.0_31 (mixed mode)
OS: Windows 8.1 - (6.3, amd64)
Host: computername (192.168.1.116)
Full output: http://pastebin.com/1EAEbTFw

I could only get that error using the exact config you provided, because there are weird characters in it, see: ❶
I guess you copy-pasted from the docs site? Those are references within the docs.
Removed them and it should work.

Related

Quartz job to read wildcard filename only picks up one file

Using Mule 3.7. If I have 5 files in a directory with a .csv extension the below code only picks up one of the five files. If I remove the quartz trigger and make it a normal file:inbound-endpoint it picks up all five files. It seems so simple but does not work as intended.
Thanks,
-- Don
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:context="http://www.springframework.org/schema/context" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz"
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:spring="http://www.springframework.org/schema/beans" version="EE-3.6.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
<file:connector name="fileInConnector" autoDelete="false" streaming="true" validateConnections="true" doc:name="FileConnector" />
<file:endpoint name="fileInEndpoint" path="\\\\c:\\scratch" connector-ref="fileInConnector" doc:name="FileEndpoint">
<file:filename-wildcard-filter pattern="*.csv" />
</file:endpoint>
<flow name="fileUploader">
<quartz:inbound-endpoint jobName="getFilesTrigger" cronExpression="/15 * * * * ?" doc:name="Quartz">
<quartz:endpoint-polling-job>
<quartz:job-endpoint ref="fileInEndpoint" />
</quartz:endpoint-polling-job>
</quartz:inbound-endpoint>
<logger message="Filename=#[message.inboundProperties.originalFilename]" level="INFO" doc:name="Logger" />
</flow>
</mule>
Here is the log after it firing twice:
INFO 2015-10-05 15:09:30,063 [scheduler-quartzcronfilepickup_Worker-1] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'fileInConnector.requester.2009817243'. Object is: FileMessageRequester
INFO 2015-10-05 15:09:30,069 [scheduler-quartzcronfilepickup_Worker-1] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'fileInConnector.requester.2009817243'. Object is: FileMessageRequester
INFO 2015-10-05 15:09:30,117 [[quartzcronfilepickup].fileUploader.stage1.02] org.mule.api.processor.LoggerMessageProcessor: Filename=D1.csv
INFO 2015-10-05 15:09:45,015 [scheduler-quartzcronfilepickup_Worker-2] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'fileInConnector.requester.636902426'. Object is: FileMessageRequester
INFO 2015-10-05 15:09:45,016 [scheduler-quartzcronfilepickup_Worker-2] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'fileInConnector.requester.636902426'. Object is: FileMessageRequester
INFO 2015-10-05 15:09:45,022 [[quartzcronfilepickup].fileUploader.stage1.02] org.mule.api.processor.LoggerMessageProcessor: Filename=D1.csv
There is a major difference between using a polling file inbound-endpoint and a Quartz inbound-endpoint polling a file endpoint: the former uses a message receiver, while the latter uses a message requester. Being two different beasts, they have the potential to be implemented quite differently.
And, guess what?, that's exactly the case for files. The file message receiver uses a lock mechanism to prevent polling a file that is being processed, while the requester does not.
The fun bit is this comment in the source code of the requester:
// Don't we need to try to obtain a file lock as we do with receiver
This doubt and the lack of lock usage in the requester is what makes it behave differently than the receiver. The fact this has never been solved for sure probably means that adding a lock there has undesired side-effects.
In any case, if you persist in using Quartz, I suggest you move the file being processed to another directory to prevent having it re-polled. The file endpoint should be able to do the move for you.

Invalid Keystore Format when trying to deploy Mule project

I'm just trying to follow some of the Mulesoft tutorials and messing around with them to see if I can figure out how things work. This particular tutorial is one that demonstrates the usage of IMAP and how to use it to get information from an email.
I'm currently using this tutorial, and it was working fine. I then made some changes to just see how things worked. I have a simple flow that looks like this:
IMAP -> Email-to-string -> Logger
And the XML looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:email="http://www.mulesoft.org/schema/mule/email" version="EE-3.6.0" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:context="http://www.springframework.org/schema/context" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:imap="http://www.mulesoft.org/schema/mule/imap" xmlns:imaps="http://www.mulesoft.org/schema/mule/imaps" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/imap http://www.mulesoft.org/schema/mule/imap/current/mule-imap.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd
http://www.mulesoft.org/schema/mule/imaps http://www.mulesoft.org/schema/mule/imaps/current/mule-imaps.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/current/mule-email.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd">
<imaps:connector checkFrequency="100" doc:name="IMAP" name="imapsConnector" validateConnections="true">
<imaps:tls-client path="" storePassword=""/>
<imaps:tls-trust-store path="" storePassword=""/>
</imaps:connector>
<flow name="imap-to-csvFlow1">
<imaps:inbound-endpoint connector-ref="imapsConnector" doc:name="Poll emails" host="imap.gmail.com" password="samplepass" port="993" responseTimeout="10000" user="sampleuser%40gmail.com"/>
<email:email-to-string-transformer doc:name="Email to String"/>
<logger message="#[message.payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
And the error I'm getting is:
ERROR 2015-06-04 13:34:13,706 [main] org.mule.module.launcher.application.DefaultMuleApplication: null
java.io.IOException: Invalid keystore format
The full console log is obviously a bit more extensive but that's the first error that appears.
If you use IMAPS (as opposed to IMAP), you need to provide valid values for the TLS client and trust store.
For example:
<imaps:tls-client path="clientKeystore" storePassword="mulepassword" />
<imaps:tls-trust-store path="greenmail-truststore" storePassword="password" />
The email transport integration tests have ready made keystores you can play with: https://github.com/mulesoft/mule/tree/mule-3.6.2/transports/email/src/test/resources
Reference: https://developer.mulesoft.com/docs/display/current/IMAP+Transport+Reference#IMAPTransportReference-ConfigurationReference

Anypoint Enterprise Security IP Filter

Hi I am working with Mule Anypoint Studio and I am trying to implement a list of IP's but my program is allowing every request from all IP's and it works only for one request per browser. How it is working i have no Idea. Please elaborate the working . Please don't share Mule Documentation Link because there they have not given much information.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:filters="http://www.mulesoft.org/schema/mule/filters" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/filters http://www.mulesoft.org/schema/mule/filters/current/mule-filters.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<filters:config name="Filters" doc:name="Filters"/>
<flow name="mule-security-ipFlow1" doc:name="mule-security-ipFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="196.111.1.1" port="8081" doc:name="HTTP" path="ip"/>
<filters:filter-by-ip config-ref="Filters" regex="196.16.4.1,196.17.7.13" doc:name="Filters"/>
<set-payload value="#['Data Mast']" doc:name="Set Payload"/>
<logger message="#[message.payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
there are two scenarios here, we can specify regular expression to allow certain ip range requests or we can specify single ip address as part regex attaribute value.
<filters:filter-by-ip config-ref="Filters" regex="${fms.iprange}"
doc:name="verify-ip-address" />
if we want to allow comma separated ip address, its better to write custom filter and do the required logic .
Depending on how you are intending to deploy your flow your other option is to use api-kit to apply the IP whitelist (or blacklist) to your flow as a policy:

mule-esb ajax integration with google spell check

I downloaded latest mule studio from the mulesoft and started working on first example in,
Windows 8: 64bit.
Mule version: 3.4.0
JRE: 7
Project name given as: test
buildDate: 201305141336
When i click this link in a browser, getting following error:
https://www.google.com/tbproxy/spell?lang=en
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<spellresult error="1"/>
my xml file:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:ajax="http://www.mulesoft.org/schema/mule/ajax" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/ajax http://www.mulesoft.org/schema/mule/ajax/current/mule-ajax.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<ajax:connector name="AjaxConnector" serverUrl="http://127.0.0.1:8090/Ajax" resourceBase="src/main/app/docroot" jsonCommented="true" doc:name="Ajax"/>
<flow name="testFlow1" doc:name="testFlow1">
<ajax:inbound-endpoint channel="services/echo" responseTimeout="10000" doc:name="Ajax Channel" connector-ref="AjaxConnector"/>
<mulexml:object-to-xml-transformer doc:name="Convert JS to XML"/>
<mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" doc:name="Convert XML structure" xsl-file="F:\project\workspace\mulestudio\test\src\main\resources\transform.xsl"/>
<http:outbound-endpoint exchange-pattern="request-response" host="www.google.com/tbproxy/spell?lang=en" port="80" method="POST" doc:name="Google API" contentType="text/xml"/>
<echo-component doc:name="Echo to Console"/>
</flow>
</mule>
You are getting this error because by browsing https://www.google.com/tbproxy/spell?lang=en you are sending an HTTP GET request to a resource that accepts HTTP POST requests.
Try with:
curl -H "Content-Type: application/xml" \
-d '<spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="0"><text>look at the butterfli</text></spellrequest>' \
https://www.google.com/tbproxy/spell?lang=en
and you will see spelling suggestions from Google.

Catch Exception Strategy

My Mule studio version is:
version: 3.4.0
buildDate: 201305141336
I am confused on the catch exception strategy... and maybe I need to use a different strategy. Basically I need to write data to a file. After the file write I want to send an email to indicate whether the write was successful or not. (Failure is most likely to happen if someone has the file open at write time). I originally tried putting an email in the catch exception block but what happened then was that I got both emails; the one in the catch block and the one at the end of the flow. I attempted to create a variable with the email subject in it and change the value out in the exception but it doesn't seem to do anything. I still get the email with the success message in it.
Does anyone have some suggestions on how to make this work? Ultimately, I just want to send a different email based on the file write success/failure. Here is my configuration. I have been causing the failure by opening the target file with Excel which locks the file.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
http://www.mulesoft.org/schema/mule/ee/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.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/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<flow name="FileOpenExample" doc:name="FileOpenExample" >
<quartz:inbound-endpoint xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" jobName="fileOpenEx" cronExpression="0,30 * * ? * FRI" repeatInterval="0" repeatCount="2" responseTimeout="10000" doc:name="Quartz">
<quartz:event-generator-job/>
</quartz:inbound-endpoint>
<set-payload value="Some Sample File Data" doc:name="Set File Data"/>
<set-variable variableName="emailSubject" value="File Save Successful" doc:name="Variable"/>
<file:outbound-endpoint path="C:\Temp\IntegrationTesting" outputPattern="Attributes.csv" responseTimeout="10000" doc:name="File"/>
<set-payload value="This email was generated by a Mule process." doc:name="Set Email Body"/>
<smtp:outbound-endpoint host="mail1.newpig.com" to="${email.toList}" subject="#[emailSubject]" responseTimeout="10000" doc:name="EmailSuccess" />
<catch-exception-strategy doc:name="Catch Exception Strategy" enableNotifications="false">
<expression-transformer expression="#[emailSubject='Save Failed']" doc:name="Expression"/>
</catch-exception-strategy> </flow>
</mule>
This scenario seems to be more similar like an earlier post.
Here the flow is posting onto an out-bound and then continue with the flow, as the out-bound is an asynchronous in nature. There needs to be something which can make the flow wait and then based on the status proceed further.
You can find the earlier similar post and my answer at the following link.
Mule flow execution unexpectedly splits on error in SMTP sendout
Hope this helps.