camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > JXPath
Date Fri, 07 Sep 2012 21:17: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/JXPath">JXPath</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~muellerc">Christian
Mueller</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        Removed the deprecated Camel 1.x documentations<br />
    </div>
        <br/>
                         <h4>Changes (3)</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" >Camel supports [JXPath|http://commons.apache.org/jxpath/]
to allow [XPath] expressions to be used on beans in an [Expression] or [Predicate] to be used
in the [DSL] or [Xml Configuration]. For example you could use JXPath to create an [Predicate]
in a [Message Filter] or as an [Expression] for a [Recipient List]. <br> <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">From
1.3 of Camel onwards you</span> <span class="diff-added-words"style="background-color:
#dfd;">You</span> can use XPath expressions directly using smart completion in your
IDE as follows <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{code} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
<br>       xsi:schemaLocation=&quot; <br></td></tr>
            <tr><td class="diff-changed-lines" >http://www.springframework.org/schema/beans
<span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">http://www.springframework.org/schema/beans/spring-beans-2.0.xsd</span>
<span class="diff-added-words"style="background-color: #dfd;">http://www.springframework.org/schema/beans/spring-beans.xsd</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >       http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd&quot;&gt; <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >  &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
<br>  &lt;artifactId&gt;camel-jxpath&lt;/artifactId&gt; <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">&lt;version&gt;1.4.0&lt;/version&gt;</span>
<span class="diff-added-words"style="background-color: #dfd;">&lt;version&gt;x.x.x&lt;/version&gt;</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >&lt;/dependency&gt; <br>{code}
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="JXPath-JXPath"></a>JXPath</h2>

<p>Camel supports <a href="http://commons.apache.org/jxpath/" class="external-link"
rel="nofollow">JXPath</a> to allow <a href="/confluence/display/CAMEL/XPath" title="XPath">XPath</a>
expressions to be used on beans in an <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a>
or <a href="/confluence/display/CAMEL/Predicate" title="Predicate">Predicate</a>
to be used in the <a href="/confluence/display/CAMEL/DSL" title="DSL">DSL</a>
or <a href="/confluence/display/CAMEL/Xml+Configuration" title="Xml Configuration">Xml
Configuration</a>. For example you could use JXPath to create an <a href="/confluence/display/CAMEL/Predicate"
title="Predicate">Predicate</a> in a <a href="/confluence/display/CAMEL/Message+Filter"
title="Message Filter">Message Filter</a> or as an <a href="/confluence/display/CAMEL/Expression"
title="Expression">Expression</a> for a <a href="/confluence/display/CAMEL/Recipient+List"
title="Recipient List">Recipient List</a>.</p>

<p>You can use XPath expressions directly using smart completion in your IDE as follows</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"queue:foo"</span>).filter().
  jxpath(<span class="code-quote">"/in/body/foo"</span>).
  to(<span class="code-quote">"queue:bar"</span>)
</pre>
</div></div>

<h3><a name="JXPath-Variables"></a>Variables</h3>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Variable </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <b>this</b> </td>
<td class='confluenceTd'> Exchange </td>
<td class='confluenceTd'> the Exchange object </td>
</tr>
<tr>
<td class='confluenceTd'> in </td>
<td class='confluenceTd'> Message </td>
<td class='confluenceTd'> the exchange.in message </td>
</tr>
<tr>
<td class='confluenceTd'> out </td>
<td class='confluenceTd'> Message </td>
<td class='confluenceTd'> the exchange.out message </td>
</tr>
</tbody></table>
</div>


<h3><a name="JXPath-UsingXMLconfiguration"></a>Using XML configuration</h3>

<p>If you prefer to configure your routes in your <a href="/confluence/display/CAMEL/Spring"
title="Spring">Spring</a> XML file then you can use JXPath expressions as follows</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
&lt;beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
       <span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"&gt;

  <span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span>
xmlns=<span class="code-quote">"http://activemq.apache.org/camel/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;route&gt;</span>
      <span class="code-tag">&lt;from uri=<span class="code-quote">"activemq:MyQueue"</span>/&gt;</span>
      <span class="code-tag">&lt;filter&gt;</span>
        <span class="code-tag">&lt;jxpath&gt;</span>in/body/name = 'James'<span
class="code-tag">&lt;/xpath&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"mqseries:SomeOtherQueue"</span>/&gt;</span>
      <span class="code-tag">&lt;/filter&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
  <span class="code-tag">&lt;/camelContext&gt;</span>
<span class="code-tag">&lt;/beans&gt;</span>
</pre>
</div></div>

<h3><a name="JXPath-Examples"></a>Examples</h3>

<p>Here is a simple <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/JXPathFilterTest.java"
class="external-link" rel="nofollow">example</a> using a JXPath expression as a predicate
in a <a href="/confluence/display/CAMEL/Message+Filter" title="Message Filter">Message
Filter</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>).
        filter().jxpath(<span class="code-quote">"in/body/name='James'"</span>).
        to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<h2><a name="JXPath-JXPathinjection"></a>JXPath injection </h2>

<p>You can use <a href="/confluence/display/CAMEL/Bean+Integration" title="Bean Integration">Bean
Integration</a> to invoke a method on a bean and use various languages such as JXPath
to extract a value from the message and bind it to a method parameter.</p>

<p>For example</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class Foo {
	
    @MessageDriven(uri = <span class="code-quote">"activemq:my.queue"</span>)
    <span class="code-keyword">public</span> void doSomething(@JXPath(<span
class="code-quote">"in/body/foo"</span>) <span class="code-object">String</span>
correlationID, @Body <span class="code-object">String</span> body) {
		<span class="code-comment">// process the inbound message here
</span>    }
}
</pre>
</div></div>

<h3><a name="JXPath-Dependencies"></a>Dependencies</h3>

<p>To use JXpath in your camel routes you need to add the a dependency on <b>camel-jxpath</b>
which implements the JXpath language. </p>

<p>If you use maven you could just add the following to your pom.xml, substituting the
version number for the latest &amp; greatest release (see <a href="/confluence/display/CAMEL/Download"
title="Download">the download page for the latest versions</a>).</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;dependency&gt;
  &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
  &lt;artifactId&gt;camel-jxpath&lt;/artifactId&gt;
  &lt;version&gt;x.x.x&lt;/version&gt;
&lt;/dependency&gt;
</pre>
</div></div>

<p>Otherwise, you'll also need <a href="http://repo2.maven.org/maven2/commons-jxpath/commons-jxpath/1.3/commons-jxpath-1.3.jar"
class="external-link" rel="nofollow">Commons JXPath</a>.</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/JXPath">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=80308&revisedVersion=11&originalVersion=10">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/JXPath?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message