Remove a BOM Character From an Apache Camel Exchange Message (DSL Java)
Join the DZone community and get the full member experience.Join For Free
A BOM character (Byte Order Mark) is an invisible character located at the start of a text file. A machine can identify the BOM character by its hexadecimal byte sequence, but to the user, the BOM character is invisible.
Apache Camel has a validation component that ignores BOM characters if they appear at the beginning of a file, but the component does not ignore BOM characters if they appear elsewhere. This can cause failures in an application. For example, when we use a splitter and aggregator, the exchange message can be ordered differently after aggregation is completed (i.e. the BOM character is not located at the start of a file, but somewhere else).
You may also like: How to Transform Any Type of Java Bean With BULL.
To avoid failures based on BOM characters, we create a Java Bean that scans the exchange message for the BOM character by its hexadecimal code and replaces it with an empty string.
The test using JUnit Jupiter could look as follows:
Opinions expressed by DZone contributors are their own.