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-kamelets.git


The following commit(s) were added to refs/heads/main by this push:
     new 8c31faeeb chore: mllp-sink sends text in the charset of MSH-18, and 
the charset workarounds of mllp-source and mllp-sink are gone (CAMEL-27366) 
(#3351)
8c31faeeb is described below

commit 8c31faeebcffa3a7cb9ac8b80278d7ac1d2ebe6f
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 22 17:17:29 2026 +0100

    chore: mllp-sink sends text in the charset of MSH-18, and the charset 
workarounds of mllp-source and mllp-sink are gone (CAMEL-27366) (#3351)
    
    Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 kamelets/mllp-sink.kamelet.yaml                    | 15 +++--------
 kamelets/mllp-source.kamelet.yaml                  | 10 ++++----
 .../main/resources/META-INF/kamelets-index.json    |  4 +--
 .../main/resources/kamelets/mllp-sink.kamelet.yaml | 15 +++--------
 .../resources/kamelets/mllp-source.kamelet.yaml    | 10 ++++----
 .../src/test/resources/mllp/mllp-sink-route.yaml   | 15 +++++++++++
 .../resources/mllp/mllp-sink-source.citrus.it.yaml | 30 +++++++++++++++++++++-
 .../src/test/resources/mllp/mllp-source-route.yaml |  1 +
 8 files changed, 63 insertions(+), 37 deletions(-)

diff --git a/kamelets/mllp-sink.kamelet.yaml b/kamelets/mllp-sink.kamelet.yaml
index d36fc74fa..fcd99eda0 100644
--- a/kamelets/mllp-sink.kamelet.yaml
+++ b/kamelets/mllp-sink.kamelet.yaml
@@ -36,11 +36,11 @@ spec:
 
       Use it to send admissions, orders or results to a hospital information 
system, a lab system or an interface engine that receives HL7 v2 over MLLP, or 
to forward the messages that `mllp-source` receives. To write FHIR resources 
instead, use `fhir-sink`.
 
-      Input: the body is the HL7 message, as text with its segments separated 
by a carriage return (`\r`), or as bytes, which are sent as they are. Text is 
sent in `charset`, which is ISO-8859-1 when it is not set: set it to the 
charset that the MSH-18 field of the messages names, such as `UTF-8` for 
`UNICODE UTF-8`, because it is not read from the message.
+      Input: the body is the HL7 message, as text with its segments separated 
by a carriage return (`\r`), or as bytes, which are sent as they are. Text is 
sent in the charset that the MSH-18 field of the message names, such as 
`UNICODE UTF-8`, or in `charset` when MSH-18 is empty.
 
       Output: when it is used inside a route, the body is unchanged 
afterwards. `CamelMllpAcknowledgementType` is the code of the acknowledgement, 
`AA` when the receiver accepted the message, `CamelMllpAcknowledgementString` 
the acknowledgement as text, and `CamelMllpAcknowledgement` the same as bytes.
 
-      Good to know: an acknowledgement `AE` (error) or `AR` (rejected) fails 
the message, and `CamelMllpAcknowledgementType` and 
`CamelMllpAcknowledgementString` are still set, so that a step that handles the 
error can read the reason in the MSA-3 field. A receiver that cannot be 
reached, or that does not answer within `ackTimeout`, fails the message. It 
connects at the first message and keeps the connection open for the next ones. 
It connects with no TLS. For TLS, set the application pr [...]
+      Good to know: an acknowledgement `AE` (error) or `AR` (rejected) fails 
the message, and `CamelMllpAcknowledgementType` and 
`CamelMllpAcknowledgementString` are still set, so that a step that handles the 
error can read the reason in the MSA-3 field. A receiver that cannot be 
reached, or that does not answer within `ackTimeout`, fails the message. It 
connects at the first message and keeps the connection open for the next ones. 
It connects with no TLS. For TLS, set the application pr [...]
     required:
     - host
     - port
@@ -59,7 +59,7 @@ spec:
         example: 2575
       charset:
         title: Charset
-        description: The charset to send text in, such as `UTF-8`. Set it to 
the charset that MSH-18 of the messages names; it is not read from the message. 
It is also used to read the acknowledgement when its MSH-18 is empty.
+        description: The charset to send text in when the MSH-18 field of the 
message is empty, such as `UTF-8`. A message whose MSH-18 names a charset, such 
as `UNICODE UTF-8` or `8859/1`, is sent in that charset. It is also used to 
read the acknowledgement when its MSH-18 is empty.
         type: string
         default: ISO-8859-1
         example: UTF-8
@@ -97,15 +97,6 @@ spec:
       steps:
         - removeHeaders:
             pattern: CamelMllpAcknowledgement*
-        # The charset of the text is `charset`: a CamelCharsetName header or 
exchange property, which
-        # the MLLP component reads first and which mllp-source and earlier 
MLLP sends set, would win.
-        - removeHeader:
-            name: CamelCharsetName
-        - setProperty:
-            name: CamelCharsetName
-            expression:
-              constant:
-                expression: "{{charset}}"
         - to:
             uri: mllp
             parameters:
diff --git a/kamelets/mllp-source.kamelet.yaml 
b/kamelets/mllp-source.kamelet.yaml
index 9953e2062..15f929756 100644
--- a/kamelets/mllp-source.kamelet.yaml
+++ b/kamelets/mllp-source.kamelet.yaml
@@ -36,7 +36,7 @@ spec:
 
       Use it to receive the HL7 v2 feed of a hospital information system, a 
lab system or an interface engine, for example to store the messages, or to 
turn them into FHIR resources for `fhir-sink`. To send HL7 v2 messages, use 
`mllp-sink`.
 
-      Output: the body is the HL7 message, as text, with its segments 
separated by a carriage return (`\r`). The text is read in the charset that the 
MSH-18 field of the message names, such as `UNICODE UTF-8`, or in `charset` 
when MSH-18 is empty. Headers give the fields of the MSH segment: 
`CamelMllpMessageType` (MSH-9, such as `ADT^A01`), split into 
`CamelMllpEventType` (`ADT`) and `CamelMllpTriggerEvent` (`A01`), 
`CamelMllpMessageControlId` (MSH-10), `CamelMllpSendingApplication` and  [...]
+      Output: the body is the HL7 message, as text, with its segments 
separated by a carriage return (`\r`). The text is read in the charset that the 
MSH-18 field of the message names, such as `UNICODE UTF-8`, or in `charset` 
when MSH-18 is empty. Headers give the fields of the MSH segment: 
`CamelMllpMessageType` (MSH-9, such as `ADT^A01`), split into 
`CamelMllpEventType` (`ADT`) and `CamelMllpTriggerEvent` (`A01`), 
`CamelMllpMessageControlId` (MSH-10), `CamelMllpSendingApplication` and  [...]
 
       Good to know: it answers each message with an HL7 acknowledgement (ACK) 
once the rest of the flow has processed it, and the sender waits for it: `AA` 
(accepted), or `AE` (error) when a step of the flow fails, with the name of the 
error in the MSA-3 field. A message without a complete MSH segment still 
reaches the flow, but gets no acknowledgement. It listens on all the network 
interfaces of the machine unless `host` says otherwise, with no login and no 
TLS, so anyone who can reach  [...]
     required:
@@ -110,6 +110,10 @@ spec:
           title: Version ID
           description: The HL7 version of the message, from MSH-12, such as 
`2.5`.
           type: string
+        CamelMllpCharset:
+          title: Charset
+          description: The charset of the message, from MSH-18, such as 
`UNICODE UTF-8`.
+          type: string
         CamelMllpRemoteAddress:
           title: Remote Address
           description: The address and port of the sender, such as 
`/10.0.0.5:51234`.
@@ -125,9 +129,5 @@ spec:
         port: "{{port}}"
         charsetName: "{{?charset}}"
       steps:
-        # The component marks the message with its charset (ISO-8859-1 by 
default), which would then
-        # turn the text into bytes in that charset in the later steps, 
whatever MSH-18 says.
-        - removeProperty:
-            name: CamelCharsetName
         - to:
             uri: kamelet:sink
diff --git 
a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json 
b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
index 2e1fe6a09..dc95dbcd5 100644
--- a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
+++ b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
@@ -1505,7 +1505,7 @@
     "supportLevel" : "Stable",
     "title" : "MLLP Sink",
     "summary" : "Sends each message as an HL7 v2 message to a hospital system 
over MLLP, a plain TCP connection, and waits for its HL7 acknowledgement 
(ACK).",
-    "description" : "Sends each message as an HL7 v2 message to a hospital 
system over MLLP, a plain TCP connection, and waits for its HL7 acknowledgement 
(ACK).\n\nUse it to send admissions, orders or results to a hospital 
information system, a lab system or an interface engine that receives HL7 v2 
over MLLP, or to forward the messages that `mllp-source` receives. To write 
FHIR resources instead, use `fhir-sink`.\n\nInput: the body is the HL7 message, 
as text with its segments separated [...]
+    "description" : "Sends each message as an HL7 v2 message to a hospital 
system over MLLP, a plain TCP connection, and waits for its HL7 acknowledgement 
(ACK).\n\nUse it to send admissions, orders or results to a hospital 
information system, a lab system or an interface engine that receives HL7 v2 
over MLLP, or to forward the messages that `mllp-source` receives. To write 
FHIR resources instead, use `fhir-sink`.\n\nInput: the body is the HL7 message, 
as text with its segments separated [...]
     "group" : "MLLP",
     "namespace" : "Messaging",
     "provider" : "Apache Software Foundation"
@@ -1515,7 +1515,7 @@
     "supportLevel" : "Stable",
     "title" : "MLLP Source",
     "summary" : "Receives HL7 v2 messages, such as admissions (ADT) or lab 
results (ORU), that hospital systems send over MLLP, a plain TCP connection, 
and acknowledges each one.",
-    "description" : "Receives HL7 v2 messages, such as admissions (ADT) or lab 
results (ORU), that hospital systems send over MLLP, a plain TCP connection, 
and acknowledges each one.\n\nUse it to receive the HL7 v2 feed of a hospital 
information system, a lab system or an interface engine, for example to store 
the messages, or to turn them into FHIR resources for `fhir-sink`. To send HL7 
v2 messages, use `mllp-sink`.\n\nOutput: the body is the HL7 message, as text, 
with its segments sepa [...]
+    "description" : "Receives HL7 v2 messages, such as admissions (ADT) or lab 
results (ORU), that hospital systems send over MLLP, a plain TCP connection, 
and acknowledges each one.\n\nUse it to receive the HL7 v2 feed of a hospital 
information system, a lab system or an interface engine, for example to store 
the messages, or to turn them into FHIR resources for `fhir-sink`. To send HL7 
v2 messages, use `mllp-sink`.\n\nOutput: the body is the HL7 message, as text, 
with its segments sepa [...]
     "group" : "MLLP",
     "namespace" : "Messaging",
     "provider" : "Apache Software Foundation"
diff --git 
a/library/camel-kamelets/src/main/resources/kamelets/mllp-sink.kamelet.yaml 
b/library/camel-kamelets/src/main/resources/kamelets/mllp-sink.kamelet.yaml
index d36fc74fa..fcd99eda0 100644
--- a/library/camel-kamelets/src/main/resources/kamelets/mllp-sink.kamelet.yaml
+++ b/library/camel-kamelets/src/main/resources/kamelets/mllp-sink.kamelet.yaml
@@ -36,11 +36,11 @@ spec:
 
       Use it to send admissions, orders or results to a hospital information 
system, a lab system or an interface engine that receives HL7 v2 over MLLP, or 
to forward the messages that `mllp-source` receives. To write FHIR resources 
instead, use `fhir-sink`.
 
-      Input: the body is the HL7 message, as text with its segments separated 
by a carriage return (`\r`), or as bytes, which are sent as they are. Text is 
sent in `charset`, which is ISO-8859-1 when it is not set: set it to the 
charset that the MSH-18 field of the messages names, such as `UTF-8` for 
`UNICODE UTF-8`, because it is not read from the message.
+      Input: the body is the HL7 message, as text with its segments separated 
by a carriage return (`\r`), or as bytes, which are sent as they are. Text is 
sent in the charset that the MSH-18 field of the message names, such as 
`UNICODE UTF-8`, or in `charset` when MSH-18 is empty.
 
       Output: when it is used inside a route, the body is unchanged 
afterwards. `CamelMllpAcknowledgementType` is the code of the acknowledgement, 
`AA` when the receiver accepted the message, `CamelMllpAcknowledgementString` 
the acknowledgement as text, and `CamelMllpAcknowledgement` the same as bytes.
 
-      Good to know: an acknowledgement `AE` (error) or `AR` (rejected) fails 
the message, and `CamelMllpAcknowledgementType` and 
`CamelMllpAcknowledgementString` are still set, so that a step that handles the 
error can read the reason in the MSA-3 field. A receiver that cannot be 
reached, or that does not answer within `ackTimeout`, fails the message. It 
connects at the first message and keeps the connection open for the next ones. 
It connects with no TLS. For TLS, set the application pr [...]
+      Good to know: an acknowledgement `AE` (error) or `AR` (rejected) fails 
the message, and `CamelMllpAcknowledgementType` and 
`CamelMllpAcknowledgementString` are still set, so that a step that handles the 
error can read the reason in the MSA-3 field. A receiver that cannot be 
reached, or that does not answer within `ackTimeout`, fails the message. It 
connects at the first message and keeps the connection open for the next ones. 
It connects with no TLS. For TLS, set the application pr [...]
     required:
     - host
     - port
@@ -59,7 +59,7 @@ spec:
         example: 2575
       charset:
         title: Charset
-        description: The charset to send text in, such as `UTF-8`. Set it to 
the charset that MSH-18 of the messages names; it is not read from the message. 
It is also used to read the acknowledgement when its MSH-18 is empty.
+        description: The charset to send text in when the MSH-18 field of the 
message is empty, such as `UTF-8`. A message whose MSH-18 names a charset, such 
as `UNICODE UTF-8` or `8859/1`, is sent in that charset. It is also used to 
read the acknowledgement when its MSH-18 is empty.
         type: string
         default: ISO-8859-1
         example: UTF-8
@@ -97,15 +97,6 @@ spec:
       steps:
         - removeHeaders:
             pattern: CamelMllpAcknowledgement*
-        # The charset of the text is `charset`: a CamelCharsetName header or 
exchange property, which
-        # the MLLP component reads first and which mllp-source and earlier 
MLLP sends set, would win.
-        - removeHeader:
-            name: CamelCharsetName
-        - setProperty:
-            name: CamelCharsetName
-            expression:
-              constant:
-                expression: "{{charset}}"
         - to:
             uri: mllp
             parameters:
diff --git 
a/library/camel-kamelets/src/main/resources/kamelets/mllp-source.kamelet.yaml 
b/library/camel-kamelets/src/main/resources/kamelets/mllp-source.kamelet.yaml
index 9953e2062..15f929756 100644
--- 
a/library/camel-kamelets/src/main/resources/kamelets/mllp-source.kamelet.yaml
+++ 
b/library/camel-kamelets/src/main/resources/kamelets/mllp-source.kamelet.yaml
@@ -36,7 +36,7 @@ spec:
 
       Use it to receive the HL7 v2 feed of a hospital information system, a 
lab system or an interface engine, for example to store the messages, or to 
turn them into FHIR resources for `fhir-sink`. To send HL7 v2 messages, use 
`mllp-sink`.
 
-      Output: the body is the HL7 message, as text, with its segments 
separated by a carriage return (`\r`). The text is read in the charset that the 
MSH-18 field of the message names, such as `UNICODE UTF-8`, or in `charset` 
when MSH-18 is empty. Headers give the fields of the MSH segment: 
`CamelMllpMessageType` (MSH-9, such as `ADT^A01`), split into 
`CamelMllpEventType` (`ADT`) and `CamelMllpTriggerEvent` (`A01`), 
`CamelMllpMessageControlId` (MSH-10), `CamelMllpSendingApplication` and  [...]
+      Output: the body is the HL7 message, as text, with its segments 
separated by a carriage return (`\r`). The text is read in the charset that the 
MSH-18 field of the message names, such as `UNICODE UTF-8`, or in `charset` 
when MSH-18 is empty. Headers give the fields of the MSH segment: 
`CamelMllpMessageType` (MSH-9, such as `ADT^A01`), split into 
`CamelMllpEventType` (`ADT`) and `CamelMllpTriggerEvent` (`A01`), 
`CamelMllpMessageControlId` (MSH-10), `CamelMllpSendingApplication` and  [...]
 
       Good to know: it answers each message with an HL7 acknowledgement (ACK) 
once the rest of the flow has processed it, and the sender waits for it: `AA` 
(accepted), or `AE` (error) when a step of the flow fails, with the name of the 
error in the MSA-3 field. A message without a complete MSH segment still 
reaches the flow, but gets no acknowledgement. It listens on all the network 
interfaces of the machine unless `host` says otherwise, with no login and no 
TLS, so anyone who can reach  [...]
     required:
@@ -110,6 +110,10 @@ spec:
           title: Version ID
           description: The HL7 version of the message, from MSH-12, such as 
`2.5`.
           type: string
+        CamelMllpCharset:
+          title: Charset
+          description: The charset of the message, from MSH-18, such as 
`UNICODE UTF-8`.
+          type: string
         CamelMllpRemoteAddress:
           title: Remote Address
           description: The address and port of the sender, such as 
`/10.0.0.5:51234`.
@@ -125,9 +129,5 @@ spec:
         port: "{{port}}"
         charsetName: "{{?charset}}"
       steps:
-        # The component marks the message with its charset (ISO-8859-1 by 
default), which would then
-        # turn the text into bytes in that charset in the later steps, 
whatever MSH-18 says.
-        - removeProperty:
-            name: CamelCharsetName
         - to:
             uri: kamelet:sink
