Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 50. Flatpack
Flatpack Component Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
The Flatpack component supports fixed width and delimited file parsing using the FlatPack library. Notice: This component only supports consuming from flatpack files to Object model. You can not (yet) write from Object model to flatpack format.
Maven users will need to add the following dependency to their
pom.xml for this component:
URI format Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
flatpack:[delim|fixed]:flatPackConfig.pzmap.xml[?options]
flatpack:[delim|fixed]:flatPackConfig.pzmap.xml[?options]
Or for a delimited file handler with no configuration file just use:
flatpack:someName[?options]
flatpack:someName[?options]
You can append query options to the URI in the following format,
?option=value&option=value&...
URI Options Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
| Name | Default Value | Description |
|---|---|---|
delimiter
|
,
|
The default character delimiter for delimited files. |
textQualifier
|
"
|
The text qualifier for delimited files. |
ignoreFirstRecord
|
true
|
Whether the first line is ignored for delimited files (for the column headers). |
splitRows
|
true
|
As of Apache Camel 1.5, the component can either process each row one by one or the entire content at once. |
allowShortLines
|
false
|
*Camel 2.9.3:* Allows for lines to be shorter than expected and ignores the extra characters. |
ignoreExtraColumns
|
false
|
*Camel 2.9.3:* Allows for lines to be longer than expected and ignores the extra characters. |
Examples Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
flatpack:fixed:foo.pzmap.xmlcreates a fixed-width endpoint using thefoo.pzmap.xmlfile configuration.flatpack:delim:bar.pzmap.xmlcreates a delimited endpoint using thebar.pzmap.xmlfile configuration.flatpack:foocreates a delimited endpoint calledfoowith no file configuration.
Message Headers Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
Apache Camel will store the following headers on the IN message:
| Header | Description |
|---|---|
camelFlatpackCounter
|
The current row index. For splitRows=false the counter is the total number of rows.
|
Message Body Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
The component delivers the data in the IN message as a
org.apache.camel.component.flatpack.DataSetList object that has converters for java.util.Map or java.util.List. Usually you want the Map if you process one row at a time (splitRows=true). Use List for the entire content (splitRows=false), where each element in the list is a Map. Each Map contains the key for the column name and its corresponding value.
For example to get the firstname from the sample below:
Map row = exchange.getIn().getBody(Map.class);
String firstName = row.get("FIRSTNAME");
Map row = exchange.getIn().getBody(Map.class);
String firstName = row.get("FIRSTNAME");
However, you can also always get it as a
List (even for splitRows=true). The same example:
List data = exchange.getIn().getBody(List.class);
Map row = (Map)data.get(0);
String firstName = row.get("FIRSTNAME");
List data = exchange.getIn().getBody(List.class);
Map row = (Map)data.get(0);
String firstName = row.get("FIRSTNAME");
Header and Trailer records Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
The header and trailer notions in Flatpack are supported. However, you must use fixed record IDs:
headerfor the header record (must be lowercase)trailerfor the trailer record (must be lowercase)
The example below illustrates this fact that we have a header and a trailer. You can omit one or both of them if not needed.
Using the endpoint Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
A common use case is sending a file to this endpoint for further processing in a separate route. For example:
You can also convert the payload of each message created to a
Map for easy Bean Integration