shashank created CAMEL-25317:
--------------------------------

             Summary: camel-iso8583 - unmarshal fails with "IsoType ... is not 
known" for every message type without an ISO header or with a binary ISO header
                 Key: CAMEL-25317
                 URL: https://issues.apache.org/jira/browse/CAMEL-25317
             Project: Camel
          Issue Type: Bug
            Reporter: shashank


{{Iso8583DataFormat.unmarshal}} takes the length of the ISO header to skip from 
the j8583 {{MessageFactory}}:

{code:java}
String type = messageFactory.getIsoHeader(i);
if (type != null) {
    len = type.length();
}
if (len == -1) {
    throw new IllegalArgumentException("IsoType " + iType + " is not known in 
the MessageFactory configuration file.");
}
return messageFactory.parseMessage(data, len);
{code}

In j8583 the ISO header of a message type is optional ({{<header type="...">}} 
in {{j8583-config.xml}}), and a binary header ({{<header binary="true">}}) is 
returned by {{getBinaryIsoHeader}} only. So every message of a type without a 
text header fails, even when its parse guide is configured: the test 
configuration of the module itself has parse guides for 0201, 0202, 0280..0283 
and 0600 without a text header, and 0600 is one of the types the documentation 
lists.

h3. Reproduction

New {{Iso8583DataFormatIsoHeaderTest}}: a 0201 message (no header) and a 0280 
message (binary header {{ffffffff}}) written by {{IsoMessage.writeData()}} 
cannot be unmarshalled ({{IllegalArgumentException: IsoType 0201 is not known 
in the MessageFactory configuration file.}}); a 0800 message with a text header 
is the control and passes. Three runs on main.

h3. Proposed fix

Skip the binary header ({{parseMessage(data, length, true)}}) when the type has 
one, the text header otherwise, and nothing when the type has no header. Types 
with a text header are parsed as before. Module: 7 tests pass.

Behaviour for a configured ISO type that does not match the data: before, a 
type without a text header always failed with the {{IllegalArgumentException}} 
above. With the fix the header length of that type (possibly 0) is skipped and 
j8583 parses the rest, so a mismatch now fails in j8583 with 
{{java.text.ParseException: ISO8583 MessageFactory has no parsing guide for 
message type ...}}, the error main already gives when a type with a text header 
is configured for data that does not match. That j8583 message contains the raw 
message data, as it already does on main in that case. An ISO type that is not 
in the configuration at all is no longer rejected when the data has no header 
(the type is read from the data, as for every other type). Checked with a probe 
(not part of the change): 0201 configured for 0800 data, 0999 for 0800 data and 
0280 for 0201 data all fail with that {{ParseException}}.

Found with a Lean 4 model of {{writeData}} / {{unmarshal}}: the round trip 
"unmarshal(writeData(header, message)) gives the header and the message back" 
fails on main for every message whose type has no text header 
({{main_fails_without_text_header}}) and is proved for the fix for the three 
header kinds ({{fix_roundtrip}}); the fix equals main wherever main returned a 
result.

Affected: 4.14.x, 4.18.x and main (unchanged since CAMEL-21974, 4.14.0).

Duplicate check (2026-10-04): JIRA "iso8583" / "j8583" (CAMEL-21974 and older 
component requests only); GitHub pull requests "iso8583": none on this.

_Filed with Claude Code on behalf of allthingssecurity._




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

Reply via email to