DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Java 21 Is a Major Step for Java: Non-Blocking IO and Upgraded ZGC
  • Microservices With Apache Camel and Quarkus
  • Aggregating REST APIs Calls Using Apache Camel
  • Spring Boot Microservices + Apache Camel: A Hello World Example

Trending

  • Software Delivery at Scale: Centralized Jenkins Pipeline for Optimal Efficiency
  • Creating a Web Project: Caching for Performance Optimization
  • Understanding the Shift: Why Companies Are Migrating From MongoDB to Aerospike Database?
  • Advancing Your Software Engineering Career in 2025
  1. DZone
  2. Coding
  3. Frameworks
  4. Remove a BOM Character From an Apache Camel Exchange Message (DSL Java)

Remove a BOM Character From an Apache Camel Exchange Message (DSL Java)

By 
Dr. Julia Förster user avatar
Dr. Julia Förster
·
Updated Mar. 04, 20 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
16.2K Views

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. 

Java
 




x


 
1
 public void detectBomCharacter(Exchange exchange) { 
2
   String newBody = ((String)exchange.getIn().getBody()).replaceAll("\\uFEFF", "");
3
   exchange.getMessage().setBody((newBody)); 
4
 } 


 
The test using JUnit Jupiter could look as follows:

Java
 




xxxxxxxxxx
1
24


 
1
import org.apache.camel.Exchange;
2
import org.apache.camel.support.DefaultExchange;
3
import org.apache.camel.impl.DefaultCamelContext;
4
import org.junit.jupiter.api.Test;
5
import static org.junit.jupiter.api.Assertions.assertEquals;
6

          
7
class BomProcessor{
8
    Exchange exchange;
9
    BomProcessor bomProcessor;
10

          
11
    public void setUp(){
12
        exchange = new DefaultExchange(new DefaultCamelContext());
13
        bomProcessor = new BomProcessor ();
14
    }
15

          
16
    @Test
17
    public void shouldRemoveBomCharacter() {
18
        exchange.getIn().setBody("\uFEFFTest\uFEFF to remove\uFEFF BOM.\uFEFF");
19
        bomProcessor.removeBomCharacter(exchange);
20
        assertEquals("Test to remove BOM.", exchange.getMessage().getBody());
21
    }
22
}
23

          
24
 




Further Reading

  • Open Source Integration With Apache Camel and How Fuse IDE Can Help.
  • Microservices With Apache Camel.
BOM (file format) Apache Camel Java (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Java 21 Is a Major Step for Java: Non-Blocking IO and Upgraded ZGC
  • Microservices With Apache Camel and Quarkus
  • Aggregating REST APIs Calls Using Apache Camel
  • Spring Boot Microservices + Apache Camel: A Hello World Example

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!