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
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.

How to avoid sending some or all message headers?

When I send a message to a Camel endpoint such as the Mail component, then the mail include some message headers I do not want.
How can I avoid this?

Use removeHeaders in the route

This is a gotcha more people encounter. However it's very easy to solve. To remove all headers use a wildcard expression:


Similarly to remove all headers except some of your own (myheader1 and myheader2) use a wildcard with a vararg:

from(...).removeHeaders("*", "myheader1", "myheader2").to("smtp://....")

To do (a similar thing) in XML DSL you simply do:

  <from uri="..."/>
  <removeHeaders pattern="*" excludePattern="header1|header2"/>
  <to uri="smtp://..."/>

At present, the excludePattern only supports one header name (which can be include wild cards or regular expressions). We tackle this limitation with CAMEL-6445.

Again to remove only Camel headers but no other transport headers:


To do this in XML DSL you simply do:

  <from uri="..."/>
  <removeHeaders pattern="Camel*"/>
  <to uri="smtp://..."/>

There is also a removeHeader in the DSL to remove a single header. But it does not support patterns, so you can only remove a single header by its name.

Use HeaderFilterStrategy

An alternative is that some of the Camel Components supports configuring a custom header filter strategy.
This allows you to implement the org.apache.camel.spi.HeaderFilterStrategy interface, where you can filter unwanted headers.
Though its often easier to use the removeHeaders in the Camel route as shown above.

© 2004-2015 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram