[
https://issues.apache.org/jira/browse/CAMEL-22458?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claus Ibsen resolved CAMEL-22458.
---------------------------------
Fix Version/s: 4.10.8
Assignee: Claus Ibsen
Resolution: Fixed
Thanks for reporting and the suggested fix
> flatpack converter accesses invalid column names for header and trailer
> record value retrieval of fixed width files
> -------------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-22458
> URL: https://issues.apache.org/jira/browse/CAMEL-22458
> Project: Camel
> Issue Type: Bug
> Affects Versions: 4.14.0
> Environment: * probably all
> * discovered on camel 4 quarkus (after migrating from camel 2 fuse)
> ** quarkus-camel-bom, quarkus-bom version: 3.16.2
> Reporter: Gandrinor
> Assignee: Claus Ibsen
> Priority: Minor
> Labels: flatpack
> Fix For: 4.10.8, 4.14.2, 4.16.0
>
>
> *Errror Szenario*
> When org.apache.camel.component.flatpack.FlatpackConverter toMap function is
> called, for example while using the
> org.apache.camel.component.flatpack.DataSetList iterator, the
> putValues(Map<String, Object> map, Record recordObj) is called.
> In this method the recordObj.getColumns() is called to retrieve the available
> columns of the record. The columns are iterated over to retrieve the
> respective values.
> When a fixed with file with the following example.pzmap.xml scheme was
> parsed,
>
> {code:java}
> <?xml version='1.0'?>
> <!-- DTD can be pulled from the Jar or over the web-->
> <!DOCTYPE PZMAP SYSTEM "flatpack.dtd" >
> <!--<!DOCTYPE PZMAP SYSTEM "http://flatpack.sourceforge.net/flatpack.dtd"
> >-->
> <PZMAP>
> <RECORD id="header" indicator="0" elementNumber="1">
> <COLUMN name="RECORDINDICATOR" length="5" />
> <COLUMN name="HEADERDATA" length="20" />
> </RECORD>
> <COLUMN name="FIRSTNAME" length="35" />
> <COLUMN name="LASTNAME" length="35" />
> <COLUMN name="ADDRESS" length="100" />
> <COLUMN name="CITY" length="100" />
> <COLUMN name="STATE" length="2" />
> <COLUMN name="ZIP" length="5" />
> <RECORD id="trailer" indicator="9" elementNumber="1">
> <COLUMN name="RECORDINDICATOR" length="5" />
> <COLUMN name="TRAILERDATA" length="15" />
> </RECORD>
>
> </PZMAP> {code}
> this leads to the following error being thrown:
>
> {code:java}
> java.util.NoSuchElementException: Column [FIRSTNAME] does not exist, check
> case/spelling. key:[header] at
> net.sf.flatpack.util.ParserUtils.getColumnIndex(ParserUtils.java:618) at
> net.sf.flatpack.RowRecord.getStringValue(RowRecord.java:269) at
> net.sf.flatpack.RowRecord.getString(RowRecord.java:315) at
> org.apache.camel.component.flatpack.FlatpackConverter.putValues(FlatpackConverter.java:117)
> at
> org.apache.camel.component.flatpack.FlatpackConverter.toMap(FlatpackConverter.java:48)
> at
> org.apache.camel.component.flatpack.DataSetList$1.next(DataSetList.java:90)
> at
> org.apache.camel.component.flatpack.DataSetList$1.next(DataSetList.java:68)
> {code}
>
>
> *Error explanation*
> The first record is the header record, which differs from the rows below. But
> the recordObj.getColumns() method retrieves not the header records columns
> (RECORDINDICATOR, HEADERDATA), but the other rows columns (FIRSTNAME,
> LASTNAME, ADDRESS, CITY, STATE, ZIP), which do not match the record
> structure. This leads to error.
>
> *Solution Suggestion*
> * use the local getColumns(DataSet dataSet) method instead of
> recordObj.getColumns() to retrieve the correct colums
> * change the getColumns(DataSet dataSet) methods signature to
> getColumns(Record dataSet)
>
> {code:java}
> private static void putValues(Map<String, Object> map, net.sf.flatpack.Record
> recordObj) {
> String[] columns = getColumns(recordObj); // !!!modified!!!
> for (String column : columns) {
> String value = recordObj.getString(column);
> map.put(column, value);
> }
> }
> private static String[] getColumns(Record dataSet) { // !!!modified!!!
> // the columns can vary depending on header, body or trailer
> if (dataSet.isRecordID(FlatpackComponent.HEADER_ID)) {
> return dataSet.getColumns(FlatpackComponent.HEADER_ID);
> } else if (dataSet.isRecordID(FlatpackComponent.TRAILER_ID)) {
> return dataSet.getColumns(FlatpackComponent.TRAILER_ID);
> } else {
> return dataSet.getColumns();
> }
> } {code}
>
>
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)