简体   繁体   中英

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):

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

instead of this (with 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)

Any thoughts? Suggestions?

I ended up creating a custom groovy script to do the conversion, and put it right after the inbound-endpoint.

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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