您的位置:首页 > 其它

Mule初次使用碰到的问题

2013-03-27 23:57 183 查看
  因为需要做个数据交换的东西,知道Mule这个东西,以前简单看过,一直没有用。以为拿个来用比较简单,谁知真正用起来碰到问题还真不少,又找不到人来讨论,真是麻烦。

需求:本地文件夹与FTP同步

  使用Mule版本:2.2.1

碰到的问题及解决方法:

1、不知道怎么在Java中嵌入mule。 

    代码:   

String configFile = "conf/mule-config.xml";
String[] configFileArr = new String[]{configFile};
MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
MuleContext context =
muleContextFactory.createMuleContext(new SpringXmlConfigurationBuilder(configFileArr));
context.start();


    配置:  

<?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、上传文件大于20M左右的时候,客户端便会断开连接,Mule运行报错。

    解决:

    在ftp:outbond-endpoint节点中增加

<object-to-byte-array-transformer />
 问题解决

    3、包含中文文件名的文件不能同步,FTP服务器中文乱码。

    这个问题困扰了我很久,花了我很多时间,还是没有解决得很特底,有时有效,有时无效。

    下载mule-transport-ftp源代码,修改FtpConnector.java

public OutputStream getOutputStream(ImmutableEndpoint endpoint, MuleMessage message)方法中
         // OutputStream out = client.storeFileStream(filename);
         修改为:
OutputStream out =
client.storeFileStream(new String(filename.getBytes("GBK"), "iso8859-1"));


下一步:一定要把mule搞透,使用3.X版本
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: