1

Using Mule EE, I have the following project;

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:jdbc-ee="http://www...
    <smtp:gmail-connector name="gmail" doc:name="Gmail"/>
    <db:mysql-config name="MySQL_Configuration" host="localhost"
        port="3306"   database="dbflow"
        doc:name="MySQL Configuration" user="user" password="Pass"/>
    <data-mapper:config name="CSV_To_XML" transformationGraphPath="csv_to_xml.grf" doc:name="CSV_To_XML"/>
    <ftp:connector name="FTP" pollingFrequency="1000" validateConnections="true" moveToDirectory= "C:\Users\User\Desktop\output" doc:name="FTP"/>
    <flow name="dbFlow1" doc:name="dbFlow1">
        <ftp:inbound-endpoint host="localhost" port="21" path="/{path}" user="username" password="pass" responseTimeout="10000" doc:name="FTP" connector-ref="FTP"/>
        <data-mapper:transform config-ref="CSV_To_XML" doc:name="CSV To XML"/>
        <byte-array-to-string-transformer doc:name="Byte Array to String"/>
        <foreach collection="#[xpath('//info')]" doc:name="For Each">
            <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
            <db:insert config-ref="MySQL_Configuration" doc:name="Database">
                <db:parameterized-query><![CDATA[INSERT INTO `dbflow`.`user_table`
(`my_date`,
`serialnumber`,
`gender`,
`fullname`,
`email`,
`mobilenumber`,
`address`)
VALUES
(#[xpath://date],
#[xpath://serialnumber],
#[xpath://gender],
#[xpath://fullname],
#[xpath://email],
#[xpath://mobilenumber],
#[xpath://address]
);]]></db:parameterized-query>
            </db:insert>
            <message-properties-transformer scope="invocation" doc:name="Message Properties">
                <add-message-property key="count" value="#[flowVars.counter]"/>
            </message-properties-transformer>
        </foreach>
        <logger message="Number of records #[flowVars]" level="INFO" doc:name="Logger"/>
        <smtp:outbound-endpoint host="smtp.gmail.com" port="587" user="user10%40gmail.com" password="pass" connector-ref="gmail" to="user2@gmail.com"  subject=Muleapp" responseTimeout="10000" doc:name="Email"/>
    </flow>
</mule>

It works correctly. However, when I add the FTP connector to use moveToDirectory, Mule is giving me the following error with NON-STOP! the file is moved to the directory I want, but Mule is giving same error infinity times! It won't stop unless I stop running Mule! And Mule doesn't continue with the flow (inserting in DB & sending email);

ERROR 2014-08-03 21:00:56,113 [[tests].FTP.receiver.02] org.mule.exception.DefaultSystemExceptionStrategy: Caught exception in Exception Strategy: Failed to rename file mytest.csv to C:\Users\user\Desktop\outputmytest.csv. Ftp error: 553
java.io.IOException: Failed to rename file mytest.csv to C:\Users\user\Desktop\outputmytest.csv. Ftp error: 553
    at com.mulesoft.mule.transport.ftp.EEFtpMessageReceiver.postProcess(EEFtpMessageReceiver.java:61)
    at org.mule.transport.ftp.FtpMessageReceiver$FtpWork.run(FtpMessageReceiver.java:312)
    at org.mule.transport.TrackingWorkManager$TrackeableWork.run(TrackingWorkManager.java:267)
    at org.mule.work.WorkerContext.run(WorkerContext.java:286)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
ERROR 2014-08-03 21:00:57,138 [[tests].FTP.receiver.01] org.mule.exception.DefaultSystemExceptionStrategy: Caught exception in Exception Strategy: Failed to rename file mytest.csv to C:\Users\user\Desktop\outputmytest.csv. Ftp error: 553
java.io.IOException: Failed to rename file mytest.csv to C:\Users\user\Desktop\outputmytest.csv. Ftp error: 553
    at com.mulesoft.mule.transport.ftp.EEFtpMessageReceiver.postProcess(EEFtpMessageReceiver.java:61)
    at org.mule.transport.ftp.FtpMessageReceiver$FtpWork.run(FtpMessageReceiver.java:312)
    at org.mule.transport.TrackingWorkManager$TrackeableWork.run(TrackingWorkManager.java:267)
    at org.mule.work.WorkerContext.run(WorkerContext.java:286)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
ERROR 2014-08-03 21:00:58,064 [[tests].FTP.receiver.02] org.mule.exception.DefaultSystemExceptionStrategy: Caught exception in Exception Strategy: Failed to rename file mytest.csv to C:\Users\user\Desktop\outputmytest.csv. Ftp error: 553
java.io.IOException: Failed to rename file mytest.csv to C:\Users\user\Desktop\outputmytest.csv. Ftp error: 553
    at com.mulesoft.mule.transport.ftp.EEFtpMessageReceiver.postProcess(EEFtpMessageReceiver.java:61)
    at org.mule.transport.ftp.FtpMessageReceiver$FtpWork.run(FtpMessageReceiver.java:312)
    at org.mule.transport.TrackingWorkManager$TrackeableWork.run(TrackingWorkManager.java:267)
    at org.mule.work.WorkerContext.run(WorkerContext.java:286)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
