You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by qu...@apache.org on 2018/02/20 01:18:59 UTC
[camel] branch master updated: CAMEL-12279 - restore
CamelCharsetName Exchange property if set before call to convertBodyTo with
Charset
This is an automated email from the ASF dual-hosted git repository.
quinn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new c7b93d9 CAMEL-12279 - restore CamelCharsetName Exchange property if set before call to convertBodyTo with Charset
c7b93d9 is described below
commit c7b93d9d4cdccf34fb543272c7bd9e507e2eb474
Author: Quinn Stevenson <qu...@apache.org>
AuthorDate: Mon Feb 19 18:16:05 2018 -0700
CAMEL-12279 - restore CamelCharsetName Exchange property if set before call to convertBodyTo with Charset
---
.../apache/camel/processor/ConvertBodyProcessor.java | 10 ++++++++--
.../org/apache/camel/processor/ConvertBodyTest.java | 19 +++++++++++++++++++
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java
index e2b334e..449aa9a 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java
@@ -87,7 +87,9 @@ public class ConvertBodyProcessor extends ServiceSupport implements AsyncProcess
return true;
}
+ String originalCharsetName = null;
if (charset != null) {
+ originalCharsetName = exchange.getProperty(Exchange.CHARSET_NAME, String.class);
// override existing charset with configured charset as that is what the user
// have explicit configured and expects to be used
exchange.setProperty(Exchange.CHARSET_NAME, charset);
@@ -117,10 +119,14 @@ public class ConvertBodyProcessor extends ServiceSupport implements AsyncProcess
old.setBody(value);
}
- // remove charset when we are done as we should not propagate that,
+ // remove or restore 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);
+ if (originalCharsetName != null && !originalCharsetName.isEmpty()) {
+ exchange.setProperty(Exchange.CHARSET_NAME, originalCharsetName);
+ } else {
+ exchange.removeProperty(Exchange.CHARSET_NAME);
+ }
}
callback.done(true);
diff --git a/camel-core/src/test/java/org/apache/camel/processor/ConvertBodyTest.java b/camel-core/src/test/java/org/apache/camel/processor/ConvertBodyTest.java
index af22643..8ac2961 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/ConvertBodyTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/ConvertBodyTest.java
@@ -25,6 +25,7 @@ import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
import org.apache.camel.InvalidPayloadException;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.ExchangeBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
@@ -60,6 +61,24 @@ public class ConvertBodyTest extends ContextTestSupport {
assertMockEndpointsSatisfied();
}
+ public void testConvertBodyCharsetWithExistingCharsetName() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ public void configure() {
+ from("direct:foo").convertBodyTo(byte[].class, "iso-8859-1").to("mock:foo");
+ }
+ });
+
+ getMockEndpoint("mock:foo").expectedMessageCount(1);
+ // do not propagate charset to avoid side effects with double conversion etc
+ getMockEndpoint("mock:foo").message(0).exchangeProperty(Exchange.CHARSET_NAME).isEqualTo("UTF-8");
+
+ Exchange srcExchange = ExchangeBuilder.anExchange(context).withProperty(Exchange.CHARSET_NAME, "UTF-8").withBody("Hello World").build();
+
+ template.send("direct:foo", srcExchange);
+
+ assertMockEndpointsSatisfied();
+ }
+
public void testConvertToInteger() throws Exception {
MockEndpoint result = getMockEndpoint("mock:result");
result.expectedBodiesReceived(11);
--
To stop receiving notification emails like this one, please contact
quinn@apache.org.