On 10/8/10 8:36 PM, Andreas A. wrote:
I have made this class to subsitute the<convertBodyTo> tags.
<from uri="file:/data/in" />
<bean ref="CharsetConverter" method="toExternalCharset" />
<bean ref="CharsetConverter" method="toInternalCharset" />
public class CharsetConverter {
public void toInternalCharset(Exchange exchange) throws Exception {
String internalCharset = Charset.defaultCharset().name();
you need to set the exchange property before call the
setBody(String.class), otherwise camel cannot know the right charset
should be use.
String converted = new
String(exchange.getIn().getBody(String.class).getBytes(), internalCharset);
exchange.getIn().setBody(converted);
exchange.setProperty(Exchange.CHARSET_NAME, internalCharset);
}
public void toExternalCharset(Exchange exchange) throws Exception {
String externalCharset =
exchange.getContext().resolvePropertyPlaceholders("{{charset.external}}");
System.out.println(externalCharset);
String converted = new
String(exchange.getIn().getBody(String.class).getBytes(), externalCharset);
exchange.getIn().setBody(converted);
exchange.setProperty(Exchange.CHARSET_NAME, externalCharset);
}
}
However this does not produce the same (correct) output as using
convertbodyto.
--
Willem
----------------------------------
Open Source Integration: http://www.fusesource.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.javaeye.com (Chinese)
Twitter: http://twitter.com/willemjiang