diff --git 
a/tests/camel-kamelets-itest/src/test/resources/mllp/mllp-sink-route.yaml 
b/tests/camel-kamelets-itest/src/test/resources/mllp/mllp-sink-route.yaml
index ccd5624d1..7088b99b2 100644
--- a/tests/camel-kamelets-itest/src/test/resources/mllp/mllp-sink-route.yaml
+++ b/tests/camel-kamelets-itest/src/test/resources/mllp/mllp-sink-route.yaml
@@ -45,6 +45,21 @@
               port: "{{mllp.port}}"
               charset: "UTF-8"
         - log: "Ack MSG00002 ${header.CamelMllpAcknowledgementType}"
+        - removeHeader:
+            name: "CamelCharsetName"
+        # In UTF-8, as MSH-18 says, with no charset set on the sink 
(ISO-8859-1 then applies only without MSH-18),
+        # and a CamelCharsetName header that does not change it
+        - setBody:
+            constant: 
"MSH|^~\\&|SENDER|HOSPITAL|RECEIVER|LAB|20260101120000||ADT^A08|MSG00006|P|2.5||||||UNICODE
 UTF-8\rPID|1||12345||Sørensen^Łucja"
+        - setHeader:
+            name: "CamelCharsetName"
+            constant: "ISO-8859-1"
+        - to:
+            uri: "kamelet:mllp-sink"
+            parameters:
+              host: "localhost"
+              port: "{{mllp.port}}"
+        - log: "Ack MSG00006 ${header.CamelMllpAcknowledgementType}"
         - removeHeader:
             name: "CamelCharsetName"
         # As bytes
