This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.11.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.11.x by this push:
new b200430 CAMEL-17067 Not transforming body to String then bodyMT is
null (#6242)
b200430 is described below
commit b200430eb2909fd11398a475002cdff3d70c96fb
Author: henka-rl <[email protected]>
AuthorDate: Mon Oct 11 21:40:55 2021 +0200
CAMEL-17067 Not transforming body to String then bodyMT is null (#6242)
---
.../language/datasonnet/DatasonnetExpression.java | 2 +-
.../language/datasonnet/CamelDatasonnetTest.java | 22 ++++++++++++++++++++++
.../camel/language.datasonnet/camel-context.xml | 14 +++++++++++---
3 files changed, 34 insertions(+), 4 deletions(-)
diff --git
a/components/camel-datasonnet/src/main/java/org/apache/camel/language/datasonnet/DatasonnetExpression.java
b/components/camel-datasonnet/src/main/java/org/apache/camel/language/datasonnet/DatasonnetExpression.java
index 846229b..76a969b 100644
---
a/components/camel-datasonnet/src/main/java/org/apache/camel/language/datasonnet/DatasonnetExpression.java
+++
b/components/camel-datasonnet/src/main/java/org/apache/camel/language/datasonnet/DatasonnetExpression.java
@@ -113,7 +113,7 @@ public class DatasonnetExpression extends ExpressionAdapter
implements Expressio
Document<?> body;
if (exchange.getMessage().getBody() instanceof Document) {
body = (Document<?>) exchange.getMessage().getBody();
- } else if (MediaTypes.APPLICATION_JAVA.equalsTypeAndSubtype(bodyMT)) {
+ } else if (MediaTypes.APPLICATION_JAVA.equalsTypeAndSubtype(bodyMT) ||
bodyMT == null) {
body = new DefaultDocument<>(exchange.getMessage().getBody());
} else {
body = new
DefaultDocument<>(MessageHelper.extractBodyAsString(exchange.getMessage()),
bodyMT);
diff --git
a/components/camel-datasonnet/src/test/java/org/apache/camel/language/datasonnet/CamelDatasonnetTest.java
b/components/camel-datasonnet/src/test/java/org/apache/camel/language/datasonnet/CamelDatasonnetTest.java
index 6006648..5963796 100644
---
a/components/camel-datasonnet/src/test/java/org/apache/camel/language/datasonnet/CamelDatasonnetTest.java
+++
b/components/camel-datasonnet/src/test/java/org/apache/camel/language/datasonnet/CamelDatasonnetTest.java
@@ -118,6 +118,28 @@ public class CamelDatasonnetTest extends
CamelSpringTestSupport {
}
@Test
+ public void testReadJavaDatasonnetHeader() throws Exception {
+ Gizmo theGizmo = new Gizmo();
+ theGizmo.setName("gizmo");
+ theGizmo.setQuantity(123);
+ theGizmo.setInStock(true);
+ theGizmo.setColors(Arrays.asList("red", "white", "blue"));
+
+ Manufacturer manufacturer = new Manufacturer();
+ manufacturer.setManufacturerName("ACME Corp.");
+ manufacturer.setManufacturerCode("ACME123");
+ theGizmo.setManufacturer(manufacturer);
+
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+ df.setTimeZone(TimeZone.getTimeZone("UTC"));
+ theGizmo.setDate(df.parse("2020-01-06"));
+
+ runCamelTest(theGizmo,
+ loadResourceAsString("javaTest.json"),
+ "direct:readJavaDatasonnetHeader");
+ }
+
+ @Test
public void testWriteJava() throws Exception {
Gizmo theGizmo = new Gizmo();
theGizmo.setName("gizmo");
diff --git
a/components/camel-datasonnet/src/test/resources/org/apache/camel/language.datasonnet/camel-context.xml
b/components/camel-datasonnet/src/test/resources/org/apache/camel/language.datasonnet/camel-context.xml
index 0a9cac1..5575245 100644
---
a/components/camel-datasonnet/src/test/resources/org/apache/camel/language.datasonnet/camel-context.xml
+++
b/components/camel-datasonnet/src/test/resources/org/apache/camel/language.datasonnet/camel-context.xml
@@ -98,10 +98,10 @@
</datasonnet>
</transform>
- <to uri="mock:direct:end"/>
- </route>
+ <to uri="mock:direct:end"/>
+ </route>
- <route id="namedImports">
+ <route id="namedImports">
<from uri="direct:namedImports"/>
<transform>
<datasonnet bodyMediaType="application/json"
outputMediaType="application/json"
@@ -119,6 +119,14 @@
<to uri="mock:direct:end"/>
</route>
+ <route id="readJavaDatasonnetHeader">
+ <from uri="direct:readJavaDatasonnetHeader"/>
+ <transform>
+ <datasonnet outputMediaType="application/json"
resultType="java.lang.String">resource:classpath:readJavaTest.ds</datasonnet>
+ </transform>
+ <to uri="mock:direct:end"/>
+ </route>
+
<route id="writeJava">
<from uri="direct:writeJava"/>
<transform>