camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (Confluence)" <conflue...@apache.org>
Subject [CONF] Apache Camel > JSonPath
Date Sun, 06 Oct 2013 10:23:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/en/2176/1/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/JSonPath">JSonPath</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="JSonPath-JSonPath"></a>JSonPath</h2>
<p><b>Available as of Camel 2.13</b></p>

<p>Camel supports <a href="https://code.google.com/p/json-path/" class="external-link"
rel="nofollow">JSonPath</a> to allow using <a href="/confluence/display/CAMEL/Expression"
title="Expression">Expression</a> or <a href="/confluence/display/CAMEL/Predicate"
title="Predicate">Predicate</a> on json messages.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("queue:books.new")
  .choice()
    .when().jsonPath("$.store.book[?(@.price &lt; 10)]")
      .to("jms:queue:book.cheap")
    .when().jsonPath("$.store.book[?(@.price &lt; 30)]")
      .to("jms:queue:book.average")
    .otherwise()
      .to("jms:queue:book.expensive")
</pre>
</div></div>

<h3><a name="JSonPath-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 <a href="/confluence/display/CAMEL/JSonPath"
title="JSonPath">JSonPath</a> expressions as follows</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
  &lt;camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"&gt;
    &lt;route&gt;
      &lt;from uri="direct:start"/&gt;
      &lt;choice&gt;
        &lt;when&gt;
          &lt;jsonpath&gt;$.store.book[?(@.price &amp;lt; 10)]&lt;/jsonpath&gt;
          &lt;to uri="mock:cheap"/&gt;
        &lt;/when&gt;
        &lt;when&gt;
          &lt;jsonpath&gt;$.store.book[?(@.price &amp;lt; 30)]&lt;/jsonpath&gt;
          &lt;to uri="mock:average"/&gt;
        &lt;/when&gt;
        &lt;otherwise&gt;
          &lt;to uri="mock:expensive"/&gt;
        &lt;/otherwise&gt;
      &lt;/choice&gt;
    &lt;/route&gt;
  &lt;/camelContext&gt;
</pre>
</div></div>

<h3><a name="JSonPath-Syntax"></a>Syntax</h3>

<p>See the <a href="https://code.google.com/p/json-path/" class="external-link" rel="nofollow">JSonPath</a>
project page for further examples.</p>


<h2><a name="JSonPath-JSonPathinjection"></a>JSonPath 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 JSonPath
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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
public class Foo {
	
    @Consume(uri = "activemq:queue:books.new")
    public void doSomething(@JSonPath("$.store.book[*].author") String author, @Body String
json) {
      // process the inbound message here
    }
}
</pre>
</div></div>

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

<p>To use JSonPath in your camel routes you need to add the a dependency on <b>camel-jsonpath</b>
which implements the JSonPath 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="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;dependency&gt;
  &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
  &lt;artifactId&gt;camel-jsonpath&lt;/artifactId&gt;
  &lt;version&gt;x.x.x&lt;/version&gt;
&lt;/dependency&gt;
</pre>
</div></div>
    </div>
    <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;" class="grey">
                        <a href="https://cwiki.apache.org/confluence/users/removespacenotification.action?spaceKey=CAMEL">Stop
watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://cwiki.apache.org/confluence/users/editmyemailsettings.action">Change
email notification preferences</a>
</div>
       <a href="https://cwiki.apache.org/confluence/display/CAMEL/JSonPath">View Online</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message