I have digged a bit deeper.

The problem is that ftp files get's written in the wrong charset even if you
specify the charset to use on the ftp endpoint like
to("ftp://test:test@127.0.0.1:10017/?charset=iso-8859-1 or do a
convertBodyTo(String.class, "iso-8859-1") before sending to the ftp
endpoint.

The root probmel lies in FtpOperation.doStoreFile where the call to 
    if (is == null) {
        is = exchange.getIn().getMandatoryBody(InputStream.class);
    }
using DefaultTypeConverter.mandatoryConvertTo ends up calling
IOConverter.toInputStream which converts the body to the desired charset,
BUT relies on the charset from the Echange.properties as a CamelCharsetName
property.

The doStoreFile operation doesn't thake the charset endpoint property into
account when constructing the inputstream.


Up until camel 2.9.2 this worked because calling convertBodyTo(String,
"iso-8859-1") before sending to the ftp endpoint used ConvertBodyProcessor
that set the Exchange.CHARSET_NAME 

snip --

public void process(Exchange exchange) throws Exception {
        ....
        if (charset != null) {
            exchange.setProperty(Exchange.CHARSET_NAME,
IOHelper.normalizeCharset(charset));
        }
        ....

But from 2.9.3 there has been a change in the process method to
        ...
         // remove charset when we are done as we should not propagate that,
        // as that can lead to double converting later on
        if (charset != null) {
            exchange.removeProperty(Exchange.CHARSET_NAME);
        }
        ....

I think the FtpOperation.doStoreFile is missing the handeling of the charset
property like that implemented in the file component FileOperation.storeFile

A way to fix it is to change the doStoreFile ->

....
            if (is == null) {
                String charset = endpoint.getCharset();
                if (charset != null) {
                    is = new
ByteArrayInputStream(exchange.getIn().getBody(String.class).getBytes(charset));
                    log.trace("Using InputStream {} with charset {}.", is,
charset);
                } else {
                    is =
exchange.getIn().getMandatoryBody(InputStream.class);
                }
            }
....

But I guess that there is a more Camel way of converting the body to with
account to charset and content.

Best 

Preben




--
View this message in context: 
http://camel.465427.n5.nabble.com/Problem-w-FTP-producer-and-charset-tp5723604p5723793.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to