This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-27266 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 232936e24041386341c667ca90080b4482ba8a3d Author: Claus Ibsen <[email protected]> AuthorDate: Fri Nov 20 07:27:55 2026 +0100 CAMEL-27266: camel-core - the body types of the binary and text-plain data types say a null body stays null TypeConverterTransformer.transform returns early on a null body, so the binary (application-octet-stream) and text-plain data types leave it null and only set the Content-Type header, but their @BodyTypes said a null body fails. Add the null carrier to transformerIn and transformerOut of both, correct the descriptions, and regenerate the metadata and its catalog copy, which the YAML body type validator and the Camel CLI read. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../camel/catalog/transformers/application-octet-stream.json | 10 ++++++---- .../org/apache/camel/catalog/transformers/text-plain.json | 8 +++++--- .../apache/camel/transformer/application-octet-stream.json | 10 ++++++---- .../services/org/apache/camel/transformer/text-plain.json | 8 +++++--- .../processor/transformer/ByteArrayDataTypeTransformer.java | 12 ++++++------ .../processor/transformer/StringDataTypeTransformer.java | 5 +++-- .../transformer/ByteArrayDataTypeTransformerTest.java | 10 ++++++++-- .../processor/transformer/StringDataTypeTransformerTest.java | 8 +++++++- 8 files changed, 46 insertions(+), 25 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/application-octet-stream.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/application-octet-stream.json index 441d22a5f079..5ca07d00c114 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/application-octet-stream.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/application-octet-stream.json @@ -15,16 +15,18 @@ "text", "bytes", "stream", - "file" + "file", + "null" ], - "description": "A body Camel can convert to a byte array: a number or a null body fails" + "description": "A body Camel can convert to a byte array: a number fails, and a null body stays null" }, "transformerOut": { "carriers": [ "bytes", - "stream" + "stream", + "null" ], - "description": "A stream cache body is kept as it is; any other body becomes a byte array" + "description": "A stream cache body is kept as it is and a null body stays null; any other body becomes a byte array" } } } diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/text-plain.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/text-plain.json index 758557daf893..35a266658010 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/text-plain.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/text-plain.json @@ -14,13 +14,15 @@ "carriers": [ "any" ], - "description": "A body Camel can convert to a String, which a null body is not" + "description": "A body Camel can convert to a String; a null body stays null" }, "transformerOut": { "carriers": [ - "text" + "text", + "null" ], - "javaType": "java.lang.String" + "javaType": "java.lang.String", + "description": "A String, or null for a null body" } } } diff --git a/core/camel-core-processor/src/generated/resources/META-INF/services/org/apache/camel/transformer/application-octet-stream.json b/core/camel-core-processor/src/generated/resources/META-INF/services/org/apache/camel/transformer/application-octet-stream.json index 441d22a5f079..5ca07d00c114 100644 --- a/core/camel-core-processor/src/generated/resources/META-INF/services/org/apache/camel/transformer/application-octet-stream.json +++ b/core/camel-core-processor/src/generated/resources/META-INF/services/org/apache/camel/transformer/application-octet-stream.json @@ -15,16 +15,18 @@ "text", "bytes", "stream", - "file" + "file", + "null" ], - "description": "A body Camel can convert to a byte array: a number or a null body fails" + "description": "A body Camel can convert to a byte array: a number fails, and a null body stays null" }, "transformerOut": { "carriers": [ "bytes", - "stream" + "stream", + "null" ], - "description": "A stream cache body is kept as it is; any other body becomes a byte array" + "description": "A stream cache body is kept as it is and a null body stays null; any other body becomes a byte array" } } } diff --git a/core/camel-core-processor/src/generated/resources/META-INF/services/org/apache/camel/transformer/text-plain.json b/core/camel-core-processor/src/generated/resources/META-INF/services/org/apache/camel/transformer/text-plain.json index 758557daf893..35a266658010 100644 --- a/core/camel-core-processor/src/generated/resources/META-INF/services/org/apache/camel/transformer/text-plain.json +++ b/core/camel-core-processor/src/generated/resources/META-INF/services/org/apache/camel/transformer/text-plain.json @@ -14,13 +14,15 @@ "carriers": [ "any" ], - "description": "A body Camel can convert to a String, which a null body is not" + "description": "A body Camel can convert to a String; a null body stays null" }, "transformerOut": { "carriers": [ - "text" + "text", + "null" ], - "javaType": "java.lang.String" + "javaType": "java.lang.String", + "description": "A String, or null for a null body" } } } diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/transformer/ByteArrayDataTypeTransformer.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/transformer/ByteArrayDataTypeTransformer.java index 211fb9a13955..7d734cbe40bc 100644 --- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/transformer/ByteArrayDataTypeTransformer.java +++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/transformer/ByteArrayDataTypeTransformer.java @@ -32,12 +32,12 @@ import org.apache.camel.spi.Transformer; * read from a bucket, is not read into memory. Any other stream is read into a byte array, as it may be read only once. */ @DataTypeTransformer(name = "application-octet-stream") -@BodyTypes(transformerIn = @BodyType(value = { Carrier.TEXT, Carrier.BYTES, Carrier.STREAM, Carrier.FILE }, - description = "A body Camel can convert to a byte array: a number or a null body" - + " fails"), - transformerOut = @BodyType(value = { Carrier.BYTES, Carrier.STREAM }, - description = "A stream cache body is kept as it is; any other body becomes a" - + " byte array")) +@BodyTypes(transformerIn = @BodyType(value = { Carrier.TEXT, Carrier.BYTES, Carrier.STREAM, Carrier.FILE, Carrier.NULL }, + description = "A body Camel can convert to a byte array: a number fails, and a null" + + " body stays null"), + transformerOut = @BodyType(value = { Carrier.BYTES, Carrier.STREAM, Carrier.NULL }, + description = "A stream cache body is kept as it is and a null body stays null;" + + " any other body becomes a byte array")) public class ByteArrayDataTypeTransformer extends Transformer { private static final Transformer DELEGATE = new TypeConverterTransformer(byte[].class); diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/transformer/StringDataTypeTransformer.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/transformer/StringDataTypeTransformer.java index 5f8b5d679774..85e4140a3c3b 100644 --- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/transformer/StringDataTypeTransformer.java +++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/transformer/StringDataTypeTransformer.java @@ -34,8 +34,9 @@ import org.apache.camel.spi.Transformer; */ @DataTypeTransformer(name = "text-plain") @BodyTypes(transformerIn = @BodyType(value = Carrier.ANY, - description = "A body Camel can convert to a String, which a null body is not"), - transformerOut = @BodyType(value = Carrier.TEXT, javaType = "java.lang.String")) + description = "A body Camel can convert to a String; a null body stays null"), + transformerOut = @BodyType(value = { Carrier.TEXT, Carrier.NULL }, javaType = "java.lang.String", + description = "A String, or null for a null body")) public class StringDataTypeTransformer extends Transformer { private static final Transformer DELEGATE = new TypeConverterTransformer(String.class); diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/transformer/ByteArrayDataTypeTransformerTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/transformer/ByteArrayDataTypeTransformerTest.java index f76820620bf7..6cd3e927987f 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/transformer/ByteArrayDataTypeTransformerTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/transformer/ByteArrayDataTypeTransformerTest.java @@ -37,6 +37,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -127,9 +128,9 @@ public class ByteArrayDataTypeTransformerTest { void theBodyTypesSayTheBody() throws Exception { // CAMEL-25928: a payload, as transformerIn says, and the body transformerOut says BodyTypes bodyTypes = ByteArrayDataTypeTransformer.class.getAnnotation(BodyTypes.class); - assertEquals(List.of(Carrier.TEXT, Carrier.BYTES, Carrier.STREAM, Carrier.FILE), + assertEquals(List.of(Carrier.TEXT, Carrier.BYTES, Carrier.STREAM, Carrier.FILE, Carrier.NULL), List.of(bodyTypes.transformerIn().value())); - assertEquals(List.of(Carrier.BYTES, Carrier.STREAM), List.of(bodyTypes.transformerOut().value())); + assertEquals(List.of(Carrier.BYTES, Carrier.STREAM, Carrier.NULL), List.of(bodyTypes.transformerOut().value())); for (Object body : List.of("Test", "Test".getBytes(StandardCharsets.UTF_8))) { Exchange exchange = new DefaultExchange(camelContext); exchange.getMessage().setBody(body); @@ -141,6 +142,11 @@ public class ByteArrayDataTypeTransformerTest { .setBody(new ByteArrayInputStreamCache(new ByteArrayInputStream("Test".getBytes(StandardCharsets.UTF_8)))); transformer.transform(stream.getMessage(), DataType.ANY, DataType.ANY); assertInstanceOf(ByteArrayInputStreamCache.class, stream.getMessage().getBody()); + // a null body stays null, as transformerOut says, and gets the content type + Exchange empty = new DefaultExchange(camelContext); + transformer.transform(empty.getMessage(), DataType.ANY, DataType.ANY); + assertNull(empty.getMessage().getBody()); + assertEquals("application/octet-stream", empty.getMessage().getHeader(Exchange.CONTENT_TYPE)); // a number is not a payload Exchange exchange = new DefaultExchange(camelContext); exchange.getMessage().setBody(5); diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/transformer/StringDataTypeTransformerTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/transformer/StringDataTypeTransformerTest.java index ab8e6b3d8bb6..5deda58e7cba 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/transformer/StringDataTypeTransformerTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/transformer/StringDataTypeTransformerTest.java @@ -34,6 +34,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNull; public class StringDataTypeTransformerTest { @@ -95,7 +96,7 @@ public class StringDataTypeTransformerTest { // CAMEL-25928: any body Camel converts, as transformerIn says, and the body transformerOut says BodyTypes bodyTypes = StringDataTypeTransformer.class.getAnnotation(BodyTypes.class); assertEquals(Carrier.ANY, bodyTypes.transformerIn().value()[0]); - assertEquals(Carrier.TEXT, bodyTypes.transformerOut().value()[0]); + assertEquals(List.of(Carrier.TEXT, Carrier.NULL), List.of(bodyTypes.transformerOut().value())); assertEquals(String.class.getCanonicalName(), bodyTypes.transformerOut().javaType()); for (Object body : List.of("Test", "Test".getBytes(StandardCharsets.UTF_8), new ByteArrayInputStream("Test".getBytes(StandardCharsets.UTF_8)), 5)) { @@ -104,6 +105,11 @@ public class StringDataTypeTransformerTest { transformer.transform(exchange.getMessage(), DataType.ANY, DataType.ANY); assertInstanceOf(String.class, exchange.getMessage().getBody(), body.getClass().getName()); } + // a null body stays null, as transformerOut says, and gets the content type + Exchange empty = new DefaultExchange(camelContext); + transformer.transform(empty.getMessage(), DataType.ANY, DataType.ANY); + assertNull(empty.getMessage().getBody()); + assertEquals("text/plain", empty.getMessage().getHeader(Exchange.CONTENT_TYPE)); } private static void assertStringBody(Exchange exchange, String key, String content) {
