in library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/avro/AvroBinaryDataType.java [43:61]
public void convert(Exchange exchange) {
AvroSchema schema = exchange.getProperty(SchemaHelper.CONTENT_SCHEMA, AvroSchema.class);
if (schema == null) {
throw new CamelExecutionException("Missing proper avro schema for data type processing", exchange);
}
try {
byte[] marshalled = Avro.MAPPER.writer().forType(JsonNode.class).with(schema)
.writeValueAsBytes(getBodyAsJsonNode(exchange, schema));
exchange.getMessage().setBody(marshalled);
exchange.getMessage().setHeader(Exchange.CONTENT_TYPE, MimeType.AVRO_BINARY.type());
exchange.getMessage().setHeader(SchemaHelper.CONTENT_SCHEMA,
exchange.getProperty(SchemaHelper.CONTENT_SCHEMA, "", String.class));
} catch (InvalidPayloadException | IOException e) {
throw new CamelExecutionException("Failed to apply Avro binary data type on exchange", exchange, e);
}
}