diff --git 
a/tests/camel-kamelets-itest/src/test/resources/mllp/mllp-sink-source.citrus.it.yaml
 
b/tests/camel-kamelets-itest/src/test/resources/mllp/mllp-sink-source.citrus.it.yaml
index 571d1ea37..08fb92851 100644
--- 
a/tests/camel-kamelets-itest/src/test/resources/mllp/mllp-sink-source.citrus.it.yaml
+++ 
b/tests/camel-kamelets-itest/src/test/resources/mllp/mllp-sink-source.citrus.it.yaml
@@ -16,7 +16,7 @@
 # ---------------------------------------------------------------------------
 
 name: mllp-sink-source-test
-description: 'mllp-sink sends HL7 v2 messages to mllp-source, which gives each 
one to its flow and acknowledges it: AA, AE when the flow fails, AR when the 
flow rejects it'
+description: 'mllp-sink sends HL7 v2 messages to mllp-source, which gives each 
one to its flow and acknowledges it: AA, AE when the flow fails, AR when the 
flow rejects it; text is sent and read in the charset of MSH-18'
 actions:
   # The source listens on all the network interfaces
   - camel:
@@ -60,6 +60,11 @@ actions:
         verify:
           integration: "mllp-source-route"
           logMessage: "Headers MSG00001 type=ADT^A01 event=ADT trigger=A01 
