Mule 3.4.0中对Ftp协议的上传下载的应用
1. 前言
一直都听说 Mule 对 Ftp 和 Http 协议的支持很好,于是就关注了一下。
Mule 通过一系列的配置文件的配置就可以完成对 Ftp 服务器的下载和上传 ,这个还是很神奇的。
但是可惜的是, Mule 本身并不支持 FtpS 协议,只支持 SFTP ,这样对于工业级的使用上,未免有点不方便 。
2. Mule 3.x 的基本知识
Mule 是一个开源的 ESB 软件,基本概念如下:
| http://tech.ddvip.com/2010-05/1274838569154227.html |
Mule 3.X 中对 Ftp 的支持是通过 < ftp:connector> 等标签实现的,具体的官方信息如下:
| http://www.mulesoft.org/documentation/display/MULE3USER/FTP+Transport |
下载实现
mule-download-config.xml
1. version="1.0" encoding="UTF-8"?>
2.
3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4. xmlns:spring="http://www.springframework.org/schema/beans"
5. xmlns:ftp="http://www.mulesoft.org/schema/mule/ftp"
6. xmlns:file="http://www.mulesoft.org/schema/mule/file"
7. xsi:schemaLocation="
8. http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
9. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
10. http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
11. http://www.mulesoft.org/schema/mule/ftp http://www.mulesoft.org/schema/mule/ftp/current/mule-ftp.xsd">
12.
15.
16.
19.
20.
21.
22.
23.
26.
27. connector-ref = "fileConnector" >
28.
29.
30.
31.
34.
35.
36. port = "21" user = "root" password = "123456" path = "/home/test" connector-ref = "ftpConnector" />
37.
38.
39.
40.
41.
42.
43.
测试
1. import org.mule.api.MuleContext;
2. import org.mule.api.MuleException;
3. import org.mule.api.context.MuleContextFactory;
4. import org.mule.config.spring.SpringXmlConfigurationBuilder;
5. import org.mule.context.DefaultMuleContextFactory;
6.
7. /**
8. * 检查是否发布成功的请求路径为:
9. * http://localhost:9090/hello?wsdl
10. * 功能描述,该部分必须以中文句号结尾。
11. *
12. * 创建日期 2013-8-16
13. * @author $Author$
14. * @version $Revision$ $Date$
15. * @since 3.0.0
16. */
17. public class MuleFtpUploadMain {
18. public static void main(String[] args) {
19. try {
20. String configFile = "mule-upload-config.xml";
21. String[] configFileArr = new String[] {configFile };
22. MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
23. MuleContext context = muleContextFactory
24. .createMuleContext(new SpringXmlConfigurationBuilder(configFileArr));
25. context.start();
26. } catch (MuleException t) {
27. t.printStackTrace();
28. }
29. }
30. }
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
