This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 94ca50181230 CAMEL-25736: YAML examples for the data formats and
languages that had none (#28023)
94ca50181230 is described below
commit 94ca50181230a837ffb3fba1b6dc0da2c292c068
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Oct 17 18:17:11 2026 +0200
CAMEL-25736: YAML examples for the data formats and languages that had none
(#28023)
Second part of CAMEL-25736: camel_catalog_sample reads its samples from the
documentation, which had no YAML route example for these data formats and
languages.
- YAML examples for 14 data formats on 12 pages (asn1, barcode, bindy,
crypto,
fhirJson, fhirXml, flatpack, fory, jaxb, jsonApi, mimeMultipart,
parquetAvro)
and for the js, openfeature and python languages, checked against the code
(the crypto key as a bean, unmarshalType on marshal for parquetAvro and
fory,
the locale of bindy) and run with camel run.
- The flatpack Java examples are fixed.
- CatalogSamples puts the samples of the asked data format first, for the
pages
that show several (univocity, bindy).
- The catalog copies of the pages are updated.
Data formats with a sample of their own: 56 of 56 (42 before); languages:
28 of
29 (all but file, on purpose).
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../apache/camel/catalog/docs/asn1-dataformat.adoc | 75 ++++++++++-
.../camel/catalog/docs/barcode-dataformat.adoc | 50 ++++++-
.../camel/catalog/docs/bindy-dataformat.adoc | 88 +++++++++++++
.../camel/catalog/docs/crypto-dataformat.adoc | 146 +++++++++++++++++++++
.../camel/catalog/docs/fhirJson-dataformat.adoc | 22 ++++
.../camel/catalog/docs/fhirXml-dataformat.adoc | 22 ++++
.../camel/catalog/docs/flatpack-dataformat.adoc | 59 +++++++--
.../apache/camel/catalog/docs/fory-dataformat.adoc | 26 ++++
.../apache/camel/catalog/docs/jaxb-dataformat.adoc | 72 ++++++++++
.../org/apache/camel/catalog/docs/js-language.adoc | 40 ++++++
.../camel/catalog/docs/jsonApi-dataformat.adoc | 28 ++++
.../catalog/docs/mimeMultipart-dataformat.adoc | 45 ++++++-
.../camel/catalog/docs/openfeature-language.adoc | 116 +++++++++++++++-
.../camel/catalog/docs/parquetAvro-dataformat.adoc | 47 ++++++-
.../apache/camel/catalog/docs/python-language.adoc | 40 ++++++
.../camel-asn1/src/main/docs/asn1-dataformat.adoc | 75 ++++++++++-
.../src/main/docs/barcode-dataformat.adoc | 50 ++++++-
.../src/main/docs/bindy-dataformat.adoc | 88 +++++++++++++
.../src/main/docs/crypto-dataformat.adoc | 146 +++++++++++++++++++++
.../src/main/docs/fhirJson-dataformat.adoc | 22 ++++
.../src/main/docs/fhirXml-dataformat.adoc | 22 ++++
.../src/main/docs/flatpack-dataformat.adoc | 59 +++++++--
.../camel-fory/src/main/docs/fory-dataformat.adoc | 26 ++++
.../src/main/docs/js-language.adoc | 40 ++++++
.../camel-jaxb/src/main/docs/jaxb-dataformat.adoc | 72 ++++++++++
.../src/main/docs/jsonApi-dataformat.adoc | 28 ++++
.../src/main/docs/mimeMultipart-dataformat.adoc | 45 ++++++-
.../src/main/docs/openfeature-language.adoc | 116 +++++++++++++++-
.../src/main/docs/parquetAvro-dataformat.adoc | 47 ++++++-
.../src/main/docs/python-language.adoc | 40 ++++++
.../dsl/jbang/core/commands/ai/CatalogSamples.java | 24 +++-
.../jbang/core/commands/ai/CatalogSamplesTest.java | 30 ++++-
32 files changed, 1760 insertions(+), 46 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/asn1-dataformat.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/asn1-dataformat.adoc
index 28a8a0890847..da053284c8fb 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/asn1-dataformat.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/asn1-dataformat.adoc
@@ -25,18 +25,39 @@ There are 3 different ways to unmarshal ASN.1 structured
messages. (Usually bina
In this first example, we unmarshal BER file payload to OutputStream and send
it to mock endpoint.
-._Java-only: uses the asn1 data format object directly_
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct:unmarshal").unmarshal(asn1).to("mock:unmarshal");
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:unmarshal
+ steps:
+ - unmarshal:
+ asn1: {}
+ - to:
+ uri: mock:unmarshal
+----
+====
+
In the second example, we unmarshal BER file payload to a byte array using
Split EIP.
The reason for applying Split EIP is that usually each BER file or (ASN.1
structured file) contains multiple records to process and Split EIP helps us to
get each record in a file as byte arrays which is actually ASN1Primitive's
instance (by the use of Bouncy Castle's ASN.1 support in bcprov-jdk18on library)
Byte arrays then may be converted to ASN1Primitive by the help of public
static method in (ASN1Primitive.fromByteArray)
In such example, note that you need to set `usingIterator=true`
-._Java-only: uses the asn1 data format object and Split EIP with bodyAs_
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct:unmarshal")
@@ -45,13 +66,38 @@ from("direct:unmarshal")
.to("mock:unmarshal");
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:unmarshal
+ steps:
+ - unmarshal:
+ asn1:
+ usingIterator: true
+ - split:
+ expression:
+ simple:
+ expression: "${body}"
+ streaming: true
+ steps:
+ - to:
+ uri: mock:unmarshal
+----
+====
+
In the last example, we unmarshalled a BER file payload to plain old Java
Objects using Split EIP. The reason for applying Split EIP is already mentioned
in the previous example. Please note and keep in mind that reason. In such
example we also need to set the fully qualified name of the class or
<YourObject>.class reference through data format.
The important thing to note here is that your object should have been
generated by jasn1 compiler, which is a nice tool to generate java object
representations of your ASN.1 structure.
For the reference usage of jasn1 compiler, see the
https://www.beanit.com/asn1/[JASN.1 Project Page] and please also see how the
compiler is invoked with the help of maven's exec plugin.
For example, in this data format's unit tests an example ASN.1
structure(TestSMSBerCdr.asn1) is added in `src/test/resources/asn1_structure`.
jasn1 compiler is invoked, and java object's representations are generated in
`$\{basedir}/target/generated/src/test/java`
The nice thing about this example, you will get POJO instance at the mock
endpoint or at whatever your endpoint is.
-._Java-only: uses unmarshal with class name and Split EIP with bodyAs_
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct:unmarshaldsl")
@@ -61,6 +107,29 @@ from("direct:unmarshaldsl")
.to("mock:unmarshaldsl");
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:unmarshaldsl
+ steps:
+ - unmarshal:
+ asn1:
+ unmarshalType:
org.apache.camel.dataformat.asn1.model.testsmscbercdr.SmsCdr
+ usingIterator: true
+ - split:
+ expression:
+ simple:
+ expression: "${body}"
+ streaming: true
+ steps:
+ - to:
+ uri: mock:unmarshaldsl
+----
+====
+
== Dependencies
To use ASN.1 data format in your camel routes you need to add a dependency on
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/barcode-dataformat.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/barcode-dataformat.adoc
index 5dd023395359..41028e186796 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/barcode-dataformat.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/barcode-dataformat.adoc
@@ -39,9 +39,9 @@ the download page for the latest versions).
include::partial$dataformat-options.adoc[]
// dataformat options: END
-== Using the Java DSL
+== Usage
-First, you have to initialize the barcode data format class.
+In Java, you first create an instance of the barcode data format class.
You can use the default constructor, or one of parameterized (see JavaDoc).
The default values are:
@@ -82,7 +82,10 @@ For possible hints, please consult the ZXing documentation.
=== Marshalling
-._Java-only: route using Java data format variable_
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct://code")
@@ -90,6 +93,25 @@ from("direct://code")
.to("file://barcode_out");
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct://code
+ steps:
+ - marshal:
+ barcode:
+ barcodeFormat: QR_CODE
+ imageType: PNG
+ width: 100
+ height: 100
+ - to:
+ uri: file://barcode_out
+----
+====
+
You can call the route from a test class with:
._Java-only: Java test API (ProducerTemplate)_
@@ -108,7 +130,10 @@ The unmarshaller is generic.
For unmarshalling, you can use any BarcodeDataFormat instance.
If you've two instances, one for (generating) QR-Code and one for PDF417, it
doesn't matter which one will be used.
-._Java-only: route using Java data format variable_
+[tabs]
+====
+Java::
++
[source,java]
----
from("file://barcode_in?noop=true")
@@ -116,6 +141,23 @@ from("file://barcode_in?noop=true")
.to("mock:out");
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: file://barcode_in
+ parameters:
+ noop: true
+ steps:
+ - unmarshal:
+ barcode: {}
+ - to:
+ uri: mock:out
+----
+====
+
If you'll paste the QR-Code image above into the 'barcode_in' folder,
you should find _`This is a testmessage!`_ inside the mock.
You can find the barcode data format as header variable:
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/bindy-dataformat.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/bindy-dataformat.adoc
index d0a25d54ff6e..83c6f9946c0b 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/bindy-dataformat.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/bindy-dataformat.adoc
@@ -2031,6 +2031,94 @@ Please verify that your model classes implement
serializable otherwise
the queue manager will raise an error.
====
+=== Using the YAML DSL
+
+In the YAML DSL, the data format is `bindy`, and its `type` is `Csv`, `Fixed`
or `KeyValue`.
+The `classType` is the model class.
+
+The following route reads CSV files, unmarshals them into a list of `Order`
objects,
+and splits the list to handle one order at a time:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: file:inbox
+ steps:
+ - unmarshal:
+ bindy:
+ type: Csv
+ classType: com.acme.model.Order
+ - split:
+ expression:
+ simple:
+ expression: "${body}"
+ steps:
+ - to:
+ uri: direct:handleSingleOrder
+----
+
+To write CSV records, marshal a list of model objects.
+Set the `locale` when the numbers and dates must not depend on the machine:
without it, Bindy uses the default locale
+of the JVM, and on a machine with a Danish or German locale `2500.45` is
written as `2500,45`.
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:handleOrders
+ steps:
+ - marshal:
+ bindy:
+ type: Csv
+ classType: com.acme.model.Order
+ locale: en-US
+ - to:
+ uri: file:outbox
+----
+
+Fixed-length records work the same way, with the type `Fixed`:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: file:inbox/fixed
+ steps:
+ - unmarshal:
+ bindy:
+ type: Fixed
+ classType: com.acme.model.fixed.Order
+ - split:
+ expression:
+ simple:
+ expression: "${body}"
+ steps:
+ - to:
+ uri: direct:handleSingleOrder
+----
+
+For key-value pairs, such as FIX messages, the type is `KeyValue`.
+As in the Spring XML example, you can define the data format once in
`dataFormats` and use it by its id:
+
+[source,yaml]
+----
+- dataFormats:
+ - bindy:
+ id: fixOrder
+ type: KeyValue
+ classType: com.acme.model.fix.Order
+- route:
+ from:
+ uri: file:inbox/fix
+ steps:
+ - unmarshal:
+ custom:
+ ref: fixOrder
+ - to:
+ uri: direct:handleFixOrder
+----
+
== Dependencies
To use Bindy in your camel routes, you need to add a dependency on
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/crypto-dataformat.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/crypto-dataformat.adoc
index d593c0599e27..37d1c979e451 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/crypto-dataformat.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/crypto-dataformat.adoc
@@ -66,6 +66,34 @@ In Spring the dataformat is configured first and then used
in routes
</camelContext>
----
+In the YAML DSL, the key is a bean that the data format refers to by name.
+Here the bean is a new DES key, made by a Groovy script when the application
starts:
+
+[source,yaml]
+----
+- beans:
+ - name: desKey
+ type: javax.crypto.SecretKey
+ scriptLanguage: groovy
+ script: "javax.crypto.KeyGenerator.getInstance('DES').generateKey()"
+- route:
+ from:
+ uri: direct:basic-encryption
+ steps:
+ - marshal:
+ crypto:
+ algorithm: DES
+ key: desKey
+ - to:
+ uri: mock:encrypted
+ - unmarshal:
+ crypto:
+ algorithm: DES
+ key: desKey
+ - to:
+ uri: mock:unencrypted
+----
+
== Specifying the Encryption Algorithm
@@ -154,6 +182,42 @@ Spring XML::
<crypto id="inline-decrypt" algorithm="DES/CBC/PKCS5Padding" key="desKey"
inline="true" />
----
+YAML::
++
+[source,yaml]
+----
+- beans:
+ - name: initializationVector
+ scriptLanguage: groovy
+ script: "[0, 1, 2, 3, 4, 5, 6, 7] as byte[]"
+- dataFormats:
+ - crypto:
+ id: inline
+ algorithm: DES/CBC/PKCS5Padding
+ key: desKey
+ initVector: initializationVector
+ inline: true
+ - crypto:
+ id: inline-decrypt
+ algorithm: DES/CBC/PKCS5Padding
+ key: desKey
+ inline: true
+- route:
+ from:
+ uri: direct:inline
+ steps:
+ - marshal:
+ custom:
+ ref: inline
+ - to:
+ uri: mock:encrypted
+ - unmarshal:
+ custom:
+ ref: inline-decrypt
+ - to:
+ uri: mock:unencrypted
+----
+
====
For more information about the use of Initialization Vectors, consult
@@ -191,6 +255,32 @@ Spring XML::
<crypto id="hmac" algorithm="DES" key="desKey" shouldAppendHMAC="true" />
----
+YAML::
++
+[source,yaml]
+----
+- dataFormats:
+ - crypto:
+ id: hmac
+ algorithm: DES
+ key: desKey
+ shouldAppendHMAC: true
+- route:
+ from:
+ uri: direct:hmac
+ steps:
+ - marshal:
+ custom:
+ ref: hmac
+ - to:
+ uri: mock:encrypted
+ - unmarshal:
+ custom:
+ ref: hmac
+ - to:
+ uri: mock:unencrypted
+----
+
====
By default, the HMAC is calculated using the HmacSHA1 mac algorithm, though
this can be easily changed by supplying a different algorithm name. See here
for how to check what algorithms are available through the configured security
providers
@@ -221,6 +311,33 @@ Spring XML::
<crypto id="hmac-algorithm" algorithm="DES" key="desKey"
macAlgorithm="HmacMD5" shouldAppendHMAC="true" />
----
+YAML::
++
+[source,yaml]
+----
+- dataFormats:
+ - crypto:
+ id: hmac-algorithm
+ algorithm: DES
+ key: desKey
+ macAlgorithm: HmacMD5
+ shouldAppendHMAC: true
+- route:
+ from:
+ uri: direct:hmac-algorithm
+ steps:
+ - marshal:
+ custom:
+ ref: hmac-algorithm
+ - to:
+ uri: mock:encrypted
+ - unmarshal:
+ custom:
+ ref: hmac-algorithm
+ - to:
+ uri: mock:unencrypted
+----
+
====
== Supplying Keys Dynamically
@@ -265,6 +382,35 @@ Spring XML::
<crypto id="nokey" algorithm="DES" />
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:key-in-header-encrypt
+ steps:
+ - marshal:
+ crypto:
+ algorithm: DES
+ # remove the key so it does not leak with the message
+ - removeHeader:
+ name: CamelCryptoKey
+ - to:
+ uri: mock:encrypted
+- route:
+ from:
+ uri: direct:key-in-header-decrypt
+ steps:
+ - unmarshal:
+ crypto:
+ algorithm: DES
+ - removeHeader:
+ name: CamelCryptoKey
+ - to:
+ uri: mock:unencrypted
+----
+
====
== Dependencies
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/fhirJson-dataformat.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/fhirJson-dataformat.adoc
index de217cdf6bd9..4d3c3347c2ec 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/fhirJson-dataformat.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/fhirJson-dataformat.adoc
@@ -18,3 +18,25 @@ JSON parser to parse to/from JSON format to/from a
HAPI-FHIR's `IBaseResource`.
// dataformat options: START
include::partial$dataformat-options.adoc[]
// dataformat options: END
+
+== Usage
+
+The following route parses a FHIR resource from JSON and writes it as XML.
+The `fhirVersion` must match the version of the resources (R4 is the default):
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:patient
+ steps:
+ - unmarshal:
+ fhirJson:
+ fhirVersion: R4
+ - marshal:
+ fhirXml:
+ fhirVersion: R4
+ prettyPrint: true
+ - to:
+ uri: mock:result
+----
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/fhirXml-dataformat.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/fhirXml-dataformat.adoc
index e744e8fd0ace..a3c074e97eb9 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/fhirXml-dataformat.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/fhirXml-dataformat.adoc
@@ -18,3 +18,25 @@ XML parser to parse to/from XML format to/from a HAPI-FHIR's
`IBaseResource`.
// dataformat options: START
include::partial$dataformat-options.adoc[]
// dataformat options: END
+
+== Usage
+
+The following route parses a FHIR resource from XML and writes it as JSON.
+The `fhirVersion` must match the version of the resources (R4 is the default):
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:patient
+ steps:
+ - unmarshal:
+ fhirXml:
+ fhirVersion: R4
+ - marshal:
+ fhirJson:
+ fhirVersion: R4
+ prettyPrint: true
+ - to:
+ uri: mock:result
+----
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/flatpack-dataformat.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/flatpack-dataformat.adoc
index ba58200fa9a8..dd98ab9244b1 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/flatpack-dataformat.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/flatpack-dataformat.adoc
@@ -33,34 +33,75 @@ include::partial$dataformat-options.adoc[]
== Usage
-To use the data format, instantiate an instance and invoke the
-marshal or unmarshal operation in the route builder:
+To use the data format, set it on the marshal or unmarshal step of the route:
-._Java-only: programmatic FlatpackDataFormat configuration and unmarshal_
+[tabs]
+====
+Java::
++
[source,java]
----
- FlatpackDataFormat fp = new FlatpackDataFormat();
- fp.setDefinition(new ClassPathResource("INVENTORY-Delimited.pzmap.xml"));
- ...
- from("file:order/in").unmarshal(df).to("seda:queue:neworder");
+FlatpackDataFormat fp = new FlatpackDataFormat();
+fp.setDefinition("INVENTORY-Delimited.pzmap.xml");
+
+from("file:order/in").unmarshal(fp).to("seda:neworder");
+----
+
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: file:order/in
+ steps:
+ - unmarshal:
+ flatpack:
+ definition: INVENTORY-Delimited.pzmap.xml
+ - to:
+ uri: seda:neworder
----
+====
The sample above will read files from the `order/in` folder and
unmarshal the input using the Flatpack configuration file
`INVENTORY-Delimited.pzmap.xml` that configures the structure of the
files. The result is a `DataSetList` object we store on the SEDA queue.
-._Java-only: programmatic FlatpackDataFormat configuration and marshal_
+[tabs]
+====
+Java::
++
[source,java]
----
FlatpackDataFormat df = new FlatpackDataFormat();
-df.setDefinition(new ClassPathResource("PEOPLE-FixedLength.pzmap.xml"));
+df.setDefinition("PEOPLE-FixedLength.pzmap.xml");
df.setFixed(true);
df.setIgnoreFirstRecord(false);
from("seda:people").marshal(df).convertBodyTo(String.class).to("jms:queue:people");
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: seda:people
+ steps:
+ - marshal:
+ flatpack:
+ definition: PEOPLE-FixedLength.pzmap.xml
+ fixed: true
+ ignoreFirstRecord: false
+ - convertBodyTo:
+ type: java.lang.String
+ - to:
+ uri: jms:queue:people
+----
+====
+
In the code above we marshal the data from an Object representation as a
`List` of rows as `Maps`. The rows as `Map` contains the column name as
the key, and the corresponding value. This structure can be created
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/fory-dataformat.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/fory-dataformat.adoc
index 4783ba03ea23..00f799e0aa70 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/fory-dataformat.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/fory-dataformat.adoc
@@ -22,6 +22,32 @@ Apache Fory is not supporting architecture using Big Endian
(s390x, for instance
include::partial$dataformat-options.adoc[]
// dataformat options: END
+== Usage
+
+Fory only serializes registered classes by default
(`requireClassRegistration`).
+The data format registers the `unmarshalType` class, so set it on marshal as
well as on unmarshal:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:marshal
+ steps:
+ - marshal:
+ fory:
+ unmarshalType: com.example.Order
+ - to:
+ uri: mock:marshal
+- route:
+ from:
+ uri: direct:unmarshal
+ steps:
+ - unmarshal:
+ fory:
+ unmarshalType: com.example.Order
+ - to:
+ uri: mock:unmarshal
+----
== Dependencies
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jaxb-dataformat.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jaxb-dataformat.adoc
index dc89f967a355..a12c7a13d161 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jaxb-dataformat.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jaxb-dataformat.adoc
@@ -80,6 +80,61 @@ The following example shows how to configure the
`JaxbDataFormat` and use it in
</beans>
----
+=== Using the YAML DSL
+
+In the YAML DSL, you configure the data format on the `marshal` and
`unmarshal` steps:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - marshal:
+ jaxb:
+ contextPath: org.apache.camel.example
+ - to:
+ uri: direct:marshalled
+- route:
+ from:
+ uri: direct:marshalled
+ steps:
+ - unmarshal:
+ jaxb:
+ contextPath: org.apache.camel.example
+ - to:
+ uri: mock:result
+----
+
+To use one configuration in many routes, define the data format once in
`dataFormats` and refer to it by its id,
+as the Spring XML example does:
+
+[source,yaml]
+----
+- dataFormats:
+ - jaxb:
+ id: myJaxb
+ contextPath: org.apache.camel.example
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - marshal:
+ custom:
+ ref: myJaxb
+ - to:
+ uri: direct:marshalled
+- route:
+ from:
+ uri: direct:marshalled
+ steps:
+ - unmarshal:
+ custom:
+ ref: myJaxb
+ - to:
+ uri: mock:result
+----
+
=== Multiple context paths
It is possible to use this data format with more than one context path.
@@ -247,6 +302,23 @@ You can do the same using the XML DSL:
</marshal>
----
+And using the YAML DSL:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - marshal:
+ jaxb:
+ contextPath: com.acme.model
+ schema: "classpath:person.xsd,classpath:address.xsd"
+ accessExternalSchemaProtocols: file
+ - to:
+ uri: mock:result
+----
+
=== Schema Location
The `JaxbDataFormat` supports to specify the `SchemaLocation` when marshalling
the XML.
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/js-language.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/js-language.adoc
index 28f67ca33c24..7adba6032a66 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/js-language.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/js-language.adoc
@@ -55,6 +55,46 @@ The `variable` and `variables` bindings are the
exchange-scoped variables (for e
xref:eips:setVariable-eip.adoc[Set Variable] EIP). Global and route variables,
such as `global:foo`,
are not in this map; use `exchange.getVariable('global:foo')` for those.
+== Examples
+
+A JavaScript predicate in a xref:eips:choice-eip.adoc[Content-Based Router]:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:orders
+ steps:
+ - choice:
+ when:
+ - expression:
+ js:
+ expression: "headers.get('priority') == 'high'"
+ steps:
+ - to:
+ uri: direct:fast
+ otherwise:
+ steps:
+ - to:
+ uri: direct:normal
+----
+
+A JavaScript expression that sets the message body from the body and a header:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:greet
+ steps:
+ - setBody:
+ expression:
+ js:
+ expression: "'Hello ' + body + ', your priority is ' +
headers.get('priority')"
+ - to:
+ uri: log:greeting
+----
+
== Dependencies
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jsonApi-dataformat.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jsonApi-dataformat.adoc
index c3058b8355e6..ef5d8b56573a 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jsonApi-dataformat.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jsonApi-dataformat.adoc
@@ -13,6 +13,34 @@
include::partial$dataformat-options.adoc[]
// dataformat options: END
+== Usage
+
+The `dataFormatTypes` are the resource classes, separated by commas.
+They are annotated with `@Type` and `@Id` of the JSONAPI-Converter library.
+On unmarshal, `mainFormatType` is the class of the primary data of the
document:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:marshal
+ steps:
+ - marshal:
+ jsonApi:
+ dataFormatTypes: com.example.Book,com.example.Author
+ - to:
+ uri: mock:marshal
+- route:
+ from:
+ uri: direct:unmarshal
+ steps:
+ - unmarshal:
+ jsonApi:
+ dataFormatTypes: com.example.Book,com.example.Author
+ mainFormatType: com.example.Book
+ - to:
+ uri: mock:unmarshal
+----
== Dependencies
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/mimeMultipart-dataformat.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/mimeMultipart-dataformat.adoc
index 7d3c73cb3d78..9b5318b2267c 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/mimeMultipart-dataformat.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/mimeMultipart-dataformat.adoc
@@ -97,12 +97,30 @@ MIME multipart. The header is removed afterward
== Examples
-._Java-only: marshalling a message with attachments into MIME-Multipart format_
+[tabs]
+====
+Java::
++
[source,java]
----
from(...).marshal().mimeMultipart()
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - marshal:
+ mimeMultipart: {}
+ - to:
+ uri: mock:result
+----
+====
+
With a message where no Content-Type header is set, will create a
Message with the following message Camel headers:
@@ -136,12 +154,35 @@ AAECAwQFBgc=
A message with the header Content-Type set to "text/plain" sent to the
route
-._Java-only: marshalling with custom MIME-Multipart options_
+[tabs]
+====
+Java::
++
[source,java]
----
from("...").marshal().mimeMultipart("related", true, true, "(included|x-.*)",
true);
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - marshal:
+ mimeMultipart:
+ multipartSubType: related
+ multipartWithoutAttachment: true
+ headersInline: true
+ includeHeaders: "(included|x-.*)"
+ binaryContent: true
+ - to:
+ uri: mock:result
+----
+====
+
will create a message without any specific MIME headers set as Camel
headers (the Content-Type header is removed from the Camel message) and
the following message body that includes also all headers of the
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/openfeature-language.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/openfeature-language.adoc
index 07a08f3bf387..fa02ab66ca18 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/openfeature-language.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/openfeature-language.adoc
@@ -38,8 +38,12 @@ from message headers but does not set any properties or
headers itself.
This means it is safe to use before a producer `to("openfeature:...")`
call without leaking settings.
-=== Java DSL
+=== Filter
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct:start")
@@ -48,8 +52,31 @@ from("direct:start")
.end();
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - filter:
+ expression:
+ language:
+ language: openfeature
+ expression: enrichment-enabled
+ steps:
+ - to:
+ uri: direct:enrich-order
+----
+====
+
=== Choice
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct:start")
@@ -61,6 +88,30 @@ from("direct:start")
.end();
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - choice:
+ when:
+ - expression:
+ language:
+ language: openfeature
+ expression: enrichment-enabled
+ steps:
+ - to:
+ uri: direct:enrich-order
+ otherwise:
+ steps:
+ - to:
+ uri: direct:skip-enrichment
+----
+====
+
=== Expression with setProperty
The language can also be used as an expression to store the evaluation
@@ -68,6 +119,10 @@ result in an exchange property. This is a lightweight
alternative to the
component's `resultProperty` option — it avoids a full `to()` call and
keeps the message body untouched:
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct:start")
@@ -76,6 +131,30 @@ from("direct:start")
.toD("direct:route-${exchangeProperty.routingAlgorithm}");
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - setHeader:
+ name: CamelOpenFeatureTargetingKey
+ expression:
+ simple:
+ expression: "${body[order_id]}"
+ - setProperty:
+ name: routingAlgorithm
+ expression:
+ language:
+ language: openfeature
+ expression: new-routing-algorithm
+ - toD:
+ uri: "direct:route-${exchangeProperty.routingAlgorithm}"
+----
+====
+
The `language()` expression defaults to variant (string) evaluation, so
the property receives the string variant value directly.
@@ -97,6 +176,10 @@ language evaluates:
* `CamelOpenFeatureEvaluationContext` (header): a `Map<String, Object>` of
additional
context key-value pairs.
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct:start")
@@ -107,6 +190,37 @@ from("direct:start")
.end();
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - setHeader:
+ name: CamelOpenFeatureTargetingKey
+ expression:
+ constant:
+ expression: user-123
+ - setHeader:
+ name: CamelOpenFeatureEvaluationContext
+ expression:
+ groovy:
+ expression: "[customer_tier: 'ENTERPRISE']"
+ - filter:
+ expression:
+ language:
+ language: openfeature
+ expression: enrichment-enabled
+ steps:
+ - to:
+ uri: direct:enrich-order
+----
+====
+
+In YAML, the Groovy expression `[customer_tier: 'ENTERPRISE']` makes the map
of the evaluation context.
+
=== Via createPredicate / createExpression
When building a predicate or expression programmatically, pass the
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/parquetAvro-dataformat.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/parquetAvro-dataformat.adoc
index b05a4f95f9d4..c53eb43e4b87 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/parquetAvro-dataformat.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/parquetAvro-dataformat.adoc
@@ -29,22 +29,65 @@ There are ways to unmarshal parquet files/structures,
usually binary parquet fil
In this first example we unmarshal file payload to OutputStream and send it to
mock endpoint, then we will be able to get GenericRecord or POJO (it could be a
list if that is coming through)
-._Java-only: unmarshal with a local parquet data format variable_
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct:unmarshal").unmarshal(parquet).to("mock:unmarshal");
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:unmarshal
+ steps:
+ - unmarshal:
+ parquetAvro:
+ unmarshalType: com.example.Order
+ - to:
+ uri: mock:unmarshal
+----
+====
+
+With `unmarshalType`, the records are objects of that class. Without it, they
are `GenericRecord` objects.
+
== Marshal
Marshalling is the reverse process of unmarshalling, so when you have your
`GenericRecord` or POJO and marshal it, you will get the parquet-formatted
output stream on your producer endpoint.
-._Java-only: marshal with a local parquet data format variable_
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct:marshal").marshal(parquet).to("mock:marshal");
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:marshal
+ steps:
+ - marshal:
+ parquetAvro:
+ unmarshalType: com.example.Order
+ - to:
+ uri: mock:marshal
+----
+====
+
+To marshal POJOs, set `unmarshalType` on marshal as well: the data format
makes the parquet schema from that class.
+A `GenericRecord` has its own schema.
+
== Dependencies
To use parquet-avro data format in your camel routes you need to add a
dependency on
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/python-language.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/python-language.adoc
index 486c001e046f..76a14e411d11 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/python-language.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/python-language.adoc
@@ -55,6 +55,46 @@ The `variable` and `variables` bindings are the
exchange-scoped variables (for e
xref:eips:setVariable-eip.adoc[Set Variable] EIP). Global and route variables,
such as `global:foo`,
are not in this map; use `exchange.getVariable('global:foo')` for those.
+== Examples
+
+A Python predicate in a xref:eips:choice-eip.adoc[Content-Based Router]:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:orders
+ steps:
+ - choice:
+ when:
+ - expression:
+ python:
+ expression: "headers.get('priority') == 'high'"
+ steps:
+ - to:
+ uri: direct:fast
+ otherwise:
+ steps:
+ - to:
+ uri: direct:normal
+----
+
+A Python expression that sets the message body from the body and a header:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:greet
+ steps:
+ - setBody:
+ expression:
+ python:
+ expression: "'Hello ' + str(body) + ', your priority is ' +
str(headers.get('priority'))"
+ - to:
+ uri: log:greeting
+----
+
== Dependencies
diff --git a/components/camel-asn1/src/main/docs/asn1-dataformat.adoc
b/components/camel-asn1/src/main/docs/asn1-dataformat.adoc
index 28a8a0890847..da053284c8fb 100644
--- a/components/camel-asn1/src/main/docs/asn1-dataformat.adoc
+++ b/components/camel-asn1/src/main/docs/asn1-dataformat.adoc
@@ -25,18 +25,39 @@ There are 3 different ways to unmarshal ASN.1 structured
messages. (Usually bina
In this first example, we unmarshal BER file payload to OutputStream and send
it to mock endpoint.
-._Java-only: uses the asn1 data format object directly_
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct:unmarshal").unmarshal(asn1).to("mock:unmarshal");
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:unmarshal
+ steps:
+ - unmarshal:
+ asn1: {}
+ - to:
+ uri: mock:unmarshal
+----
+====
+
In the second example, we unmarshal BER file payload to a byte array using
Split EIP.
The reason for applying Split EIP is that usually each BER file or (ASN.1
structured file) contains multiple records to process and Split EIP helps us to
get each record in a file as byte arrays which is actually ASN1Primitive's
instance (by the use of Bouncy Castle's ASN.1 support in bcprov-jdk18on library)
Byte arrays then may be converted to ASN1Primitive by the help of public
static method in (ASN1Primitive.fromByteArray)
In such example, note that you need to set `usingIterator=true`
-._Java-only: uses the asn1 data format object and Split EIP with bodyAs_
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct:unmarshal")
@@ -45,13 +66,38 @@ from("direct:unmarshal")
.to("mock:unmarshal");
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:unmarshal
+ steps:
+ - unmarshal:
+ asn1:
+ usingIterator: true
+ - split:
+ expression:
+ simple:
+ expression: "${body}"
+ streaming: true
+ steps:
+ - to:
+ uri: mock:unmarshal
+----
+====
+
In the last example, we unmarshalled a BER file payload to plain old Java
Objects using Split EIP. The reason for applying Split EIP is already mentioned
in the previous example. Please note and keep in mind that reason. In such
example we also need to set the fully qualified name of the class or
<YourObject>.class reference through data format.
The important thing to note here is that your object should have been
generated by jasn1 compiler, which is a nice tool to generate java object
representations of your ASN.1 structure.
For the reference usage of jasn1 compiler, see the
https://www.beanit.com/asn1/[JASN.1 Project Page] and please also see how the
compiler is invoked with the help of maven's exec plugin.
For example, in this data format's unit tests an example ASN.1
structure(TestSMSBerCdr.asn1) is added in `src/test/resources/asn1_structure`.
jasn1 compiler is invoked, and java object's representations are generated in
`$\{basedir}/target/generated/src/test/java`
The nice thing about this example, you will get POJO instance at the mock
endpoint or at whatever your endpoint is.
-._Java-only: uses unmarshal with class name and Split EIP with bodyAs_
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct:unmarshaldsl")
@@ -61,6 +107,29 @@ from("direct:unmarshaldsl")
.to("mock:unmarshaldsl");
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:unmarshaldsl
+ steps:
+ - unmarshal:
+ asn1:
+ unmarshalType:
org.apache.camel.dataformat.asn1.model.testsmscbercdr.SmsCdr
+ usingIterator: true
+ - split:
+ expression:
+ simple:
+ expression: "${body}"
+ streaming: true
+ steps:
+ - to:
+ uri: mock:unmarshaldsl
+----
+====
+
== Dependencies
To use ASN.1 data format in your camel routes you need to add a dependency on
diff --git a/components/camel-barcode/src/main/docs/barcode-dataformat.adoc
b/components/camel-barcode/src/main/docs/barcode-dataformat.adoc
index 5dd023395359..41028e186796 100644
--- a/components/camel-barcode/src/main/docs/barcode-dataformat.adoc
+++ b/components/camel-barcode/src/main/docs/barcode-dataformat.adoc
@@ -39,9 +39,9 @@ the download page for the latest versions).
include::partial$dataformat-options.adoc[]
// dataformat options: END
-== Using the Java DSL
+== Usage
-First, you have to initialize the barcode data format class.
+In Java, you first create an instance of the barcode data format class.
You can use the default constructor, or one of parameterized (see JavaDoc).
The default values are:
@@ -82,7 +82,10 @@ For possible hints, please consult the ZXing documentation.
=== Marshalling
-._Java-only: route using Java data format variable_
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct://code")
@@ -90,6 +93,25 @@ from("direct://code")
.to("file://barcode_out");
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct://code
+ steps:
+ - marshal:
+ barcode:
+ barcodeFormat: QR_CODE
+ imageType: PNG
+ width: 100
+ height: 100
+ - to:
+ uri: file://barcode_out
+----
+====
+
You can call the route from a test class with:
._Java-only: Java test API (ProducerTemplate)_
@@ -108,7 +130,10 @@ The unmarshaller is generic.
For unmarshalling, you can use any BarcodeDataFormat instance.
If you've two instances, one for (generating) QR-Code and one for PDF417, it
doesn't matter which one will be used.
-._Java-only: route using Java data format variable_
+[tabs]
+====
+Java::
++
[source,java]
----
from("file://barcode_in?noop=true")
@@ -116,6 +141,23 @@ from("file://barcode_in?noop=true")
.to("mock:out");
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: file://barcode_in
+ parameters:
+ noop: true
+ steps:
+ - unmarshal:
+ barcode: {}
+ - to:
+ uri: mock:out
+----
+====
+
If you'll paste the QR-Code image above into the 'barcode_in' folder,
you should find _`This is a testmessage!`_ inside the mock.
You can find the barcode data format as header variable:
diff --git a/components/camel-bindy/src/main/docs/bindy-dataformat.adoc
b/components/camel-bindy/src/main/docs/bindy-dataformat.adoc
index d0a25d54ff6e..83c6f9946c0b 100644
--- a/components/camel-bindy/src/main/docs/bindy-dataformat.adoc
+++ b/components/camel-bindy/src/main/docs/bindy-dataformat.adoc
@@ -2031,6 +2031,94 @@ Please verify that your model classes implement
serializable otherwise
the queue manager will raise an error.
====
+=== Using the YAML DSL
+
+In the YAML DSL, the data format is `bindy`, and its `type` is `Csv`, `Fixed`
or `KeyValue`.
+The `classType` is the model class.
+
+The following route reads CSV files, unmarshals them into a list of `Order`
objects,
+and splits the list to handle one order at a time:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: file:inbox
+ steps:
+ - unmarshal:
+ bindy:
+ type: Csv
+ classType: com.acme.model.Order
+ - split:
+ expression:
+ simple:
+ expression: "${body}"
+ steps:
+ - to:
+ uri: direct:handleSingleOrder
+----
+
+To write CSV records, marshal a list of model objects.
+Set the `locale` when the numbers and dates must not depend on the machine:
without it, Bindy uses the default locale
+of the JVM, and on a machine with a Danish or German locale `2500.45` is
written as `2500,45`.
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:handleOrders
+ steps:
+ - marshal:
+ bindy:
+ type: Csv
+ classType: com.acme.model.Order
+ locale: en-US
+ - to:
+ uri: file:outbox
+----
+
+Fixed-length records work the same way, with the type `Fixed`:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: file:inbox/fixed
+ steps:
+ - unmarshal:
+ bindy:
+ type: Fixed
+ classType: com.acme.model.fixed.Order
+ - split:
+ expression:
+ simple:
+ expression: "${body}"
+ steps:
+ - to:
+ uri: direct:handleSingleOrder
+----
+
+For key-value pairs, such as FIX messages, the type is `KeyValue`.
+As in the Spring XML example, you can define the data format once in
`dataFormats` and use it by its id:
+
+[source,yaml]
+----
+- dataFormats:
+ - bindy:
+ id: fixOrder
+ type: KeyValue
+ classType: com.acme.model.fix.Order
+- route:
+ from:
+ uri: file:inbox/fix
+ steps:
+ - unmarshal:
+ custom:
+ ref: fixOrder
+ - to:
+ uri: direct:handleFixOrder
+----
+
== Dependencies
To use Bindy in your camel routes, you need to add a dependency on
diff --git a/components/camel-crypto/src/main/docs/crypto-dataformat.adoc
b/components/camel-crypto/src/main/docs/crypto-dataformat.adoc
index d593c0599e27..37d1c979e451 100644
--- a/components/camel-crypto/src/main/docs/crypto-dataformat.adoc
+++ b/components/camel-crypto/src/main/docs/crypto-dataformat.adoc
@@ -66,6 +66,34 @@ In Spring the dataformat is configured first and then used
in routes
</camelContext>
----
+In the YAML DSL, the key is a bean that the data format refers to by name.
+Here the bean is a new DES key, made by a Groovy script when the application
starts:
+
+[source,yaml]
+----
+- beans:
+ - name: desKey
+ type: javax.crypto.SecretKey
+ scriptLanguage: groovy
+ script: "javax.crypto.KeyGenerator.getInstance('DES').generateKey()"
+- route:
+ from:
+ uri: direct:basic-encryption
+ steps:
+ - marshal:
+ crypto:
+ algorithm: DES
+ key: desKey
+ - to:
+ uri: mock:encrypted
+ - unmarshal:
+ crypto:
+ algorithm: DES
+ key: desKey
+ - to:
+ uri: mock:unencrypted
+----
+
== Specifying the Encryption Algorithm
@@ -154,6 +182,42 @@ Spring XML::
<crypto id="inline-decrypt" algorithm="DES/CBC/PKCS5Padding" key="desKey"
inline="true" />
----
+YAML::
++
+[source,yaml]
+----
+- beans:
+ - name: initializationVector
+ scriptLanguage: groovy
+ script: "[0, 1, 2, 3, 4, 5, 6, 7] as byte[]"
+- dataFormats:
+ - crypto:
+ id: inline
+ algorithm: DES/CBC/PKCS5Padding
+ key: desKey
+ initVector: initializationVector
+ inline: true
+ - crypto:
+ id: inline-decrypt
+ algorithm: DES/CBC/PKCS5Padding
+ key: desKey
+ inline: true
+- route:
+ from:
+ uri: direct:inline
+ steps:
+ - marshal:
+ custom:
+ ref: inline
+ - to:
+ uri: mock:encrypted
+ - unmarshal:
+ custom:
+ ref: inline-decrypt
+ - to:
+ uri: mock:unencrypted
+----
+
====
For more information about the use of Initialization Vectors, consult
@@ -191,6 +255,32 @@ Spring XML::
<crypto id="hmac" algorithm="DES" key="desKey" shouldAppendHMAC="true" />
----
+YAML::
++
+[source,yaml]
+----
+- dataFormats:
+ - crypto:
+ id: hmac
+ algorithm: DES
+ key: desKey
+ shouldAppendHMAC: true
+- route:
+ from:
+ uri: direct:hmac
+ steps:
+ - marshal:
+ custom:
+ ref: hmac
+ - to:
+ uri: mock:encrypted
+ - unmarshal:
+ custom:
+ ref: hmac
+ - to:
+ uri: mock:unencrypted
+----
+
====
By default, the HMAC is calculated using the HmacSHA1 mac algorithm, though
this can be easily changed by supplying a different algorithm name. See here
for how to check what algorithms are available through the configured security
providers
@@ -221,6 +311,33 @@ Spring XML::
<crypto id="hmac-algorithm" algorithm="DES" key="desKey"
macAlgorithm="HmacMD5" shouldAppendHMAC="true" />
----
+YAML::
++
+[source,yaml]
+----
+- dataFormats:
+ - crypto:
+ id: hmac-algorithm
+ algorithm: DES
+ key: desKey
+ macAlgorithm: HmacMD5
+ shouldAppendHMAC: true
+- route:
+ from:
+ uri: direct:hmac-algorithm
+ steps:
+ - marshal:
+ custom:
+ ref: hmac-algorithm
+ - to:
+ uri: mock:encrypted
+ - unmarshal:
+ custom:
+ ref: hmac-algorithm
+ - to:
+ uri: mock:unencrypted
+----
+
====
== Supplying Keys Dynamically
@@ -265,6 +382,35 @@ Spring XML::
<crypto id="nokey" algorithm="DES" />
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:key-in-header-encrypt
+ steps:
+ - marshal:
+ crypto:
+ algorithm: DES
+ # remove the key so it does not leak with the message
+ - removeHeader:
+ name: CamelCryptoKey
+ - to:
+ uri: mock:encrypted
+- route:
+ from:
+ uri: direct:key-in-header-decrypt
+ steps:
+ - unmarshal:
+ crypto:
+ algorithm: DES
+ - removeHeader:
+ name: CamelCryptoKey
+ - to:
+ uri: mock:unencrypted
+----
+
====
== Dependencies
diff --git
a/components/camel-fhir/camel-fhir-component/src/main/docs/fhirJson-dataformat.adoc
b/components/camel-fhir/camel-fhir-component/src/main/docs/fhirJson-dataformat.adoc
index de217cdf6bd9..4d3c3347c2ec 100644
---
a/components/camel-fhir/camel-fhir-component/src/main/docs/fhirJson-dataformat.adoc
+++
b/components/camel-fhir/camel-fhir-component/src/main/docs/fhirJson-dataformat.adoc
@@ -18,3 +18,25 @@ JSON parser to parse to/from JSON format to/from a
HAPI-FHIR's `IBaseResource`.
// dataformat options: START
include::partial$dataformat-options.adoc[]
// dataformat options: END
+
+== Usage
+
+The following route parses a FHIR resource from JSON and writes it as XML.
+The `fhirVersion` must match the version of the resources (R4 is the default):
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:patient
+ steps:
+ - unmarshal:
+ fhirJson:
+ fhirVersion: R4
+ - marshal:
+ fhirXml:
+ fhirVersion: R4
+ prettyPrint: true
+ - to:
+ uri: mock:result
+----
diff --git
a/components/camel-fhir/camel-fhir-component/src/main/docs/fhirXml-dataformat.adoc
b/components/camel-fhir/camel-fhir-component/src/main/docs/fhirXml-dataformat.adoc
index e744e8fd0ace..a3c074e97eb9 100644
---
a/components/camel-fhir/camel-fhir-component/src/main/docs/fhirXml-dataformat.adoc
+++
b/components/camel-fhir/camel-fhir-component/src/main/docs/fhirXml-dataformat.adoc
@@ -18,3 +18,25 @@ XML parser to parse to/from XML format to/from a HAPI-FHIR's
`IBaseResource`.
// dataformat options: START
include::partial$dataformat-options.adoc[]
// dataformat options: END
+
+== Usage
+
+The following route parses a FHIR resource from XML and writes it as JSON.
+The `fhirVersion` must match the version of the resources (R4 is the default):
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:patient
+ steps:
+ - unmarshal:
+ fhirXml:
+ fhirVersion: R4
+ - marshal:
+ fhirJson:
+ fhirVersion: R4
+ prettyPrint: true
+ - to:
+ uri: mock:result
+----
diff --git a/components/camel-flatpack/src/main/docs/flatpack-dataformat.adoc
b/components/camel-flatpack/src/main/docs/flatpack-dataformat.adoc
index ba58200fa9a8..dd98ab9244b1 100644
--- a/components/camel-flatpack/src/main/docs/flatpack-dataformat.adoc
+++ b/components/camel-flatpack/src/main/docs/flatpack-dataformat.adoc
@@ -33,34 +33,75 @@ include::partial$dataformat-options.adoc[]
== Usage
-To use the data format, instantiate an instance and invoke the
-marshal or unmarshal operation in the route builder:
+To use the data format, set it on the marshal or unmarshal step of the route:
-._Java-only: programmatic FlatpackDataFormat configuration and unmarshal_
+[tabs]
+====
+Java::
++
[source,java]
----
- FlatpackDataFormat fp = new FlatpackDataFormat();
- fp.setDefinition(new ClassPathResource("INVENTORY-Delimited.pzmap.xml"));
- ...
- from("file:order/in").unmarshal(df).to("seda:queue:neworder");
+FlatpackDataFormat fp = new FlatpackDataFormat();
+fp.setDefinition("INVENTORY-Delimited.pzmap.xml");
+
+from("file:order/in").unmarshal(fp).to("seda:neworder");
+----
+
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: file:order/in
+ steps:
+ - unmarshal:
+ flatpack:
+ definition: INVENTORY-Delimited.pzmap.xml
+ - to:
+ uri: seda:neworder
----
+====
The sample above will read files from the `order/in` folder and
unmarshal the input using the Flatpack configuration file
`INVENTORY-Delimited.pzmap.xml` that configures the structure of the
files. The result is a `DataSetList` object we store on the SEDA queue.
-._Java-only: programmatic FlatpackDataFormat configuration and marshal_
+[tabs]
+====
+Java::
++
[source,java]
----
FlatpackDataFormat df = new FlatpackDataFormat();
-df.setDefinition(new ClassPathResource("PEOPLE-FixedLength.pzmap.xml"));
+df.setDefinition("PEOPLE-FixedLength.pzmap.xml");
df.setFixed(true);
df.setIgnoreFirstRecord(false);
from("seda:people").marshal(df).convertBodyTo(String.class).to("jms:queue:people");
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: seda:people
+ steps:
+ - marshal:
+ flatpack:
+ definition: PEOPLE-FixedLength.pzmap.xml
+ fixed: true
+ ignoreFirstRecord: false
+ - convertBodyTo:
+ type: java.lang.String
+ - to:
+ uri: jms:queue:people
+----
+====
+
In the code above we marshal the data from an Object representation as a
`List` of rows as `Maps`. The rows as `Map` contains the column name as
the key, and the corresponding value. This structure can be created
diff --git a/components/camel-fory/src/main/docs/fory-dataformat.adoc
b/components/camel-fory/src/main/docs/fory-dataformat.adoc
index 4783ba03ea23..00f799e0aa70 100644
--- a/components/camel-fory/src/main/docs/fory-dataformat.adoc
+++ b/components/camel-fory/src/main/docs/fory-dataformat.adoc
@@ -22,6 +22,32 @@ Apache Fory is not supporting architecture using Big Endian
(s390x, for instance
include::partial$dataformat-options.adoc[]
// dataformat options: END
+== Usage
+
+Fory only serializes registered classes by default
(`requireClassRegistration`).
+The data format registers the `unmarshalType` class, so set it on marshal as
well as on unmarshal:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:marshal
+ steps:
+ - marshal:
+ fory:
+ unmarshalType: com.example.Order
+ - to:
+ uri: mock:marshal
+- route:
+ from:
+ uri: direct:unmarshal
+ steps:
+ - unmarshal:
+ fory:
+ unmarshalType: com.example.Order
+ - to:
+ uri: mock:unmarshal
+----
== Dependencies
diff --git a/components/camel-javascript/src/main/docs/js-language.adoc
b/components/camel-javascript/src/main/docs/js-language.adoc
index 28f67ca33c24..7adba6032a66 100644
--- a/components/camel-javascript/src/main/docs/js-language.adoc
+++ b/components/camel-javascript/src/main/docs/js-language.adoc
@@ -55,6 +55,46 @@ The `variable` and `variables` bindings are the
exchange-scoped variables (for e
xref:eips:setVariable-eip.adoc[Set Variable] EIP). Global and route variables,
such as `global:foo`,
are not in this map; use `exchange.getVariable('global:foo')` for those.
+== Examples
+
+A JavaScript predicate in a xref:eips:choice-eip.adoc[Content-Based Router]:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:orders
+ steps:
+ - choice:
+ when:
+ - expression:
+ js:
+ expression: "headers.get('priority') == 'high'"
+ steps:
+ - to:
+ uri: direct:fast
+ otherwise:
+ steps:
+ - to:
+ uri: direct:normal
+----
+
+A JavaScript expression that sets the message body from the body and a header:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:greet
+ steps:
+ - setBody:
+ expression:
+ js:
+ expression: "'Hello ' + body + ', your priority is ' +
headers.get('priority')"
+ - to:
+ uri: log:greeting
+----
+
== Dependencies
diff --git a/components/camel-jaxb/src/main/docs/jaxb-dataformat.adoc
b/components/camel-jaxb/src/main/docs/jaxb-dataformat.adoc
index dc89f967a355..a12c7a13d161 100644
--- a/components/camel-jaxb/src/main/docs/jaxb-dataformat.adoc
+++ b/components/camel-jaxb/src/main/docs/jaxb-dataformat.adoc
@@ -80,6 +80,61 @@ The following example shows how to configure the
`JaxbDataFormat` and use it in
</beans>
----
+=== Using the YAML DSL
+
+In the YAML DSL, you configure the data format on the `marshal` and
`unmarshal` steps:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - marshal:
+ jaxb:
+ contextPath: org.apache.camel.example
+ - to:
+ uri: direct:marshalled
+- route:
+ from:
+ uri: direct:marshalled
+ steps:
+ - unmarshal:
+ jaxb:
+ contextPath: org.apache.camel.example
+ - to:
+ uri: mock:result
+----
+
+To use one configuration in many routes, define the data format once in
`dataFormats` and refer to it by its id,
+as the Spring XML example does:
+
+[source,yaml]
+----
+- dataFormats:
+ - jaxb:
+ id: myJaxb
+ contextPath: org.apache.camel.example
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - marshal:
+ custom:
+ ref: myJaxb
+ - to:
+ uri: direct:marshalled
+- route:
+ from:
+ uri: direct:marshalled
+ steps:
+ - unmarshal:
+ custom:
+ ref: myJaxb
+ - to:
+ uri: mock:result
+----
+
=== Multiple context paths
It is possible to use this data format with more than one context path.
@@ -247,6 +302,23 @@ You can do the same using the XML DSL:
</marshal>
----
+And using the YAML DSL:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - marshal:
+ jaxb:
+ contextPath: com.acme.model
+ schema: "classpath:person.xsd,classpath:address.xsd"
+ accessExternalSchemaProtocols: file
+ - to:
+ uri: mock:result
+----
+
=== Schema Location
The `JaxbDataFormat` supports to specify the `SchemaLocation` when marshalling
the XML.
diff --git a/components/camel-jsonapi/src/main/docs/jsonApi-dataformat.adoc
b/components/camel-jsonapi/src/main/docs/jsonApi-dataformat.adoc
index c3058b8355e6..ef5d8b56573a 100644
--- a/components/camel-jsonapi/src/main/docs/jsonApi-dataformat.adoc
+++ b/components/camel-jsonapi/src/main/docs/jsonApi-dataformat.adoc
@@ -13,6 +13,34 @@
include::partial$dataformat-options.adoc[]
// dataformat options: END
+== Usage
+
+The `dataFormatTypes` are the resource classes, separated by commas.
+They are annotated with `@Type` and `@Id` of the JSONAPI-Converter library.
+On unmarshal, `mainFormatType` is the class of the primary data of the
document:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:marshal
+ steps:
+ - marshal:
+ jsonApi:
+ dataFormatTypes: com.example.Book,com.example.Author
+ - to:
+ uri: mock:marshal
+- route:
+ from:
+ uri: direct:unmarshal
+ steps:
+ - unmarshal:
+ jsonApi:
+ dataFormatTypes: com.example.Book,com.example.Author
+ mainFormatType: com.example.Book
+ - to:
+ uri: mock:unmarshal
+----
== Dependencies
diff --git a/components/camel-mail/src/main/docs/mimeMultipart-dataformat.adoc
b/components/camel-mail/src/main/docs/mimeMultipart-dataformat.adoc
index 7d3c73cb3d78..9b5318b2267c 100644
--- a/components/camel-mail/src/main/docs/mimeMultipart-dataformat.adoc
+++ b/components/camel-mail/src/main/docs/mimeMultipart-dataformat.adoc
@@ -97,12 +97,30 @@ MIME multipart. The header is removed afterward
== Examples
-._Java-only: marshalling a message with attachments into MIME-Multipart format_
+[tabs]
+====
+Java::
++
[source,java]
----
from(...).marshal().mimeMultipart()
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - marshal:
+ mimeMultipart: {}
+ - to:
+ uri: mock:result
+----
+====
+
With a message where no Content-Type header is set, will create a
Message with the following message Camel headers:
@@ -136,12 +154,35 @@ AAECAwQFBgc=
A message with the header Content-Type set to "text/plain" sent to the
route
-._Java-only: marshalling with custom MIME-Multipart options_
+[tabs]
+====
+Java::
++
[source,java]
----
from("...").marshal().mimeMultipart("related", true, true, "(included|x-.*)",
true);
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - marshal:
+ mimeMultipart:
+ multipartSubType: related
+ multipartWithoutAttachment: true
+ headersInline: true
+ includeHeaders: "(included|x-.*)"
+ binaryContent: true
+ - to:
+ uri: mock:result
+----
+====
+
will create a message without any specific MIME headers set as Camel
headers (the Content-Type header is removed from the Camel message) and
the following message body that includes also all headers of the
diff --git
a/components/camel-openfeature/src/main/docs/openfeature-language.adoc
b/components/camel-openfeature/src/main/docs/openfeature-language.adoc
index 07a08f3bf387..fa02ab66ca18 100644
--- a/components/camel-openfeature/src/main/docs/openfeature-language.adoc
+++ b/components/camel-openfeature/src/main/docs/openfeature-language.adoc
@@ -38,8 +38,12 @@ from message headers but does not set any properties or
headers itself.
This means it is safe to use before a producer `to("openfeature:...")`
call without leaking settings.
-=== Java DSL
+=== Filter
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct:start")
@@ -48,8 +52,31 @@ from("direct:start")
.end();
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - filter:
+ expression:
+ language:
+ language: openfeature
+ expression: enrichment-enabled
+ steps:
+ - to:
+ uri: direct:enrich-order
+----
+====
+
=== Choice
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct:start")
@@ -61,6 +88,30 @@ from("direct:start")
.end();
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - choice:
+ when:
+ - expression:
+ language:
+ language: openfeature
+ expression: enrichment-enabled
+ steps:
+ - to:
+ uri: direct:enrich-order
+ otherwise:
+ steps:
+ - to:
+ uri: direct:skip-enrichment
+----
+====
+
=== Expression with setProperty
The language can also be used as an expression to store the evaluation
@@ -68,6 +119,10 @@ result in an exchange property. This is a lightweight
alternative to the
component's `resultProperty` option — it avoids a full `to()` call and
keeps the message body untouched:
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct:start")
@@ -76,6 +131,30 @@ from("direct:start")
.toD("direct:route-${exchangeProperty.routingAlgorithm}");
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - setHeader:
+ name: CamelOpenFeatureTargetingKey
+ expression:
+ simple:
+ expression: "${body[order_id]}"
+ - setProperty:
+ name: routingAlgorithm
+ expression:
+ language:
+ language: openfeature
+ expression: new-routing-algorithm
+ - toD:
+ uri: "direct:route-${exchangeProperty.routingAlgorithm}"
+----
+====
+
The `language()` expression defaults to variant (string) evaluation, so
the property receives the string variant value directly.
@@ -97,6 +176,10 @@ language evaluates:
* `CamelOpenFeatureEvaluationContext` (header): a `Map<String, Object>` of
additional
context key-value pairs.
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct:start")
@@ -107,6 +190,37 @@ from("direct:start")
.end();
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - setHeader:
+ name: CamelOpenFeatureTargetingKey
+ expression:
+ constant:
+ expression: user-123
+ - setHeader:
+ name: CamelOpenFeatureEvaluationContext
+ expression:
+ groovy:
+ expression: "[customer_tier: 'ENTERPRISE']"
+ - filter:
+ expression:
+ language:
+ language: openfeature
+ expression: enrichment-enabled
+ steps:
+ - to:
+ uri: direct:enrich-order
+----
+====
+
+In YAML, the Groovy expression `[customer_tier: 'ENTERPRISE']` makes the map
of the evaluation context.
+
=== Via createPredicate / createExpression
When building a predicate or expression programmatically, pass the
diff --git
a/components/camel-parquet-avro/src/main/docs/parquetAvro-dataformat.adoc
b/components/camel-parquet-avro/src/main/docs/parquetAvro-dataformat.adoc
index b05a4f95f9d4..c53eb43e4b87 100644
--- a/components/camel-parquet-avro/src/main/docs/parquetAvro-dataformat.adoc
+++ b/components/camel-parquet-avro/src/main/docs/parquetAvro-dataformat.adoc
@@ -29,22 +29,65 @@ There are ways to unmarshal parquet files/structures,
usually binary parquet fil
In this first example we unmarshal file payload to OutputStream and send it to
mock endpoint, then we will be able to get GenericRecord or POJO (it could be a
list if that is coming through)
-._Java-only: unmarshal with a local parquet data format variable_
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct:unmarshal").unmarshal(parquet).to("mock:unmarshal");
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:unmarshal
+ steps:
+ - unmarshal:
+ parquetAvro:
+ unmarshalType: com.example.Order
+ - to:
+ uri: mock:unmarshal
+----
+====
+
+With `unmarshalType`, the records are objects of that class. Without it, they
are `GenericRecord` objects.
+
== Marshal
Marshalling is the reverse process of unmarshalling, so when you have your
`GenericRecord` or POJO and marshal it, you will get the parquet-formatted
output stream on your producer endpoint.
-._Java-only: marshal with a local parquet data format variable_
+[tabs]
+====
+Java::
++
[source,java]
----
from("direct:marshal").marshal(parquet).to("mock:marshal");
----
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:marshal
+ steps:
+ - marshal:
+ parquetAvro:
+ unmarshalType: com.example.Order
+ - to:
+ uri: mock:marshal
+----
+====
+
+To marshal POJOs, set `unmarshalType` on marshal as well: the data format
makes the parquet schema from that class.
+A `GenericRecord` has its own schema.
+
== Dependencies
To use parquet-avro data format in your camel routes you need to add a
dependency on
diff --git a/components/camel-python/src/main/docs/python-language.adoc
b/components/camel-python/src/main/docs/python-language.adoc
index 486c001e046f..76a14e411d11 100644
--- a/components/camel-python/src/main/docs/python-language.adoc
+++ b/components/camel-python/src/main/docs/python-language.adoc
@@ -55,6 +55,46 @@ The `variable` and `variables` bindings are the
exchange-scoped variables (for e
xref:eips:setVariable-eip.adoc[Set Variable] EIP). Global and route variables,
such as `global:foo`,
are not in this map; use `exchange.getVariable('global:foo')` for those.
+== Examples
+
+A Python predicate in a xref:eips:choice-eip.adoc[Content-Based Router]:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:orders
+ steps:
+ - choice:
+ when:
+ - expression:
+ python:
+ expression: "headers.get('priority') == 'high'"
+ steps:
+ - to:
+ uri: direct:fast
+ otherwise:
+ steps:
+ - to:
+ uri: direct:normal
+----
+
+A Python expression that sets the message body from the body and a header:
+
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:greet
+ steps:
+ - setBody:
+ expression:
+ python:
+ expression: "'Hello ' + str(body) + ', your priority is ' +
str(headers.get('priority'))"
+ - to:
+ uri: log:greeting
+----
+
== Dependencies
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogSamples.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogSamples.java
index b4a883b0872a..599e6cca0a36 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogSamples.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogSamples.java
@@ -226,7 +226,7 @@ public final class CatalogSamples {
try {
found = switch (kind) {
case "component" -> componentSamples(catalog, key);
- case "dataformat" -> pageSamples(catalog,
dataFormatPages(catalog, key), null);
+ case "dataformat" -> pageSamples(catalog,
dataFormatPages(catalog, key), dataFormatUse(catalog, key));
case "language" -> pageSamples(catalog, List.of(key +
"-language"), null);
default -> eipSamples(catalog, key);
};
@@ -715,6 +715,28 @@ public final class CatalogSamples {
return variants;
}
+ /**
+ * What the samples that use the data format itself write, to put them
first: a page can show its siblings too (the
+ * univocity pages show the csv, fixed and tsv formats), and bindyCsv,
bindyFixed and bindyKvp are all bindy, with
+ * the type Csv, Fixed or KeyValue.
+ */
+ static Pattern dataFormatUse(CamelCatalog catalog, String name) {
+ DataFormatModel model = catalog.findDataFormatNames().contains(name) ?
catalog.dataFormatModel(name) : null;
+ if (model == null) {
+ return null;
+ }
+ if (name.equals(model.getModelName())) {
+ return Pattern.compile("^[\\s-]*" + Pattern.quote(name) + ":",
Pattern.MULTILINE);
+ }
+ return model.getOptions().stream()
+ .filter(o -> "type".equals(o.getName()) && o.getDefaultValue()
!= null)
+ .findFirst()
+ .map(o -> Pattern.compile(
+ "^\\s*type:\\s*[\"']?" +
Pattern.quote(o.getDefaultValue().toString()) + "[\"']?\\s*$",
+ Pattern.MULTILINE))
+ .orElse(null);
+ }
+
static String normalizeKind(String kind) {
if (kind == null || kind.isBlank()) {
return null;
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogSamplesTest.java
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogSamplesTest.java
index d2c6bb8dae3b..6436fcaf36f8 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogSamplesTest.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogSamplesTest.java
@@ -371,12 +371,36 @@ public class CatalogSamplesTest {
assertThat(jackson.getString("kind")).isEqualTo("dataformat");
assertThat(source(jackson, 0)).startsWith("jackson2-dataformat.adoc");
assertThat((Integer) jackson.get("count")).isEqualTo(2);
- // bindyCsv is on the bindy page, which has no YAML example
+ // bindyCsv, bindyFixed and bindyKvp are on the bindy page, and the
samples of the asked type come first
assertThat(CatalogSamples.dataFormatPages(catalog,
"bindyCsv")).containsExactly("bindy-dataformat");
JsonObject bindy = CatalogSamples.sample(catalog, "bindyCsv", 1);
assertThat(bindy.getString("kind")).isEqualTo("dataformat");
- assertThat((Integer) bindy.get("count")).isZero();
- assertThat(bindy.getString("hint")).contains("no YAML route example");
+ assertThat(source(bindy, 0)).startsWith("bindy-dataformat.adoc");
+ assertThat(yaml(bindy, 0)).contains("type: Csv");
+ assertThat(yaml(CatalogSamples.sample(catalog, "bindyFixed", 1),
0)).contains("type: Fixed");
+ assertThat(yaml(CatalogSamples.sample(catalog, "bindyKvp", 1),
0)).contains("type: KeyValue");
+ // the univocityTsv page shows the csv and fixed formats first, and
its own sample comes first
+ assertThat(yaml(CatalogSamples.sample(catalog, "univocityTsv", 1),
0)).contains("univocityTsv:");
+ assertThat(CatalogSamples.dataFormatUse(catalog, "jackson")).isNull();
+ }
+
+ @Test
+ void aPageWithoutYamlExampleSaysSo() {
+ // a catalog whose python page has no YAML example; without a version
its answers are not cached
+ CamelCatalog catalog = new DefaultCamelCatalog() {
+ @Override
+ public String getCatalogVersion() {
+ return null;
+ }
+
+ @Override
+ public String asciiDoc(String name) {
+ return "python-language".equals(name) ? "= Python
Language\n\nNo route example.\n" : super.asciiDoc(name);
+ }
+ };
+ JsonObject python = CatalogSamples.sample(catalog, "language",
"python", 1);
+ assertThat((Integer) python.get("count")).isZero();
+ assertThat(python.getString("hint")).contains("no YAML route example");
}
/** CAMEL-25370: the error handler has samples, both of its places, and
its kinds resolve to it. */