diff --git a/core/runtime/src/main/java/org/switchyard/runtime/util/ExchangeFormatter.java b/core/runtime/src/main/java/org/switchyard/runtime/util/ExchangeFormatter.java index ed1fada..e1ae301 100644 --- a/core/runtime/src/main/java/org/switchyard/runtime/util/ExchangeFormatter.java +++ b/core/runtime/src/main/java/org/switchyard/runtime/util/ExchangeFormatter.java @@ -89,7 +89,8 @@ public final class ExchangeFormatter { // check to see if we have to put content back into the message // after the conversion to string if (InputStream.class.isAssignableFrom(msg.getContent().getClass())) { - msg.setContent(new ByteArrayInputStream(content.getBytes())); + String charsetName = getCharsetName(exchange.getContext().getProperties(Scope.EXCHANGE)); + msg.setContent(new ByteArrayInputStream(charsetName != null ? content.getBytes(charsetName) : content.getBytes())); } else if (Reader.class.isAssignableFrom(msg.getContent().getClass())) { msg.setContent(new StringReader(content)); } @@ -105,6 +106,18 @@ public final class ExchangeFormatter { return body.toString(); } + private static String getCharsetName(Set properties) { + String charsetName = null; + for (Property property : properties) { + String name = property.getName(); + if("CamelCharsetName".equals(name)) { + charsetName = (String)property.getValue(); + break; + } + } + return charsetName; + } + private static void dumpContext(StringBuilder summary, Set properties) { Set orderedProperties = new TreeSet(new Comparator() { public int compare(Property p1, Property p2) {