ERROR 2014-08-03 21:00:58,491 [[tests].dbFlow1.stage1.03] org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : Duplicate entry '546565' for key 'PRIMARY' (com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException). Message payload is of type: String
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Duplicate entry '546565' for key 'PRIMARY' (com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException)
  sun.reflect.NativeConstructorAccessorImpl:-2 (null)
2. Duplicate entry '546565' for key 'PRIMARY' (com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException). Message payload is of type: String (org.mule.api.MessagingException)
  org.mule.module.db.internal.processor.AbstractDbMessageProcessor:81 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '546565' for key 'PRIMARY'
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

The content of mytest.csv is like: (DB same columns and serialnumber is primary key)

date|serialnumber|gender|fullname|email|mobilenumber|address
03-07-2014|546565|m|your name|my@mail.com|219239|my address

I've tried to use #[message.inboundProperties.originalFilename] and outputPattern="#[header:originalFilename]". maybe those are wrong but anyways, Mule keeps showing same error with no changes!

The point is to move the file from FTP to local PC, and insert it in DB then email. (both roads together). Any help will be appreciated!

Jad
  • 479
  • 2
  • 10
  • 23

2 Answers2

2

You are not showing the value you were sing in moveToDirectory but, from the exception, it looks like you were trying to move to a local directory, which would be a mistake.

The whole point of moveToDirectory is to move the file to a remote directory, not a local one.

If you want a local copy of the file downloaded from FTP, just use a file:outbound-endpoint to write it to whatever local directory you want.

David Dossot
  • 33,403
  • 4
  • 38
  • 72
  • Ok. Awesome +1! But how can I use the file outbound with the other components? The `` is deprecated. And plus, when I tried to use the file outbound, the file is moved as .dat not as .csv file like the original one. Is there any configuration to add with the file:outbound endpoint? Thanks in advance! – Jad Aug 04 '14 at 03:22
  • 1
    You don't need all: you should be able to put the `file:outbound-endpoint` right into your flow. And yes, you can control the name of the written file. See `outputPattern` in the user guide: http://www.mulesoft.org/documentation/display/current/File+Transport+Reference#FileTransportReference-Outboundendpoint – David Dossot Aug 04 '14 at 14:43
  • well, seems it is working BUT, it is not stopping :'( Mule keeps doing the same for infinity times until I stop it manually! I received 33 emails :3 and the DB table is about to be full :D and the file name is so long (I can't delete the file now :O). How to tell Mule to do the process one time only, please?! – Jad Aug 04 '14 at 15:52
  • This does not make sense: is `moveToDirectory` correctly configured? Do you see the files being moved from the pick-up directory to the moveTo directory? – David Dossot Aug 04 '14 at 16:44
  • NO, I've deleted `moveToDirectory` as I want the file to be moved to the local PC. I added: `` I added it after the `FTP:inbound-endpoint` and the file is moved from ftp to the local PC (but with infinity name), data is inserted in DB (infinity records), and I am receiving the email (infinity emails) :'( – Jad Aug 04 '14 at 17:19
  • Is the FTP user authorized to delete files on the server? – David Dossot Aug 04 '14 at 18:01
  • yes, in the FTP server, I gave the user permission to read, write, delete and append the files. Is that related? – Jad Aug 04 '14 at 18:21
  • Can you clean up the DB? I'm wondering if the issue simply comes from the fact you're trying to reprocess an already processed file and the exceptions thrown at DB insert (constraints violation) prevent the FTP delete to occur. – David Dossot Aug 04 '14 at 18:30
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/58633/discussion-between-jad-and-david-dossot). – Jad Aug 04 '14 at 18:38
1

I had a similar thing start happening, I took a project that worked fine in Studio and Standalone 3.50, when I moved the same .zip deployment file to 3.51 it started pulling the files from the file:inbound-endpoint's moveToDirectory (my processed/archive directory).

Lock obtained on file:

\\fsvr\vol2\DCH_ESB_Test\LMS\In2\Processed\LMS_20140821_112625_250.dat 

Lock obtained on file:

\\fsvr\vol2\DCH_ESB_Test\LMS\In2\Processed\LMS_20140821_112625_265.dat 

It should have been pulling files from:

\\fsvr\vol2\DCH_ESB_Test\LMS\In2

Instead it pulled them from:

\\fsvr\vol2\DCH_ESB_Test\LMS\In2\Processed 

So my app also started spamming me through my daily confirmation email by running through my archives. Weird, the same zip file that misbehaved on 3.51 worked on 3.50.
Of course this would have been found at Mulesoft before letting the release into the wild. The only thing I can think of is I am using an FTP component toward the end of the flow processes, too. Dunno, but I do know that backing it back down to 3.50 made it behave.

Jad
  • 479
  • 2
  • 10
  • 23
Don Harrington
  • 87
  • 1
  • 11