camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Camel > Claim Check
Date Fri, 07 Sep 2012 20:36:00 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
<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="">Claim
    <h4>Page <b>edited</b> by             <a href="">Christian
        <div id="versionComment">
        Removed the deprecated Camel 1.x documentations<br />
                         <h4>Changes (1)</h4>
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >!!
<br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">Available
in Camel 1.5. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h4. Example <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h3><a name="ClaimCheck-ClaimCheck"></a>Claim Check</h3>

<p>The <a href=""
class="external-link" rel="nofollow">Claim Check</a> from the <a href="/confluence/display/CAMEL/Enterprise+Integration+Patterns"
title="Enterprise Integration Patterns">EIP patterns</a> allows you to replace message
content with a claim check (a unique key), which can be used to retrieve the message content
at a later time. The message content is stored temporarily in a persistent store like a database
or file system. This pattern is very useful when message content is very large (thus it would
be expensive to send around) and not all components require all information. </p>

<p>It can also be useful in situations where you cannot trust the information with an
outside party; in this case, you can use the Claim Check to hide the sensitive portions of
data. </p>

<p><span class="image-wrap" style=""><img src=""
style="border: 0px solid black" /></span></p>

<h4><a name="ClaimCheck-Example"></a>Example</h4>

<p>In this example we want to replace a message body with a claim check, and restore
the body at a later step.</p>

<p><b>Using the <a href="/confluence/display/CAMEL/Fluent+Builders" title="Fluent
Builders">Fluent Builders</a></b></p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:start"</span>).to(<span
class="code-quote">"bean:checkLuggage"</span>, <span class="code-quote">"mock:testCheckpoint"</span>,
<span class="code-quote">"bean:dataEnricher"</span>, <span class="code-quote">"mock:result"</span>);

<p><b>Using the <a href="/confluence/display/CAMEL/Spring+XML+Extensions" title="Spring
XML Extensions">Spring XML Extensions</a></b></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">"direct:start"</span>/&gt;</span>
    <span class="code-tag">&lt;pipeline&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:checkLuggage"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:testCheckpoint"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:dataEnricher"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;</span>
    <span class="code-tag">&lt;/pipeline&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>


<p>The example route is pretty simple - its just a <a href="/confluence/display/CAMEL/Pipes+and+Filters"
title="Pipes and Filters">Pipeline</a>. In a real application you would have some
other steps where the <tt>mock:testCheckpoint</tt> endpoint is in the example.</p>

<p>The message is first sent to the <tt>checkLuggage</tt> bean which looks

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> <span
class="code-keyword">static</span> <span class="code-keyword">final</span>
class CheckLuggageBean {        
    <span class="code-keyword">public</span> void checkLuggage(Exchange exchange,
@Body <span class="code-object">String</span> body, @XPath(<span class="code-quote">"/order/@custId"</span>)
<span class="code-object">String</span> custId) {   
        <span class="code-comment">// store the message body into the data store, using
the custId as the claim check
</span>        dataStore.put(custId, body);
        <span class="code-comment">// add the claim check as a header
</span>        exchange.getIn().setHeader(<span class="code-quote">"claimCheck"</span>,
        <span class="code-comment">// remove the body from the message
</span>        exchange.getIn().setBody(<span class="code-keyword">null</span>);

<p>This bean stores the message body into the data store, using the <tt>custId</tt>
as the claim check. In this example, we're just using a <tt>HashMap</tt> to store
the message body; in a real application you would use a database or file system, etc. Next
the claim check is added as a message header for use later. Finally we remove the body from
the message and pass it down the pipeline. </p>

<p>The next step in the pipeline is the <tt>mock:testCheckpoint</tt> endpoint
which is just used to check that the message body is removed, claim check added, etc.</p>

<p>To add the message body back into the message, we use the <tt>dataEnricher</tt>
bean which looks like</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> <span
class="code-keyword">static</span> <span class="code-keyword">final</span>
class DataEnricherBean {
    <span class="code-keyword">public</span> void addDataBackIn(Exchange exchange,
@Header(<span class="code-quote">"claimCheck"</span>) <span class="code-object">String</span>
claimCheck) { 
        <span class="code-comment">// query the data store using the claim check as
the key and add the data
</span>        <span class="code-comment">// back into the message body
</span>        exchange.getIn().setBody(dataStore.get(claimCheck));
        <span class="code-comment">// remove the message data from the data store
</span>        dataStore.remove(claimCheck);
        <span class="code-comment">// remove the claim check header
</span>        exchange.getIn().removeHeader(<span class="code-quote">"claimCheck"</span>);

<p>This bean queries the data store using the claim check as the key and then adds the
data back into the message. The message body is then removed from the data store and finally
the claim check is removed. Now the message is back to what we started with!</p>

<p>For full details, check the example source here:</p>

<p><a href=""
class="external-link" rel="nofollow">camel-core/src/test/java/org/apache/camel/processor/</a></p>

<h4><a name="ClaimCheck-UsingThisPattern"></a>Using This Pattern</h4>

<p>If you would like to use this EIP Pattern then please read the <a href="/confluence/display/CAMEL/Getting+Started"
title="Getting Started">Getting Started</a>, you may also find the <a href="/confluence/display/CAMEL/Architecture"
title="Architecture">Architecture</a> useful particularly the description of <a
href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a> and <a
href="/confluence/display/CAMEL/URIs" title="URIs">URIs</a>. Then you could try out
some of the <a href="/confluence/display/CAMEL/Examples" title="Examples">Examples</a>
first before trying this pattern out.</p>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href=""
class="grey">Change Notification Preferences</a>
        <a href="">View
        <a href="">View
        <a href=";showCommentArea=true#addcomment">Add

View raw message