Torsten Mielke created CAMEL-25337:
--------------------------------------

             Summary: Wrong comparison in sendAcknowledgement of camel-mllp — 
SEGMENT_DELIMITER compared against loop index instead of byte value
                 Key: CAMEL-25337
                 URL: https://issues.apache.org/jira/browse/CAMEL-25337
             Project: Camel
          Issue Type: Bug
          Components: camel-mllp
    Affects Versions: 4.22.1
            Reporter: Torsten Mielke
            Assignee: Torsten Mielke


In {{{}MllpTcpServerConsumer.sendAcknowledgement(){}}}, the loop that scans the 
original HL7 message for the MSA segment delimiter compares 
{{SEGMENT_DELIMITER}} against the loop index {{i}} instead of the byte value at 
that position.
{code:java}
  // MllpTcpServerConsumer.java, line 579-580
  for (int i = 0; i < originalHl7MessageBytes.length; ++i) {
      if (MllpProtocolConstants.SEGMENT_DELIMITER == i) {   // BUG: compares 
against loop index
  {code}
{{SEGMENT_DELIMITER}} is {{0x0D}} (decimal 13), so this condition is only true 
when {{i == 13}} — a fixed position — rather than scanning every byte for a 
segment delimiter. The
correct comparison should be:
{code:java}
  if (MllpProtocolConstants.SEGMENT_DELIMITER == originalHl7MessageBytes[i]) {
  {code}
The producer-side equivalent in {{MllpTcpClientProducer.java}} (line 369) has 
the correct form:
{code:java}
  if (MllpProtocolConstants.SEGMENT_DELIMITER == hl7AcknowledgementBytes[i]) {
  {code}
Impact: The loop is trying to locate the MSA segment after the MSH segment 
delimiter in order to extract the acknowledgement type. Since it only checks 
position 13, it fails to find
the MSA segment in any message where the first {{\r}} is not at exactly byte 
13. For typical HL7 messages (MSH segments are usually 50+ bytes), the 
acknowledgement type is never
extracted from the original message.

This code path is only reached when the exchange already has an 
{{MLLP_ACKNOWLEDGEMENT}} property set (manual acknowledgement scenario), so 
auto-acknowledgement is not affected.

Found during: Investigation of CAMEL-25137.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to