将Mule从CE-3.5升级到3.7.0会破坏文件编码

时间:2015-12-21 19:09:43

标签: java character-encoding mule

流速:

<sftp:inbound-endpoint
    connector-ref="sftpServer"
    host="${sftp.host}"
    port="${sftp.port}"
    path="${sftp.path}"
    user="${sftp.user}"
    password="${sftp.password}"
    responseTimeout="${standard.response.timeout.millis}"
    sizeCheckWaitTime="${sftp.sizeCheckWaitTime.millis}"
    pollingFrequency="${sftp.polling.frequency.millis}"
    autoDelete="false"
    encoding="UTF-16LE"
    doc:name="SFTPEndpoint">
    <file:filename-wildcard-filter pattern="${sftp.filename}" />
</sftp:inbound-endpoint>

<file:file-to-byte-array-transformer encoding="UTF-16LE" doc:name="Object to Byte Array" />
<byte-array-to-string-transformer encoding="UTF-8" doc:name="Byte Array to String"/>

只是版本号更改,我开始得到这个例外:

Message               : Cannot apply transformer FileToByteArray{this=74dda694, name='FileToByteArray', ignoreBadInput=false, returnClass=SimpleDataType{type=[B, mimeType='*/*', encoding='UTF-16LE'}, sourceTypes=[SimpleDataType{type=java.io.File, mimeType='*/*', encoding='null'}, SimpleDataType{type=java.io.FileInputStream, mimeType='*/*', encoding='null'}]} on source payload: class org.mule.transport.sftp.SftpInputStream (java.lang.IllegalArgumentException). Message payload is of type: SftpInputStream
Code                  : MULE_ERROR--2

所以我不得不改变这个:

<object-to-byte-array-transformer encoding="UTF-16LE" doc:name="Object to Byte Array" />
<byte-array-to-string-transformer encoding="UTF-8" doc:name="Object to Byte Array" />

其他所有设置完全相同,除非我现在得到这个(3.7.0):

T h i s   i s   a   t e s t   f i l e . 

而不是这个(3.5.0):

This is a test file.

在移动文件的最终版本中。这些不是空格字符,而是不可见的字符(我假设因为UTF16是双字节字符集)

有什么想法?建议?

1 个答案:

答案 0 :(得分:0)

我最终创建了一个自定义groovy脚本来进行转换,并将其放在入站端点之后。

<sftp:inbound-endpoint
    connector-ref="sftpServer"
    host="${sftp.host}"
    port="${sftp.port}"
    path="${sftp.path}"
    user="${sftp.user}"
    password="${sftp.password}"
    responseTimeout="${standard.response.timeout.millis}"
    sizeCheckWaitTime="${sftp.sizeCheckWaitTime.millis}"
    pollingFrequency="${sftp.polling.frequency.millis}"
    autoDelete="false"
    encoding="UTF-16LE"
    doc:name="SFTPEndpoint">
    <file:filename-wildcard-filter pattern="${sftp.filename}" />
</sftp:inbound-endpoint>

<scripting:transformer doc:name="Convert File Encoding">
  <scripting:script engine="Groovy" file="encodingConverter.groovy" />
</scripting:transformer>

<!-- Do flow stuff here -->

groovy脚本接收InputStream并输出转换后的文件。

相关问题