from=SENDER/HOSPITAL to=RECEIVER/LAB time=20260101120000 processing=P 
version=2.5 remote=/127.0.0.1:"
+  - camel:
+      cli:
+        verify:
+          integration: "mllp-source-route"
+          logMessage: "Charset MSG00001 msh18=|"
 
   # The sink leaves the body as it is, and gives the AA acknowledgement of the 
source
   - camel:
@@ -105,6 +110,29 @@ actions:
           integration: "mllp-sink-route"
           logMessage: "Ack MSG00002 AA"
 
+  # The sink sends UTF-8 text as MSH-18 says also when charset is not set, 
whatever the CamelCharsetName
+  # header says, and the source gives MSH-18 in CamelMllpCharset
+  - camel:
+      cli:
+        verify:
+          integration: "mllp-source-route"
+          logMessage: "Name MSG00006 true"
+  - camel:
+      cli:
+        verify:
+          integration: "mllp-source-route"
+          logMessage: "Bytes MSG00006 126"
+  - camel:
+      cli:
+        verify:
+          integration: "mllp-source-route"
+          logMessage: "Charset MSG00006 msh18=UNICODE UTF-8|"
+  - camel:
+      cli:
+        verify:
+          integration: "mllp-sink-route"
+          logMessage: "Ack MSG00006 AA"
+
   # A body of bytes is sent as it is
   - camel:
       cli:
