简体   繁体   English

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

[英]Upgrading Mule from CE-3.5 to 3.7.0 breaks file encoding

Flow: 流:

<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"/>

With just the version number change, I started getting this exception: 仅更改版本号,我就开始遇到此异常:

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

So I had to change this: 所以我不得不改变这个:

<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" />

Everything else is exactly the same setup, except now I'm getting this (with 3.7.0): 其他所有设置都完全相同,但是现在我有了(3.7.0):

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

instead of this (with 3.5.0): 而不是这个(使用3.5.0):

This is a test file.

In the final version of the moved file. 在已移动文件的最终版本中。 These are not space characters, but invisible characters (I assume because UTF16 is a double byte character set) 这些不是空格字符,而是不可见的字符(我想是因为UTF16是双字节字符集)

Any thoughts? 有什么想法吗? Suggestions? 建议?

I ended up creating a custom groovy script to do the conversion, and put it right after the inbound-endpoint. 我最终创建了一个自定义的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 -->

The groovy script takes in an InputStream and outputs the converted File. groovy脚本接收InputStream并输出转换后的File。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM