camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Content Filter
Date Fri, 02 Apr 2010 17:23:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CAMEL/Content+Filter">Content
Filter</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~premiergeneration@yahoo.com">Yogesh
Chawla</a>
    </h4>
     added example route that uses XPath expression as a content filter
          <div id="versionComment" class="noteMacro" style="display:none; padding: 5px;">
     added example route that uses XPath expression as a content filter<br />
     </div>
          <br/>
     <div class="notificationGreySide">
         <h3><a name="ContentFilter-ContentFilter"></a>Content Filter</h3>

<p>Camel supports the <a href="http://www.enterpriseintegrationpatterns.com/ContentFilter.html"
rel="nofollow">Content Filter</a> from the <a href="/confluence/display/CAMEL/Enterprise+Integration+Patterns"
title="Enterprise Integration Patterns">EIP patterns</a> using one of the following
mechanisms in the routing logic to transform content from the inbound message.</p>

<ul>
	<li><a href="/confluence/display/CAMEL/Message+Translator" title="Message Translator">Message
Translator</a></li>
	<li>invoking a <a href="/confluence/display/CAMEL/Bean+Integration" title="Bean
Integration">Java bean</a></li>
	<li><a href="/confluence/display/CAMEL/Processor" title="Processor">Processor</a>
object</li>
</ul>


<p><img src="http://www.enterpriseintegrationpatterns.com/img/ContentFilter.gif"
align="absmiddle" border="0" /></p>

<p>A common way to filter messages is to use an <a href="/confluence/display/CAMEL/Expression"
title="Expression">Expression</a> in the <a href="/confluence/display/CAMEL/DSL"
title="DSL">DSL</a> like <a href="/confluence/display/CAMEL/XQuery" title="XQuery">XQuery</a>,
<a href="/confluence/display/CAMEL/SQL" title="SQL">SQL</a> or one of the supported
<a href="/confluence/display/CAMEL/Scripting+Languages" title="Scripting Languages">Scripting
Languages</a>.</p>

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

<p>Here is a simple example using the <a href="/confluence/display/CAMEL/DSL" title="DSL">DSL</a>
directly</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>).setBody(body().append(<span
class="code-quote">" World!"</span>)).to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>In this example we add our own <a href="/confluence/display/CAMEL/Processor" title="Processor">Processor</a></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>).process(<span
class="code-keyword">new</span> Processor() {
    <span class="code-keyword">public</span> void process(Exchange exchange) {
        Message in = exchange.getIn();
        in.setBody(in.getBody(<span class="code-object">String</span>.class) +
<span class="code-quote">" World!"</span>);
    }
}).to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>For further examples of this pattern in use you could look at one of the JUnit tests</p>

<ul>
	<li><a href="http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TransformTest.java?view=markup"
rel="nofollow">TransformTest</a></li>
	<li><a href="http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TransformViaDSLTest.java?view=markup"
rel="nofollow">TransformViaDSLTest</a></li>
</ul>


<p><b>Using Spring XML</b></p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;route&gt;
  &lt;from uri=<span class="code-quote">"activemq:Input"</span>/&gt;
  &lt;bean ref=<span class="code-quote">"myBeanName"</span> method=<span
class="code-quote">"doTransform"</span>/&gt;
  &lt;to uri=<span class="code-quote">"activemq:Output"</span>/&gt;
&lt;/route&gt;
</pre>
</div></div>

<p>You can also use XPath to filter out part of the message you are interested in:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;route&gt;
  &lt;from uri=<span class="code-quote">"activemq:Input"</span>/&gt;
  &lt;setBody&gt;&lt;xpath resultType=<span class="code-quote">"org.w3c.dom.Document"</span>&gt;<span
class="code-comment">//foo:bar&lt;/xpath&gt;&lt;/setBody&gt;
</span>  &lt;to uri=<span class="code-quote">"activemq:Output"</span>/&gt;
&lt;/route&gt; 
</pre>
</div></div>
<h4><a name="ContentFilter-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>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/CAMEL/Content+Filter">View
Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=52526&revisedVersion=10&originalVersion=9">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CAMEL/Content+Filter?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message