Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.
Flatpack ComponentThe Flatpack component supports fixed width and delimited file parsing via the FlatPack library. Maven users will need to add the following dependency to their <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-flatpack</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency> URI formatflatpack:[delim|fixed]:flatPackConfig.pzmap.xml[?options] Or for a delimited file handler with no configuration file just use flatpack:someName[?options] You can append query options to the URI in the following format, URI Options
Examples
Message HeadersCamel will store the following headers on the IN message:
Message BodyThe component delivers the data in the IN message as a For example to get the firstname from the sample below: Map row = exchange.getIn().getBody(Map.class); String firstName = row.get("FIRSTNAME"); However, you can also always get it as a List data = exchange.getIn().getBody(List.class); Map row = (Map)data.get(0); String firstName = row.get("FIRSTNAME"); Header and Trailer recordsThe header and trailer notions in Flatpack are supported. However, you must use fixed record IDs:
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. <RECORD id="header" startPosition="1" endPosition="3" indicator="HBT"> <COLUMN name="INDICATOR" length="3"/> <COLUMN name="DATE" length="8"/> </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" startPosition="1" endPosition="3" indicator="FBT"> <COLUMN name="INDICATOR" length="3"/> <COLUMN name="STATUS" length="7"/> </RECORD> Using the endpointA common use case is sending a file to this endpoint for further processing in a separate route. For example: <camelContext xmlns="http://activemq.apache.org/camel/schema/spring"> <route> <from uri="file://someDirectory"/> <to uri="flatpack:foo"/> </route> <route> <from uri="flatpack:foo"/> ... </route> </camelContext> You can also convert the payload of each message created to a Flatpack DataFormatThe Flatpack component ships with the Flatpack data format that can be used to format between fixed width or delimited text messages to a
Notice: The Flatpack library does currently not support header and trailers for the marshal operation. OptionsThe data format has the following options:
UsageTo use the data format, simply instantiate an instance and invoke the marshal or unmarshal operation in the route builder: FlatpackDataFormat fp = new FlatpackDataFormat(); fp.setDefinition(new ClassPathResource("INVENTORY-Delimited.pzmap.xml")); ... from("file:order/in").unmarshal(df).to("seda:queue:neworder"); The sample above will read files from the FlatpackDataFormat df = new FlatpackDataFormat(); df.setDefinition(new ClassPathResource("PEOPLE-FixedLength.pzmap.xml")); df.setFixed(true); df.setIgnoreFirstRecord(false); from("seda:people").marshal(df).convertBodyTo(String.class).to("jms:queue:people"); In the code above we marshal the data from a Object representation as a DependenciesTo use Flatpack in your camel routes you need to add the a dependency on camel-flatpack which implements this data format. If you use maven you could just add the following to your pom.xml, substituting the version number for the latest & greatest release (see the download page for the latest versions). <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-flatpack</artifactId> <version>x.x.x</version> </dependency> |