tmielke opened a new pull request, #27371:
URL: https://github.com/apache/camel/pull/27371

   # Description
   
   `MllpTcpServerConsumer.sendAcknowledgement()` fails to extract the 
acknowledgement type (AA/AE/AR) from the MSA segment when the segment delimiter 
(`\r`) is not at byte offset 13 in the original HL7 message.
   
     The bug is in the segment delimiter scan loop at line 580:
   
     ```java
     // Bug: compares constant against loop index
     if (MllpProtocolConstants.SEGMENT_DELIMITER == i)
   
     // Fix: compares constant against byte value at that index
     if (MllpProtocolConstants.SEGMENT_DELIMITER == originalHl7MessageBytes[i])
   ```
   
     `SEGMENT_DELIMITER` is `0x0D` (decimal 13), so the condition only matched 
when the loop index i equalled 13 — not when the byte at position i was 
actually a carriage return.
     As a result, the `MLLP_ACKNOWLEDGEMENT_TYPE` exchange header was almost 
never set when using a custom acknowledgement via the 
`CamelMllpAcknowledgement` exchange property.
   
     The correct pattern already exists in MllpTcpClientProducer at line 369:
    `if (MllpProtocolConstants.SEGMENT_DELIMITER == hl7AcknowledgementBytes[i])`
   
     Test plan
     - [x] New unit test `MllpTcpServerConsumerSendAcknowledgementTest` with 
two test methods:
       - `testAcknowledgementTypeExtractedFromMsaSegment` — MSA segment after a 
long MSH (delimiter well past position 13)
       - `testAcknowledgementTypeExtractedWhenDelimiterAtPosition13` — edge 
case where \r happens to be at offset 13 (where the bug accidentally worked)
     - [x] All 349 existing MLLP tests pass, no regressions
   
     Discovered during analysis of CAMEL-25137.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   
   - [x] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to