diff --git 
a/tests/camel-kamelets-itest/src/test/resources/mllp/mllp-source-route.yaml 
b/tests/camel-kamelets-itest/src/test/resources/mllp/mllp-source-route.yaml
index 104157e35..d859aabdf 100644
--- a/tests/camel-kamelets-itest/src/test/resources/mllp/mllp-source-route.yaml
+++ b/tests/camel-kamelets-itest/src/test/resources/mllp/mllp-source-route.yaml
@@ -24,6 +24,7 @@
       steps:
         - log: "Received ${header.CamelMllpMessageControlId} 
${body.getClass().getName()}: ${body.replace('\r', ' / ')}|"
         - log: "Headers ${header.CamelMllpMessageControlId} 
type=${header.CamelMllpMessageType} event=${header.CamelMllpEventType} 
trigger=${header.CamelMllpTriggerEvent} 
from=${header.CamelMllpSendingApplication}/${header.CamelMllpSendingFacility} 
to=${header.CamelMllpReceivingApplication}/${header.CamelMllpReceivingFacility} 
time=${header.CamelMllpTimestamp} processing=${header.CamelMllpProcessingId} 
version=${header.CamelMllpVersionId} remote=${header.CamelMllpRemoteAddress}"
+        - log: "Charset ${header.CamelMllpMessageControlId} 
msh18=${header.CamelMllpCharset}|"
         # Read in the charset of MSH-18, and turned into bytes in UTF-8 
afterwards (Sørensen and Łucja are 2 bytes longer)
         - log: "Name ${header.CamelMllpMessageControlId} 
${body.contains('Sørensen^Łucja')}"
         - convertBodyTo:

Reply via email to