camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > How to avoid sending some or all message headers
Date Mon, 31 Dec 2012 12:10:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/How+to+avoid+sending+some+or+all+message+headers">How
to avoid sending some or all message headers</a></h2>
    <h4>Page  <b>added</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
         <br/>
    <div class="notificationGreySide">
         <h2><a name="Howtoavoidsendingsomeorallmessageheaders-Howtoavoidsendingsomeorallmessageheaders%3F"></a>How
to avoid sending some or all message headers?</h2>

<p>When I send a message to a Camel endpoint such as the <a href="/confluence/display/CAMEL/Mail"
title="Mail">Mail</a> component, then the mail include some message headers I do
not want.<br/>
How can I avoid this?</p>

<h4><a name="Howtoavoidsendingsomeorallmessageheaders-UseremoveHeadersintheroute"></a>Use
removeHeaders in the route</h4>
<p>This is a gotcha more people encounter. However it's very easy to solve. To remove
all headers use a wildcard expression:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(...).removeHeaders(<span class="code-quote">"*"</span>).to(<span class="code-quote">"smtp:<span
class="code-comment">//...."</span>)</span>
</pre>
</div></div>

<p>Similarly to remove all headers except some of your own (myheader1 and myheader2)
use a wildcard with a vararg:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(...).removeHeaders(<span class="code-quote">"*"</span>, <span class="code-quote">"myheader1"</span>,
<span class="code-quote">"myheader).to("</span>smtp:<span class="code-comment">//....")</span>
</pre>
</div></div>

<p>To do this in XML DSL you simply do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;route&gt;</span>
  <span class="code-tag">&lt;from uri=<span class="code-quote">"..."</span>/&gt;</span>
  <span class="code-tag">&lt;removeHeaders pattern=<span class="code-quote">"*"</span>
excludePattern=<span class="code-quote">"myHeader1,myHeader2"</span>/&gt;</span>
  <span class="code-tag">&lt;to uri=<span class="code-quote">"smtp://..."</span>/&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>


<p>Again to remove only Camel headers but no other transport headers:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(...).removeHeaders(<span class="code-quote">"Camel*"</span>).to(<span
class="code-quote">"smtp:<span class="code-comment">//...."</span>)</span>
</pre>
</div></div>

<p>To do this in XML DSL you simply do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;route&gt;</span>
  <span class="code-tag">&lt;from uri=<span class="code-quote">"..."</span>/&gt;</span>
  <span class="code-tag">&lt;removeHeaders pattern=<span class="code-quote">"Camel*"</span>/&gt;</span>
  <span class="code-tag">&lt;to uri=<span class="code-quote">"smtp://..."</span>/&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>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.</td></tr></table></div>

<h4><a name="Howtoavoidsendingsomeorallmessageheaders-UseHeaderFilterStrategy"></a>Use
HeaderFilterStrategy</h4>

<p>An alternative is that some of the Camel <a href="/confluence/display/CAMEL/Components"
title="Components">Components</a> supports configuring a custom header filter strategy.<br/>
This allows you to implement the <tt>org.apache.camel.spi.HeaderFilterStrategy</tt>
interface, where you can filter unwanted headers.<br/>
Though its often easier to use the removeHeaders in the Camel route as shown above.</p>


    </div>
    <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>
       <a href="https://cwiki.apache.org/confluence/display/CAMEL/How+to+avoid+sending+some+or+all+message+headers">View
Online</a>
              |
       <a href="https://cwiki.apache.org/confluence/display/CAMEL/How+to+avoid+sending+some+or+all+message+headers?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message