Because we need to do something about data exchange and know about the mule, which we have seen before and has never used. I thought it would be easy to use it. Who knows there are a lot of problems with it and there is no one to discuss.
Requirement: synchronize local folders with FTP
Use mule version: 2.2.1
Problems encountered and solutions:
1. I don't know how to embed mule in Java.
Code:
String configFile = "conf/mule-config.xml"; String[] configFileArr = new String[]{configFile}; MuleContextFactory muleContextFactory = new DefaultMuleContextFactory(); MuleContext context = muleContextFactory.createMuleContext(new SpringXmlConfigurationBuilder(configFileArr)); context.start();
Configuration:
<?xml version = "1.0" encoding = "UTF-8"?><mule xmlns="http://www.mulesource.org/schema/mule/core/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.2" xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2" xmlns:ftp="http://www.mulesource.org/schema/mule/ftp/2.2" xmlns:file="http://www.mulesource.org/schema/mule/file/2.2" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd http://www.mulesource.org/schema/mule/stdio/2.2 http://www.mulesource.org/schema/mule/stdio/2.2/mule-stdio.xsd http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd http://www.mulesource.org/schema/mule/file/2.2 http://www.mulesource.org/schema/mule/file/2.2/mule-file.xsd http://www.mulesource.org/schema/mule/ftp/2.2 http://www.mulesource.org/schema/mule/ftp/2.2/mule-ftp.xsd"> <file:connector name="fileConnector" pollingFrequency="6000" /> <ftp:connector name="ftpConnector"/> <model name="model"> <service name="service"> <inbound> <file:inbound-endpoint path="/e:/tmp" connector-ref="fileConnector"> </file:inbound-endpoint> </inbound> <outbound> <pass-through-router> <ftp:outbound-endpoint host="XXX.XXX.XXX.XXXX" port="21" user="3guser" password="3guser" outputPattern="#[ORIGINALNAME]" path="/tttt" connector-ref="ftpConnector"> </ftp:outbound-endpoint> </pass-through-router> </outbound> </service> </model></mule>
2. When the file to be uploaded is about 20 mb, the client will be disconnected and an error will be reported during mule operation.
Solution:
Add
<Object-to-byte-array-transformer/>
Problem Solving
3. files containing Chinese file names cannot be synchronized, and Chinese characters on the FTP server are garbled.
This problem has plagued me for a long time. It took me a lot of time, but it is still not solved very well. Sometimes it is effective and sometimes ineffective.
Download the mule-transport-FTP source code and modify ftpconnector. java.
In the public outputstream getoutputstream (immutableendpoint endpoint, mulemessage message) Method
// Outputstream out = client. storefilestream (filename );
Change to: outputstream out = client. storefilestream (new string (filename. getbytes ("GBK"), "iso8859-1 "));
Next step: Be sure to thoroughly understand the mule and use version 3.x.