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 57f3fd636129 CAMEL-27035: camel-alibaba-kms - the plaintext header, 
the number of bytes, and the operation header in the catalog (#30258)
57f3fd636129 is described below

commit 57f3fd636129927e904e2f2aacaff371b90ec9a8
Author: Karol Krawczyk <[email protected]>
AuthorDate: Tue Nov 17 10:01:17 2026 +0100

    CAMEL-27035: camel-alibaba-kms - the plaintext header, the number of bytes, 
and the operation header in the catalog (#30258)
    
    …bytes, and the operation header in the catalog
    
    A Map or a POJO in the CamelAlibabaKmsPlaintext header, or in the exchange 
property of the same name, was encrypted as
    its toString(), because the value is read with getHeader(name, 
String.class). It now fails with an
    IllegalArgumentException, as the same value in the message body has since 
CAMEL-26258. A value is rejected only when
    the text the converter gives is the toString() of the object, which is what 
ToStringTypeConverter, the fallback that is
    never promoted, returns for an object no other converter reads as text. The 
message names the class and never the
    value, which is the plaintext.
    
    The CamelAlibabaKmsNumberOfBytes header is read only by generateDataKey, 
the only operation that sends it. Before,
    every exchange resolved it, so an empty or non-numeric value failed encrypt 
and decrypt too, with a
    TypeConversionException from Integer.valueOf. Such a value now fails 
generateDataKey alone, with a message that names
    the header, and an empty value counts as unset.
    
    region is no longer marked as required: region or endpoint is required, and 
the kmsClient option replaces both, which
    KMSUtils.createClient already says at runtime.
    
    KMSHeaders gets the OPERATION constant, so CamelAlibabaKmsOperation is in 
the header list of the component JSON, the
    endpoint DSL and the doc page, as PR #30048 did for camel-alibaba-mns. 
KMSProperties is now plain constants that point
    at KMSHeaders, as MNSProperties is: the Metadata texts it carried were read 
by nothing, since the build reads only the
    headers class the endpoint names.
    
    Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
---
 .../camel/catalog/components/alibaba-kms.json      |  15 +-
 .../camel/catalog/docs/alibaba-kms-component.adoc  |   7 +-
 .../camel/component/alibaba/kms/alibaba-kms.json   |  15 +-
 .../src/main/docs/alibaba-kms-component.adoc       |   7 +-
 .../camel/component/alibaba/kms/KMSEndpoint.java   |   4 +-
 .../camel/component/alibaba/kms/KMSUtils.java      |  94 +++++++-
 .../alibaba/kms/constants/KMSHeaders.java          |  24 +-
 .../alibaba/kms/constants/KMSProperties.java       |  33 +--
 .../camel/component/alibaba/kms/KMSInputTest.java  | 247 +++++++++++++++++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    |  18 ++
 .../endpoint/dsl/KMSEndpointBuilderFactory.java    |  26 ++-
 11 files changed, 432 insertions(+), 58 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/alibaba-kms.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/alibaba-kms.json
index 010ab88c1fb1..8f80932e69b1 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/alibaba-kms.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/alibaba-kms.json
@@ -30,12 +30,13 @@
     "healthCheckProducerEnabled": { "index": 3, "kind": "property", 
"displayName": "Health Check Producer Enabled", "group": "health", "label": 
"health", "required": false, "type": "boolean", "javaType": "boolean", 
"deprecated": false, "autowired": false, "secret": false, "defaultValue": true, 
"description": "Used for enabling or disabling all producer based health checks 
from this component. Notice: Camel has by default disabled all producer based 
health-checks. You can turn on producer [...]
   },
   "headers": {
-    "CamelAlibabaKmsKeyId": { "index": 0, "kind": "header", "displayName": "", 
"group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The ID, alias or ARN of the KMS key for encrypt and 
generateDataKey. This header replaces the keyId option. If this header is not 
set, an exchange property of the same name replaces the keyId option.", 
"constantName": "org.apache.camel.component.alibaba.km [...]
-    "CamelAlibabaKmsPlaintext": { "index": 1, "kind": "header", "displayName": 
"", "group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The plaintext for encrypt. The producer encodes it in UTF-8 and 
sends it to KMS in Base64. This header replaces the plaintext option. If this 
header is not set, an exchange property of the same name replaces the plaintext 
option.", "constantName": "org [...]
-    "CamelAlibabaKmsCiphertextBlob": { "index": 2, "kind": "header", 
"displayName": "", "group": "producer", "label": "producer", "required": false, 
"javaType": "String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The ciphertext blob for decrypt, for example from the response 
to encrypt or generateDataKey. This header replaces the ciphertextBlob option. 
If this header is not set, an exchange property of the same name replaces the 
ciphertextBlob option.", "c [...]
-    "CamelAlibabaKmsKeySpec": { "index": 3, "kind": "header", "displayName": 
"", "group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The key spec of the data key for generateDataKey. The value 
must be AES_256 or AES_128. KMS does not use it when the number of bytes is set 
as well. This header replaces the keySpec option. If this header is not set, an 
exchange property of the same name [...]
-    "CamelAlibabaKmsNumberOfBytes": { "index": 4, "kind": "header", 
"displayName": "", "group": "producer", "label": "producer", "required": false, 
"javaType": "Integer", "deprecated": false, "autowired": false, "secret": 
false, "description": "The number of bytes of the data key for generateDataKey. 
The value must be from 1 to 1024. This header replaces the numberOfBytes 
option. If this header is not set, an exchange property of the same name 
replaces the numberOfBytes option.", "consta [...]
-    "CamelAlibabaKmsRequestId": { "index": 5, "kind": "header", "displayName": 
"", "group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The request ID that KMS returns in the response to the 
operation. The producer sets it, unless the exchange fails.", "constantName": 
"org.apache.camel.component.alibaba.kms.constants.KMSHeaders#REQUEST_ID" }
+    "CamelAlibabaKmsOperation": { "index": 0, "kind": "header", "displayName": 
"", "group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The operation that the producer performs, which replaces the 
operation of the endpoint. If this header is not set, an exchange property of 
the same name replaces it.", "constantName": 
"org.apache.camel.component.alibaba.kms.constants.KMSHeaders#OPERATION" },
+    "CamelAlibabaKmsKeyId": { "index": 1, "kind": "header", "displayName": "", 
"group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The ID, alias or ARN of the KMS key for encrypt and 
generateDataKey. This header replaces the keyId option. If this header is not 
set, an exchange property of the same name replaces the keyId option.", 
"constantName": "org.apache.camel.component.alibaba.km [...]
+    "CamelAlibabaKmsPlaintext": { "index": 2, "kind": "header", "displayName": 
"", "group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The plaintext for encrypt. The producer encodes it in UTF-8 and 
sends it to KMS in Base64. This header replaces the plaintext option. If this 
header is not set, an exchange property of the same name replaces the plaintext 
option. A Map or a POJO fails, [...]
+    "CamelAlibabaKmsCiphertextBlob": { "index": 3, "kind": "header", 
"displayName": "", "group": "producer", "label": "producer", "required": false, 
"javaType": "String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The ciphertext blob for decrypt, for example from the response 
to encrypt or generateDataKey. This header replaces the ciphertextBlob option. 
If this header is not set, an exchange property of the same name replaces the 
ciphertextBlob option.", "c [...]
+    "CamelAlibabaKmsKeySpec": { "index": 4, "kind": "header", "displayName": 
"", "group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The key spec of the data key for generateDataKey. The value 
must be AES_256 or AES_128. KMS does not use it when the number of bytes is set 
as well. This header replaces the keySpec option. If this header is not set, an 
exchange property of the same name [...]
+    "CamelAlibabaKmsNumberOfBytes": { "index": 5, "kind": "header", 
"displayName": "", "group": "producer", "label": "producer", "required": false, 
"javaType": "Integer", "deprecated": false, "autowired": false, "secret": 
false, "description": "The number of bytes of the data key for generateDataKey. 
The value must be from 1 to 1024. This header replaces the numberOfBytes 
option. If this header is not set, an exchange property of the same name 
replaces the numberOfBytes option. Only gene [...]
+    "CamelAlibabaKmsRequestId": { "index": 6, "kind": "header", "displayName": 
"", "group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The request ID that KMS returns in the response to the 
operation. The producer sets it, unless the exchange fails.", "constantName": 
"org.apache.camel.component.alibaba.kms.constants.KMSHeaders#REQUEST_ID" }
   },
   "bodyTypes": {
     "producerIn": { "carriers": [ "any" ], "byOption": [ { "option": 
"operation", "value": "encrypt", "carriers": [ "text", "bytes", "stream", 
"file" ] }, { "option": "operation", "value": "decrypt", "carriers": [ "text" ] 
} ], "description": "encrypt encrypts the body unless the plaintext option or 
header is set: text in UTF-8, bytes as they are, and a stream or a file as its 
bytes, so binary data is kept. A Map or a POJO fails, as it does not convert to 
bytes, so marshal it first. decr [...]
@@ -47,7 +48,7 @@
     "keyId": { "index": 2, "kind": "parameter", "displayName": "Key Id", 
"group": "producer", "label": "", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The ID, alias or ARN of the KMS key for 
encrypt and generateDataKey. The CamelAlibabaKmsKeyId header replaces this 
option for a request that the producer sends. If that header is not set, an 
exchange property of the same name replaces this op [...]
     "keySpec": { "index": 3, "kind": "parameter", "displayName": "Key Spec", 
"group": "producer", "label": "", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The key spec of the data key for 
generateDataKey. The value must be AES_256 or AES_128. KMS does not use it when 
the number of bytes is set as well. The CamelAlibabaKmsKeySpec header replaces 
this option for a request that the producer se [...]
     "numberOfBytes": { "index": 4, "kind": "parameter", "displayName": "Number 
Of Bytes", "group": "producer", "label": "", "required": false, "type": 
"integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": 
false, "secret": false, "description": "The number of bytes of the data key for 
generateDataKey. The value must be from 1 to 1024. The 
CamelAlibabaKmsNumberOfBytes header replaces this option for a request that the 
producer sends. If that header is not set, an ex [...]
-    "region": { "index": 5, "kind": "parameter", "displayName": "Region", 
"group": "producer", "label": "", "required": true, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The region ID of KMS, for example cn-hangzhou. 
Only used when the endpoint option is not set, to build the endpoint of KMS. 
Not used when the kmsClient option is set or autowired." },
+    "region": { "index": 5, "kind": "parameter", "displayName": "Region", 
"group": "producer", "label": "", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The region ID of KMS, for example cn-hangzhou. 
Only used when the endpoint option is not set, to build the endpoint of KMS. 
One of the two is required, unless the kmsClient option is set or autowired, 
which uses neither." },
     "lazyStartProducer": { "index": 6, "kind": "parameter", "displayName": 
"Lazy Start Producer", "group": "producer (advanced)", "label": 
"producer,advanced", "required": false, "type": "boolean", "javaType": 
"boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Whether the producer should be started 
lazy (on the first message). By starting lazy you can use this to allow 
CamelContext and routes to startup in situations where a produc [...]
     "kmsClient": { "index": 7, "kind": "parameter", "displayName": "KMS 
Client", "group": "advanced", "label": "advanced", "required": false, "type": 
"object", "javaType": "com.aliyun.kms20160120.Client", "deprecated": false, 
"autowired": true, "secret": false, "description": "To use a custom 
com.aliyun.kms20160120.Client. The producer sends its requests with this 
client, and the region, endpoint, accessKey, secretKey and serviceKeys options 
are not used. If no client is set or autowired [...]
     "accessKey": { "index": 8, "kind": "parameter", "displayName": "Access 
Key", "group": "security", "label": "security", "required": false, "type": 
"string", "javaType": "java.lang.String", "deprecated": false, "autowired": 
false, "secret": true, "security": "secret", "description": "The AccessKey ID 
of the AccessKey pair for the requests that the producer sends to KMS. If not 
set, the accessKey of the serviceKeys option is used, and one of the two is 
required. Not used when the kmsCli [...]
diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/alibaba-kms-component.adoc
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/alibaba-kms-component.adoc
index 5c68c2e03ca8..dd54685aedb9 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/alibaba-kms-component.adoc
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/alibaba-kms-component.adoc
@@ -57,8 +57,11 @@ The component supports the following operations:
 `encrypt` encrypts the `plaintext` option or the `CamelAlibabaKmsPlaintext` 
header when one is set, else the message
 body. A `String` is encrypted in UTF-8, and a `byte[]`, an `InputStream` or a 
file as its bytes, so binary data is
 kept. The component sends these bytes to KMS in Base64, so the `plaintext` 
that `decrypt` returns for them is Base64:
-decode it to get the original bytes back. A `Map` or a POJO does not convert 
to bytes and fails with an
-`InvalidPayloadException`, so marshal it first. A message without a body fails 
with an `IllegalArgumentException`.
+decode it to get the original bytes back. A `Map` or a POJO fails instead of 
being encrypted as its `toString()`: in
+the body with an `InvalidPayloadException`, and in the header or in the 
exchange property of the same name with an
+`IllegalArgumentException`. Marshal such a value first, for example with 
`marshal().json()`. A value whose text is
+its `toString()`, such as a `UUID`, a `URI` or a `java.time` value, is 
encrypted as that text. A message without a
+body fails with an `IllegalArgumentException`.
 
 === Producer example
 
diff --git 
a/components/camel-alibaba/camel-alibaba-kms/src/generated/resources/META-INF/org/apache/camel/component/alibaba/kms/alibaba-kms.json
 
b/components/camel-alibaba/camel-alibaba-kms/src/generated/resources/META-INF/org/apache/camel/component/alibaba/kms/alibaba-kms.json
index 010ab88c1fb1..8f80932e69b1 100644
--- 
a/components/camel-alibaba/camel-alibaba-kms/src/generated/resources/META-INF/org/apache/camel/component/alibaba/kms/alibaba-kms.json
+++ 
b/components/camel-alibaba/camel-alibaba-kms/src/generated/resources/META-INF/org/apache/camel/component/alibaba/kms/alibaba-kms.json
@@ -30,12 +30,13 @@
     "healthCheckProducerEnabled": { "index": 3, "kind": "property", 
"displayName": "Health Check Producer Enabled", "group": "health", "label": 
"health", "required": false, "type": "boolean", "javaType": "boolean", 
"deprecated": false, "autowired": false, "secret": false, "defaultValue": true, 
"description": "Used for enabling or disabling all producer based health checks 
from this component. Notice: Camel has by default disabled all producer based 
health-checks. You can turn on producer [...]
   },
   "headers": {
-    "CamelAlibabaKmsKeyId": { "index": 0, "kind": "header", "displayName": "", 
"group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The ID, alias or ARN of the KMS key for encrypt and 
generateDataKey. This header replaces the keyId option. If this header is not 
set, an exchange property of the same name replaces the keyId option.", 
"constantName": "org.apache.camel.component.alibaba.km [...]
-    "CamelAlibabaKmsPlaintext": { "index": 1, "kind": "header", "displayName": 
"", "group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The plaintext for encrypt. The producer encodes it in UTF-8 and 
sends it to KMS in Base64. This header replaces the plaintext option. If this 
header is not set, an exchange property of the same name replaces the plaintext 
option.", "constantName": "org [...]
-    "CamelAlibabaKmsCiphertextBlob": { "index": 2, "kind": "header", 
"displayName": "", "group": "producer", "label": "producer", "required": false, 
"javaType": "String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The ciphertext blob for decrypt, for example from the response 
to encrypt or generateDataKey. This header replaces the ciphertextBlob option. 
If this header is not set, an exchange property of the same name replaces the 
ciphertextBlob option.", "c [...]
-    "CamelAlibabaKmsKeySpec": { "index": 3, "kind": "header", "displayName": 
"", "group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The key spec of the data key for generateDataKey. The value 
must be AES_256 or AES_128. KMS does not use it when the number of bytes is set 
as well. This header replaces the keySpec option. If this header is not set, an 
exchange property of the same name [...]
-    "CamelAlibabaKmsNumberOfBytes": { "index": 4, "kind": "header", 
"displayName": "", "group": "producer", "label": "producer", "required": false, 
"javaType": "Integer", "deprecated": false, "autowired": false, "secret": 
false, "description": "The number of bytes of the data key for generateDataKey. 
The value must be from 1 to 1024. This header replaces the numberOfBytes 
option. If this header is not set, an exchange property of the same name 
replaces the numberOfBytes option.", "consta [...]
-    "CamelAlibabaKmsRequestId": { "index": 5, "kind": "header", "displayName": 
"", "group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The request ID that KMS returns in the response to the 
operation. The producer sets it, unless the exchange fails.", "constantName": 
"org.apache.camel.component.alibaba.kms.constants.KMSHeaders#REQUEST_ID" }
+    "CamelAlibabaKmsOperation": { "index": 0, "kind": "header", "displayName": 
"", "group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The operation that the producer performs, which replaces the 
operation of the endpoint. If this header is not set, an exchange property of 
the same name replaces it.", "constantName": 
"org.apache.camel.component.alibaba.kms.constants.KMSHeaders#OPERATION" },
+    "CamelAlibabaKmsKeyId": { "index": 1, "kind": "header", "displayName": "", 
"group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The ID, alias or ARN of the KMS key for encrypt and 
generateDataKey. This header replaces the keyId option. If this header is not 
set, an exchange property of the same name replaces the keyId option.", 
"constantName": "org.apache.camel.component.alibaba.km [...]
+    "CamelAlibabaKmsPlaintext": { "index": 2, "kind": "header", "displayName": 
"", "group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The plaintext for encrypt. The producer encodes it in UTF-8 and 
sends it to KMS in Base64. This header replaces the plaintext option. If this 
header is not set, an exchange property of the same name replaces the plaintext 
option. A Map or a POJO fails, [...]
+    "CamelAlibabaKmsCiphertextBlob": { "index": 3, "kind": "header", 
"displayName": "", "group": "producer", "label": "producer", "required": false, 
"javaType": "String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The ciphertext blob for decrypt, for example from the response 
to encrypt or generateDataKey. This header replaces the ciphertextBlob option. 
If this header is not set, an exchange property of the same name replaces the 
ciphertextBlob option.", "c [...]
+    "CamelAlibabaKmsKeySpec": { "index": 4, "kind": "header", "displayName": 
"", "group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The key spec of the data key for generateDataKey. The value 
must be AES_256 or AES_128. KMS does not use it when the number of bytes is set 
as well. This header replaces the keySpec option. If this header is not set, an 
exchange property of the same name [...]
+    "CamelAlibabaKmsNumberOfBytes": { "index": 5, "kind": "header", 
"displayName": "", "group": "producer", "label": "producer", "required": false, 
"javaType": "Integer", "deprecated": false, "autowired": false, "secret": 
false, "description": "The number of bytes of the data key for generateDataKey. 
The value must be from 1 to 1024. This header replaces the numberOfBytes 
option. If this header is not set, an exchange property of the same name 
replaces the numberOfBytes option. Only gene [...]
+    "CamelAlibabaKmsRequestId": { "index": 6, "kind": "header", "displayName": 
"", "group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The request ID that KMS returns in the response to the 
operation. The producer sets it, unless the exchange fails.", "constantName": 
"org.apache.camel.component.alibaba.kms.constants.KMSHeaders#REQUEST_ID" }
   },
   "bodyTypes": {
     "producerIn": { "carriers": [ "any" ], "byOption": [ { "option": 
"operation", "value": "encrypt", "carriers": [ "text", "bytes", "stream", 
"file" ] }, { "option": "operation", "value": "decrypt", "carriers": [ "text" ] 
} ], "description": "encrypt encrypts the body unless the plaintext option or 
header is set: text in UTF-8, bytes as they are, and a stream or a file as its 
bytes, so binary data is kept. A Map or a POJO fails, as it does not convert to 
bytes, so marshal it first. decr [...]
@@ -47,7 +48,7 @@
     "keyId": { "index": 2, "kind": "parameter", "displayName": "Key Id", 
"group": "producer", "label": "", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The ID, alias or ARN of the KMS key for 
encrypt and generateDataKey. The CamelAlibabaKmsKeyId header replaces this 
option for a request that the producer sends. If that header is not set, an 
exchange property of the same name replaces this op [...]
     "keySpec": { "index": 3, "kind": "parameter", "displayName": "Key Spec", 
"group": "producer", "label": "", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The key spec of the data key for 
generateDataKey. The value must be AES_256 or AES_128. KMS does not use it when 
the number of bytes is set as well. The CamelAlibabaKmsKeySpec header replaces 
this option for a request that the producer se [...]
     "numberOfBytes": { "index": 4, "kind": "parameter", "displayName": "Number 
Of Bytes", "group": "producer", "label": "", "required": false, "type": 
"integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": 
false, "secret": false, "description": "The number of bytes of the data key for 
generateDataKey. The value must be from 1 to 1024. The 
CamelAlibabaKmsNumberOfBytes header replaces this option for a request that the 
producer sends. If that header is not set, an ex [...]
-    "region": { "index": 5, "kind": "parameter", "displayName": "Region", 
"group": "producer", "label": "", "required": true, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The region ID of KMS, for example cn-hangzhou. 
Only used when the endpoint option is not set, to build the endpoint of KMS. 
Not used when the kmsClient option is set or autowired." },
+    "region": { "index": 5, "kind": "parameter", "displayName": "Region", 
"group": "producer", "label": "", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The region ID of KMS, for example cn-hangzhou. 
Only used when the endpoint option is not set, to build the endpoint of KMS. 
One of the two is required, unless the kmsClient option is set or autowired, 
which uses neither." },
     "lazyStartProducer": { "index": 6, "kind": "parameter", "displayName": 
"Lazy Start Producer", "group": "producer (advanced)", "label": 
"producer,advanced", "required": false, "type": "boolean", "javaType": 
"boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Whether the producer should be started 
lazy (on the first message). By starting lazy you can use this to allow 
CamelContext and routes to startup in situations where a produc [...]
     "kmsClient": { "index": 7, "kind": "parameter", "displayName": "KMS 
Client", "group": "advanced", "label": "advanced", "required": false, "type": 
"object", "javaType": "com.aliyun.kms20160120.Client", "deprecated": false, 
"autowired": true, "secret": false, "description": "To use a custom 
com.aliyun.kms20160120.Client. The producer sends its requests with this 
client, and the region, endpoint, accessKey, secretKey and serviceKeys options 
are not used. If no client is set or autowired [...]
     "accessKey": { "index": 8, "kind": "parameter", "displayName": "Access 
Key", "group": "security", "label": "security", "required": false, "type": 
"string", "javaType": "java.lang.String", "deprecated": false, "autowired": 
false, "secret": true, "security": "secret", "description": "The AccessKey ID 
of the AccessKey pair for the requests that the producer sends to KMS. If not 
set, the accessKey of the serviceKeys option is used, and one of the two is 
required. Not used when the kmsCli [...]
diff --git 
a/components/camel-alibaba/camel-alibaba-kms/src/main/docs/alibaba-kms-component.adoc
 
b/components/camel-alibaba/camel-alibaba-kms/src/main/docs/alibaba-kms-component.adoc
index 5c68c2e03ca8..dd54685aedb9 100644
--- 
a/components/camel-alibaba/camel-alibaba-kms/src/main/docs/alibaba-kms-component.adoc
+++ 
b/components/camel-alibaba/camel-alibaba-kms/src/main/docs/alibaba-kms-component.adoc
@@ -57,8 +57,11 @@ The component supports the following operations:
 `encrypt` encrypts the `plaintext` option or the `CamelAlibabaKmsPlaintext` 
header when one is set, else the message
 body. A `String` is encrypted in UTF-8, and a `byte[]`, an `InputStream` or a 
file as its bytes, so binary data is
 kept. The component sends these bytes to KMS in Base64, so the `plaintext` 
that `decrypt` returns for them is Base64:
-decode it to get the original bytes back. A `Map` or a POJO does not convert 
to bytes and fails with an
-`InvalidPayloadException`, so marshal it first. A message without a body fails 
with an `IllegalArgumentException`.
+decode it to get the original bytes back. A `Map` or a POJO fails instead of 
being encrypted as its `toString()`: in
+the body with an `InvalidPayloadException`, and in the header or in the 
exchange property of the same name with an
+`IllegalArgumentException`. Marshal such a value first, for example with 
`marshal().json()`. A value whose text is
+its `toString()`, such as a `UUID`, a `URI` or a `java.time` value, is 
encrypted as that text. A message without a
+body fails with an `IllegalArgumentException`.
 
 === Producer example
 
diff --git 
a/components/camel-alibaba/camel-alibaba-kms/src/main/java/org/apache/camel/component/alibaba/kms/KMSEndpoint.java
 
b/components/camel-alibaba/camel-alibaba-kms/src/main/java/org/apache/camel/component/alibaba/kms/KMSEndpoint.java
index 05ec0ed9a5db..e61f85e6049a 100644
--- 
a/components/camel-alibaba/camel-alibaba-kms/src/main/java/org/apache/camel/component/alibaba/kms/KMSEndpoint.java
+++ 
b/components/camel-alibaba/camel-alibaba-kms/src/main/java/org/apache/camel/component/alibaba/kms/KMSEndpoint.java
@@ -66,9 +66,9 @@ public class KMSEndpoint extends DefaultEndpoint {
     private String operation;
 
     @UriParam(description = "The region ID of KMS, for example cn-hangzhou. 
Only used when the endpoint option is not set, to"
-                            + " build the endpoint of KMS. Not used when the 
kmsClient option is set or autowired.",
+                            + " build the endpoint of KMS. One of the two is 
required, unless the kmsClient option is set or"
+                            + " autowired, which uses neither.",
               displayName = "Region")
-    @Metadata(required = true)
     private String region;
 
     @UriParam(description = "The endpoint of KMS, which is a host name without 
http:// or https://. The producer sends requests"
diff --git 
a/components/camel-alibaba/camel-alibaba-kms/src/main/java/org/apache/camel/component/alibaba/kms/KMSUtils.java
 
b/components/camel-alibaba/camel-alibaba-kms/src/main/java/org/apache/camel/component/alibaba/kms/KMSUtils.java
index b155b0a679c5..71817a953024 100644
--- 
a/components/camel-alibaba/camel-alibaba-kms/src/main/java/org/apache/camel/component/alibaba/kms/KMSUtils.java
+++ 
b/components/camel-alibaba/camel-alibaba-kms/src/main/java/org/apache/camel/component/alibaba/kms/KMSUtils.java
@@ -16,10 +16,16 @@
  */
 package org.apache.camel.component.alibaba.kms;
 
+import java.net.URI;
+import java.net.URL;
 import java.nio.charset.StandardCharsets;
+import java.time.temporal.Temporal;
+import java.time.temporal.TemporalAmount;
 import java.util.Base64;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.UUID;
 
 import com.aliyun.kms20160120.Client;
 import com.aliyun.kms20160120.models.DecryptResponse;
@@ -32,8 +38,11 @@ import com.aliyun.teaopenapi.models.Config;
 import org.apache.camel.Exchange;
 import org.apache.camel.component.alibaba.common.OpenApiClientSupport;
 import org.apache.camel.component.alibaba.common.models.ServiceKeys;
+import org.apache.camel.component.alibaba.kms.constants.KMSOperations;
 import org.apache.camel.component.alibaba.kms.constants.KMSProperties;
 import org.apache.camel.component.alibaba.kms.models.ClientConfigurations;
+import org.apache.camel.spi.BodyTypeRegistry;
+import org.apache.camel.support.BodyFacts;
 import org.apache.camel.util.ObjectHelper;
 
 public final class KMSUtils {
@@ -70,13 +79,92 @@ public final class KMSUtils {
     }
 
     public static ClientConfigurations createClientConfigurations(KMSEndpoint 
endpoint, Exchange exchange) {
+        String operation = OpenApiClientSupport.resolveString(exchange, 
KMSProperties.OPERATION, endpoint.getOperation());
         return new ClientConfigurations(
-                OpenApiClientSupport.resolveString(exchange, 
KMSProperties.OPERATION, endpoint.getOperation()),
+                operation,
                 OpenApiClientSupport.resolveString(exchange, 
KMSProperties.KEY_ID, endpoint.getKeyId()),
-                OpenApiClientSupport.resolveString(exchange, 
KMSProperties.PLAINTEXT, endpoint.getPlaintext()),
+                resolvePlaintext(exchange, endpoint.getPlaintext()),
                 OpenApiClientSupport.resolveString(exchange, 
KMSProperties.CIPHERTEXT_BLOB, endpoint.getCiphertextBlob()),
                 OpenApiClientSupport.resolveString(exchange, 
KMSProperties.KEY_SPEC, endpoint.getKeySpec()),
-                OpenApiClientSupport.resolveInteger(exchange, 
KMSProperties.NUMBER_OF_BYTES, endpoint.getNumberOfBytes()));
+                KMSOperations.GENERATE_DATA_KEY.equals(operation)
+                        ? resolveNumberOfBytes(exchange, 
endpoint.getNumberOfBytes()) : null);
+    }
+
+    /**
+     * The plaintext of the plaintext header, of the exchange property of the 
same name, or of the plaintext option, in
+     * that order. A Map or a POJO fails, as it does in the message body since 
CAMEL-26258: Camel reads it only as its
+     * toString(), and KMS would encrypt that text.
+     */
+    private static String resolvePlaintext(Exchange exchange, String 
endpointValue) {
+        String plaintext = asText(exchange, 
exchange.getIn().getHeader(KMSProperties.PLAINTEXT), "header");
+        if (ObjectHelper.isEmpty(plaintext)) {
+            plaintext = asText(exchange, 
exchange.getProperty(KMSProperties.PLAINTEXT), "exchange property");
+        }
+        if (ObjectHelper.isEmpty(plaintext)) {
+            plaintext = endpointValue;
+        }
+        return plaintext;
+    }
+
+    /**
+     * The value as text, unless the text is no more than its toString(), 
which is what ToStringTypeConverter, the
+     * fallback that is never promoted, gives for an object no other converter 
reads as text. The message names the
+     * class but never the value, which is the plaintext.
+     */
+    private static String asText(Exchange exchange, Object value, String 
where) {
+        if (value == null) {
+            return null;
+        }
+        String text = 
exchange.getContext().getTypeConverter().convertTo(String.class, exchange, 
value);
+        if (text != null && BodyFacts.kindOf(value) != 
BodyTypeRegistry.Kind.PAYLOAD && !isTextValue(value)
+                && text.equals(value.toString())) {
+            throw new IllegalArgumentException(
+                    "The " + KMSProperties.PLAINTEXT + " " + where + " must be 
the plaintext as text, but it is a "
+                                               + value.getClass().getName()
+                                               + ", which Camel reads only as 
its toString(). Marshal it first, for"
+                                               + " example with 
marshal().json(), or set it to the text");
+        }
+        return text;
+    }
+
+    /**
+     * A value whose toString() is its text, rather than a dump of its fields: 
an id, an address or a point in time.
+     * BodyFacts counts text, a number, a boolean and an enum as a payload, 
but not these, and the type converter has
+     * nothing for them either, so they would otherwise be read as only a 
toString() (raised in the review of
+     * CAMEL-26521, which uses the same rule).
+     */
+    private static boolean isTextValue(Object value) {
+        return value instanceof UUID || value instanceof URI || value 
instanceof URL || value instanceof Temporal
+                || value instanceof TemporalAmount || value instanceof Date;
+    }
+
+    /**
+     * The number of bytes of the numberOfBytes header, of the exchange 
property of the same name, or of the
+     * numberOfBytes option, in that order. Only generateDataKey calls this, 
so a value that no other operation reads
+     * does not fail that operation, and a value that is not a number says so 
instead of failing the exchange with a
+     * TypeConversionException from the conversion of a header.
+     */
+    private static Integer resolveNumberOfBytes(Exchange exchange, Integer 
endpointValue) {
+        Integer numberOfBytes = toNumberOfBytes(exchange, 
exchange.getIn().getHeader(KMSProperties.NUMBER_OF_BYTES),
+                "header");
+        if (numberOfBytes == null) {
+            numberOfBytes = toNumberOfBytes(exchange, 
exchange.getProperty(KMSProperties.NUMBER_OF_BYTES),
+                    "exchange property");
+        }
+        return numberOfBytes != null ? numberOfBytes : endpointValue;
+    }
+
+    private static Integer toNumberOfBytes(Exchange exchange, Object value, 
String where) {
+        if (ObjectHelper.isEmpty(value)) {
+            return null;
+        }
+        Integer numberOfBytes = 
exchange.getContext().getTypeConverter().tryConvertTo(Integer.class, exchange, 
value);
+        if (numberOfBytes == null) {
+            throw new IllegalArgumentException(
+                    "The " + KMSProperties.NUMBER_OF_BYTES + " " + where
+                                               + " must be a number from 1 to 
1024, but it is " + value);
+        }
+        return numberOfBytes;
     }
 
     /**
diff --git 
a/components/camel-alibaba/camel-alibaba-kms/src/main/java/org/apache/camel/component/alibaba/kms/constants/KMSHeaders.java
 
b/components/camel-alibaba/camel-alibaba-kms/src/main/java/org/apache/camel/component/alibaba/kms/constants/KMSHeaders.java
index 5d21773295cb..98ac14933589 100644
--- 
a/components/camel-alibaba/camel-alibaba-kms/src/main/java/org/apache/camel/component/alibaba/kms/constants/KMSHeaders.java
+++ 
b/components/camel-alibaba/camel-alibaba-kms/src/main/java/org/apache/camel/component/alibaba/kms/constants/KMSHeaders.java
@@ -20,46 +20,54 @@ import org.apache.camel.spi.Metadata;
 
 public final class KMSHeaders {
 
+    @Metadata(label = "producer",
+              description = "The operation that the producer performs, which 
replaces the operation of the endpoint. If this"
+                            + " header is not set, an exchange property of the 
same name replaces it.",
+              javaType = "String")
+    public static final String OPERATION = "CamelAlibabaKmsOperation";
+
     @Metadata(label = "producer",
               description = "The ID, alias or ARN of the KMS key for encrypt 
and generateDataKey. This header replaces the"
                             + " keyId option. If this header is not set, an 
exchange property of the same name replaces the"
                             + " keyId option.",
               javaType = "String")
-    public static final String KEY_ID = KMSProperties.KEY_ID;
+    public static final String KEY_ID = "CamelAlibabaKmsKeyId";
 
     @Metadata(label = "producer",
               description = "The plaintext for encrypt. The producer encodes 
it in UTF-8 and sends it to KMS in Base64. This"
                             + " header replaces the plaintext option. If this 
header is not set, an exchange property of the"
-                            + " same name replaces the plaintext option.",
+                            + " same name replaces the plaintext option. A Map 
or a POJO fails, as it does in the message"
+                            + " body, since Camel reads it only as its 
toString().",
               javaType = "String")
-    public static final String PLAINTEXT = KMSProperties.PLAINTEXT;
+    public static final String PLAINTEXT = "CamelAlibabaKmsPlaintext";
 
     @Metadata(label = "producer",
               description = "The ciphertext blob for decrypt, for example from 
the response to encrypt or generateDataKey. This"
                             + " header replaces the ciphertextBlob option. If 
this header is not set, an exchange property of"
                             + " the same name replaces the ciphertextBlob 
option.",
               javaType = "String")
-    public static final String CIPHERTEXT_BLOB = KMSProperties.CIPHERTEXT_BLOB;
+    public static final String CIPHERTEXT_BLOB = 
"CamelAlibabaKmsCiphertextBlob";
 
     @Metadata(label = "producer",
               description = "The key spec of the data key for generateDataKey. 
The value must be AES_256 or AES_128. KMS does"
                             + " not use it when the number of bytes is set as 
well. This header replaces the keySpec option. If"
                             + " this header is not set, an exchange property 
of the same name replaces the keySpec option.",
               javaType = "String")
-    public static final String KEY_SPEC = KMSProperties.KEY_SPEC;
+    public static final String KEY_SPEC = "CamelAlibabaKmsKeySpec";
 
     @Metadata(label = "producer",
               description = "The number of bytes of the data key for 
generateDataKey. The value must be from 1 to 1024. This"
                             + " header replaces the numberOfBytes option. If 
this header is not set, an exchange property of"
-                            + " the same name replaces the numberOfBytes 
option.",
+                            + " the same name replaces the numberOfBytes 
option. Only generateDataKey reads it, and a value"
+                            + " that is not a number fails that operation 
alone.",
               javaType = "Integer")
-    public static final String NUMBER_OF_BYTES = KMSProperties.NUMBER_OF_BYTES;
+    public static final String NUMBER_OF_BYTES = 
"CamelAlibabaKmsNumberOfBytes";
 
     @Metadata(label = "producer",
               description = "The request ID that KMS returns in the response 
to the operation. The producer sets it, unless the"
                             + " exchange fails.",
               javaType = "String")
-    public static final String REQUEST_ID = KMSProperties.REQUEST_ID;
+    public static final String REQUEST_ID = "CamelAlibabaKmsRequestId";
 
     private KMSHeaders() {
     }
diff --git 
a/components/camel-alibaba/camel-alibaba-kms/src/main/java/org/apache/camel/component/alibaba/kms/constants/KMSProperties.java
 
b/components/camel-alibaba/camel-alibaba-kms/src/main/java/org/apache/camel/component/alibaba/kms/constants/KMSProperties.java
index dad1b122dd5d..86d39b8b3337 100644
--- 
a/components/camel-alibaba/camel-alibaba-kms/src/main/java/org/apache/camel/component/alibaba/kms/constants/KMSProperties.java
+++ 
b/components/camel-alibaba/camel-alibaba-kms/src/main/java/org/apache/camel/component/alibaba/kms/constants/KMSProperties.java
@@ -16,30 +16,19 @@
  */
 package org.apache.camel.component.alibaba.kms.constants;
 
-import org.apache.camel.spi.Metadata;
-
+/**
+ * The names the producer reads as an exchange property. Each one is read as a 
message header too, which
+ * {@link KMSHeaders} documents for the catalog.
+ */
 public final class KMSProperties {
 
-    @Metadata(label = "producer", description = "Operation to perform", 
javaType = "String")
-    public static final String OPERATION = "CamelAlibabaKmsOperation";
-
-    @Metadata(label = "producer", description = "KMS key id override", 
javaType = "String")
-    public static final String KEY_ID = "CamelAlibabaKmsKeyId";
-
-    @Metadata(label = "producer", description = "Plaintext to encrypt", 
javaType = "String")
-    public static final String PLAINTEXT = "CamelAlibabaKmsPlaintext";
-
-    @Metadata(label = "producer", description = "Ciphertext blob to decrypt", 
javaType = "String")
-    public static final String CIPHERTEXT_BLOB = 
"CamelAlibabaKmsCiphertextBlob";
-
-    @Metadata(label = "producer", description = "Key spec for 
generateDataKey", javaType = "String")
-    public static final String KEY_SPEC = "CamelAlibabaKmsKeySpec";
-
-    @Metadata(label = "producer", description = "Number of bytes for 
generateDataKey", javaType = "Integer")
-    public static final String NUMBER_OF_BYTES = 
"CamelAlibabaKmsNumberOfBytes";
-
-    @Metadata(label = "producer", description = "Request id returned by KMS 
API", javaType = "String")
-    public static final String REQUEST_ID = "CamelAlibabaKmsRequestId";
+    public static final String OPERATION = KMSHeaders.OPERATION;
+    public static final String KEY_ID = KMSHeaders.KEY_ID;
+    public static final String PLAINTEXT = KMSHeaders.PLAINTEXT;
+    public static final String CIPHERTEXT_BLOB = KMSHeaders.CIPHERTEXT_BLOB;
+    public static final String KEY_SPEC = KMSHeaders.KEY_SPEC;
+    public static final String NUMBER_OF_BYTES = KMSHeaders.NUMBER_OF_BYTES;
+    public static final String REQUEST_ID = KMSHeaders.REQUEST_ID;
 
     private KMSProperties() {
     }
diff --git 
a/components/camel-alibaba/camel-alibaba-kms/src/test/java/org/apache/camel/component/alibaba/kms/KMSInputTest.java
 
b/components/camel-alibaba/camel-alibaba-kms/src/test/java/org/apache/camel/component/alibaba/kms/KMSInputTest.java
new file mode 100644
index 000000000000..4398acc30153
--- /dev/null
+++ 
b/components/camel-alibaba/camel-alibaba-kms/src/test/java/org/apache/camel/component/alibaba/kms/KMSInputTest.java
@@ -0,0 +1,247 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.alibaba.kms;
+
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+import java.util.Map;
+import java.util.UUID;
+
+import com.aliyun.kms20160120.Client;
+import com.aliyun.kms20160120.models.EncryptRequest;
+import com.aliyun.kms20160120.models.EncryptResponse;
+import com.aliyun.kms20160120.models.EncryptResponseBody;
+import com.aliyun.kms20160120.models.GenerateDataKeyRequest;
+import com.aliyun.kms20160120.models.GenerateDataKeyResponse;
+import com.aliyun.kms20160120.models.GenerateDataKeyResponseBody;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.alibaba.kms.constants.KMSHeaders;
+import org.apache.camel.component.alibaba.kms.constants.KMSOperations;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * The operation, the plaintext and the number of bytes that the producer 
reads from a header or an exchange property:
+ * the plaintext must be text, as it must be in the message body, and only 
generateDataKey reads the number of bytes.
+ */
+class KMSInputTest extends CamelTestSupport {
+
+    private final TestConfiguration testConfiguration = new 
TestConfiguration();
+
+    @BindToRegistry("kmsClient")
+    Client kmsClient = mock(Client.class);
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:kms")
+                        .to("alibaba-kms:encrypt"
+                            + "?keyId=" + 
testConfiguration.getProperty("keyId")
+                            + "&region=" + 
testConfiguration.getProperty("region")
+                            + "&accessKey=" + 
testConfiguration.getProperty("accessKey")
+                            + "&secretKey=" + 
testConfiguration.getProperty("secretKey")
+                            + "&kmsClient=#kmsClient");
+            }
+        };
+    }
+
+    @Test
+    void theOperationHeaderReplacesTheOperationOfTheEndpoint() throws 
Exception {
+        stubGenerateDataKey();
+
+        template.sendBodyAndHeader("direct:kms", null, KMSHeaders.OPERATION, 
KMSOperations.GENERATE_DATA_KEY);
+
+        verify(kmsClient).generateDataKey(any(GenerateDataKeyRequest.class));
+        verify(kmsClient, never()).encrypt(any(EncryptRequest.class));
+    }
+
+    @Test
+    void thePlaintextHeaderIsEncryptedInUtf8() throws Exception {
+        String text = "Zürich €";
+        stubEncrypt();
+
+        template.sendBodyAndHeader("direct:kms", null, KMSHeaders.PLAINTEXT, 
text);
+
+        
assertThat(encryptedPlaintext()).isEqualTo(text.getBytes(StandardCharsets.UTF_8));
+    }
+
+    @Test
+    void aBytesPlaintextHeaderIsReadAsItsText() throws Exception {
+        stubEncrypt();
+
+        template.sendBodyAndHeader("direct:kms", null, KMSHeaders.PLAINTEXT,
+                "secret".getBytes(StandardCharsets.UTF_8));
+
+        
assertThat(encryptedPlaintext()).isEqualTo("secret".getBytes(StandardCharsets.UTF_8));
+    }
+
+    /** A value whose text is its toString(), which the type converter has 
nothing for. */
+    @Test
+    void aUuidAndAUriPlaintextHeaderAreEncryptedAsTheirText() throws Exception 
{
+        stubEncrypt();
+        UUID uuid = UUID.randomUUID();
+
+        template.sendBodyAndHeader("direct:kms", null, KMSHeaders.PLAINTEXT, 
uuid);
+
+        
assertThat(encryptedPlaintext()).isEqualTo(uuid.toString().getBytes(StandardCharsets.UTF_8));
+
+        template.sendBodyAndHeader("direct:kms", null, KMSHeaders.PLAINTEXT, 
URI.create("https://camel.apache.org";));
+
+        ArgumentCaptor<EncryptRequest> request = 
ArgumentCaptor.forClass(EncryptRequest.class);
+        verify(kmsClient, times(2)).encrypt(request.capture());
+        
assertThat(Base64.getDecoder().decode(request.getValue().getPlaintext()))
+                
.isEqualTo("https://camel.apache.org".getBytes(StandardCharsets.UTF_8));
+    }
+
+    @Test
+    void aMapInThePlaintextHeaderFailsInsteadOfBeingEncryptedAsItsToString() 
throws Exception {
+        stubEncrypt();
+
+        assertThatThrownBy(() -> template.sendBodyAndHeader("direct:kms", 
null, KMSHeaders.PLAINTEXT,
+                Map.of("secret", "value")))
+                .isInstanceOf(CamelExecutionException.class)
+                .cause()
+                .isInstanceOf(IllegalArgumentException.class)
+                .hasMessageContaining(KMSHeaders.PLAINTEXT + " header")
+                .hasMessageContaining("Map")
+                // the plaintext is a secret, so the message says the class 
and not the value
+                .hasMessageNotContaining("value");
+
+        verify(kmsClient, never()).encrypt(any(EncryptRequest.class));
+    }
+
+    @Test
+    void aPojoInThePlaintextExchangePropertyFails() throws Exception {
+        stubEncrypt();
+
+        Exchange result = template.send("direct:kms",
+                exchange -> exchange.setProperty(KMSHeaders.PLAINTEXT, new 
Secret("value")));
+
+        assertThat(result.getException())
+                .isInstanceOf(IllegalArgumentException.class)
+                .hasMessageContaining(KMSHeaders.PLAINTEXT + " exchange 
property")
+                .hasMessageContaining(Secret.class.getName());
+
+        verify(kmsClient, never()).encrypt(any(EncryptRequest.class));
+    }
+
+    @Test
+    void anInvalidNumberOfBytesHeaderDoesNotFailEncrypt() throws Exception {
+        stubEncrypt();
+
+        Exchange result = template.send("direct:kms", exchange -> {
+            exchange.getIn().setHeader(KMSHeaders.NUMBER_OF_BYTES, "abc");
+            exchange.getIn().setHeader(KMSHeaders.PLAINTEXT, "secret");
+        });
+
+        assertThat(result.getException()).isNull();
+        
assertThat(encryptedPlaintext()).isEqualTo("secret".getBytes(StandardCharsets.UTF_8));
+    }
+
+    @Test
+    void anInvalidNumberOfBytesHeaderFailsGenerateDataKey() throws Exception {
+        stubGenerateDataKey();
+
+        Exchange result = template.send("direct:kms", exchange -> {
+            exchange.getIn().setHeader(KMSHeaders.OPERATION, 
KMSOperations.GENERATE_DATA_KEY);
+            exchange.getIn().setHeader(KMSHeaders.NUMBER_OF_BYTES, "abc");
+        });
+
+        assertThat(result.getException())
+                .isInstanceOf(IllegalArgumentException.class)
+                .hasMessageContaining(KMSHeaders.NUMBER_OF_BYTES + " header")
+                .hasMessageContaining("abc");
+
+        verify(kmsClient, 
never()).generateDataKey(any(GenerateDataKeyRequest.class));
+    }
+
+    @Test
+    void anEmptyNumberOfBytesHeaderCountsAsUnset() throws Exception {
+        stubGenerateDataKey();
+
+        Exchange result = template.send("direct:kms", exchange -> {
+            exchange.getIn().setHeader(KMSHeaders.OPERATION, 
KMSOperations.GENERATE_DATA_KEY);
+            exchange.getIn().setHeader(KMSHeaders.NUMBER_OF_BYTES, "");
+        });
+
+        assertThat(result.getException()).isNull();
+        assertThat(generateDataKeyRequest().getNumberOfBytes()).isNull();
+    }
+
+    @Test
+    void theNumberOfBytesHeaderIsSentAsANumber() throws Exception {
+        stubGenerateDataKey();
+
+        Exchange result = template.send("direct:kms", exchange -> {
+            exchange.getIn().setHeader(KMSHeaders.OPERATION, 
KMSOperations.GENERATE_DATA_KEY);
+            exchange.getIn().setHeader(KMSHeaders.NUMBER_OF_BYTES, "32");
+        });
+
+        assertThat(result.getException()).isNull();
+        assertThat(generateDataKeyRequest().getNumberOfBytes()).isEqualTo(32);
+    }
+
+    private byte[] encryptedPlaintext() throws Exception {
+        ArgumentCaptor<EncryptRequest> request = 
ArgumentCaptor.forClass(EncryptRequest.class);
+        verify(kmsClient).encrypt(request.capture());
+        return Base64.getDecoder().decode(request.getValue().getPlaintext());
+    }
+
+    private GenerateDataKeyRequest generateDataKeyRequest() throws Exception {
+        ArgumentCaptor<GenerateDataKeyRequest> request = 
ArgumentCaptor.forClass(GenerateDataKeyRequest.class);
+        verify(kmsClient).generateDataKey(request.capture());
+        return request.getValue();
+    }
+
+    private void stubEncrypt() throws Exception {
+        EncryptResponseBody responseBody = new EncryptResponseBody();
+        responseBody.setCiphertextBlob("encrypted-data");
+        EncryptResponse response = new EncryptResponse();
+        response.setStatusCode(200);
+        response.setBody(responseBody);
+        
when(kmsClient.encrypt(any(EncryptRequest.class))).thenReturn(response);
+    }
+
+    private void stubGenerateDataKey() throws Exception {
+        GenerateDataKeyResponseBody responseBody = new 
GenerateDataKeyResponseBody();
+        responseBody.setCiphertextBlob("encrypted-data-key");
+        responseBody.setPlaintext("data-key");
+        GenerateDataKeyResponse response = new GenerateDataKeyResponse();
+        response.setStatusCode(200);
+        response.setBody(responseBody);
+        
when(kmsClient.generateDataKey(any(GenerateDataKeyRequest.class))).thenReturn(response);
+    }
+
+    private record Secret(String value) {
+    }
+}
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 1597253f71b9..a3fa2a04f84e 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -9626,3 +9626,21 @@ ThymeleafEndpoint endpoint = 
context.getEndpoint("thymeleaf:greeting.html?resolv
 endpoint.setJakartaServletWebApplication(
         JakartaServletWebApplication.buildApplication(servletContext));
 ----
+
+=== camel-alibaba-kms - a Map or a POJO in the plaintext header fails, and 
only generateDataKey reads numberOfBytes
+
+A `Map` or a POJO in the `CamelAlibabaKmsPlaintext` header, or in the exchange 
property of the same name, now fails
+with an `IllegalArgumentException` instead of being encrypted as its 
`toString()`. CAMEL-26258 made the same value in
+the message body fail with an `InvalidPayloadException`; the header kept 
encrypting the text of the object. Marshal
+such a value first, for example with `marshal().json()`, or set the header to 
the text. Text, bytes, a stream, a file
+and a value whose text is its `toString()`, such as a `UUID`, a `URI` or a 
`java.time` value, are read as before.
+
+The `CamelAlibabaKmsNumberOfBytes` header and the exchange property of the 
same name are now read only by
+`generateDataKey`, which is the only operation that sends the value. Before, 
every exchange resolved them, so a value
+that is not a number failed `encrypt` and `decrypt` too, with a 
`TypeConversionException` from the conversion of the
+header. Such a value now fails `generateDataKey` alone, with an 
`IllegalArgumentException` that names the header, and
+an empty value counts as unset.
+
+The `region` option is no longer marked as required in the catalog, since 
`region` or `endpoint` is required and the
+`kmsClient` option replaces both. The producer still fails with "Region or 
endpoint is required" when it has to create
+a client and neither is set.
diff --git 
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/KMSEndpointBuilderFactory.java
 
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/KMSEndpointBuilderFactory.java
index 2d7fe17b96d9..17d6897946c7 100644
--- 
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/KMSEndpointBuilderFactory.java
+++ 
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/KMSEndpointBuilderFactory.java
@@ -139,12 +139,12 @@ public interface KMSEndpointBuilderFactory {
         }
         /**
          * The region ID of KMS, for example cn-hangzhou. Only used when the
-         * endpoint option is not set, to build the endpoint of KMS. Not used
-         * when the kmsClient option is set or autowired.
+         * endpoint option is not set, to build the endpoint of KMS. One of the
+         * two is required, unless the kmsClient option is set or autowired,
+         * which uses neither.
          * 
          * The option is a: <code>java.lang.String</code> type.
          * 
-         * Required: true
          * Group: producer
          * 
          * @param region the value to set
@@ -440,6 +440,20 @@ public interface KMSEndpointBuilderFactory {
          */
         public static final KMSHeaderNameBuilder INSTANCE = new 
KMSHeaderNameBuilder();
 
+        /**
+         * The operation that the producer performs, which replaces the
+         * operation of the endpoint. If this header is not set, an exchange
+         * property of the same name replaces it.
+         * 
+         * The option is a: {@code String} type.
+         * 
+         * Group: producer
+         * 
+         * @return the name of the header {@code AlibabaKmsOperation}.
+         */
+        public String alibabaKmsOperation() {
+            return "CamelAlibabaKmsOperation";
+        }
         /**
          * The ID, alias or ARN of the KMS key for encrypt and generateDataKey.
          * This header replaces the keyId option. If this header is not set, an
@@ -458,7 +472,8 @@ public interface KMSEndpointBuilderFactory {
          * The plaintext for encrypt. The producer encodes it in UTF-8 and 
sends
          * it to KMS in Base64. This header replaces the plaintext option. If
          * this header is not set, an exchange property of the same name
-         * replaces the plaintext option.
+         * replaces the plaintext option. A Map or a POJO fails, as it does in
+         * the message body, since Camel reads it only as its toString().
          * 
          * The option is a: {@code String} type.
          * 
@@ -504,7 +519,8 @@ public interface KMSEndpointBuilderFactory {
          * The number of bytes of the data key for generateDataKey. The value
          * must be from 1 to 1024. This header replaces the numberOfBytes
          * option. If this header is not set, an exchange property of the same
-         * name replaces the numberOfBytes option.
+         * name replaces the numberOfBytes option. Only generateDataKey reads
+         * it, and a value that is not a number fails that operation alone.
          * 
          * The option is a: {@code Integer} type.
          * 

Reply via email to