You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by madusanka <ma...@gmail.com> on 2013/12/09 09:15:22 UTC

Content Based Routing with Camel

Hi,

I know that JSONPath component will be available as of camel 2.13. Is there
a way to perform CBR for JSON payload in other versions of Apache Camel?



--
View this message in context: http://camel.465427.n5.nabble.com/Content-Based-Routing-with-Camel-tp5744495.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Content Based Routing with Camel

Posted by "kraythe ." <kr...@gmail.com>.
Easiest way is to deserialize with Jackson2 into a JSON Tree and then
navigate the tree to get the info. Means you dont need a pojo or mapping
but can still fetch the data without resortign to string parsing. I dont
know how mature JSONPathc is anyway. We will see if it holds any benefit
over going about it manually.

*Robert Simmons Jr. MSc. - Lead Java Architect @ EA*
*Author of: Hardcore Java (2003) and Maintainable Java (2012)*
*LinkedIn: **http://www.linkedin.com/pub/robert-simmons/40/852/a39
<http://www.linkedin.com/pub/robert-simmons/40/852/a39>*


On Mon, Dec 9, 2013 at 6:43 AM, madusanka <ma...@gmail.com>wrote:

> I have to detect what type they are first and then route to the appropriate
> service provider. I was wondering if JSONPath is supported in early
> versions
> of Camel ?
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Content-Based-Routing-with-Camel-tp5744495p5744508.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Content Based Routing with Camel

Posted by madusanka <ma...@gmail.com>.
I have to detect what type they are first and then route to the appropriate
service provider. I was wondering if JSONPath is supported in early versions
of Camel ?



--
View this message in context: http://camel.465427.n5.nabble.com/Content-Based-Routing-with-Camel-tp5744495p5744508.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Content Based Routing with Camel

Posted by James Carman <ja...@carmanconsulting.com>.
He would need to use a Predicate for CBR.  Either way, it'd be easy to
do, as you pointed out, since it's just a library. :)

Or, if the destination can be "calculated" based on something in your
JSON (using an expression), you could do something like this:

from(...).deserialize(...).recipientList(simple("some simple expression");

On Mon, Dec 9, 2013 at 7:43 PM, Christian Posta
<ch...@gmail.com> wrote:
> If you're set on JsonPath, you can do so in a POJO or processor as
> it's just a library:
>
> http://code.google.com/p/json-path/
>
> On Mon, Dec 9, 2013 at 1:57 PM, Henryk Konsek <he...@gmail.com> wrote:
>> Hi guys,
>>
>>> Perhaps you can deserialize the object(s) first before doing CBR
>>> (using a simple expression)?
>>
>> This is very good suggestion, James. To make it a little more concrete:
>>
>> from(...).
>>   unmarshal().json(JsonLibrary.Gson, Map.class).
>>     choice().
>>       when().simple("${body[invoices][latest][netValue] > 1000}").to(...).
>>       otherwise().to(...).
>>    endChoice();
>>
>> You can use JSON data format [1] (I use Google GSON in the example) to
>> deserialize incoming message. In the example below I deserialize it to
>> Map, because I don't know the type of the message (to make things
>> little more tricky). And yeah, GSON handles nested Maps pretty well.
>> To analyse content of the nested maps structure you might use Simple
>> [2] expression (as James suggested) because it supports nested map
>> keys notation (as in the example). And nested maps keys is something
>> similar to JsonPath you wanted to have :) .
>>
>> Cheers.
>>
>> [1] http://camel.apache.org/json
>> [2] http://camel.apache.org/simple
>>
>> --
>> Henryk Konsek
>> http://henryk-konsek.blogspot.com
>
>
>
> --
> Christian Posta
> http://www.christianposta.com/blog
> twitter: @christianposta

Re: Content Based Routing with Camel

Posted by Christian Posta <ch...@gmail.com>.
If you're set on JsonPath, you can do so in a POJO or processor as
it's just a library:

http://code.google.com/p/json-path/

On Mon, Dec 9, 2013 at 1:57 PM, Henryk Konsek <he...@gmail.com> wrote:
> Hi guys,
>
>> Perhaps you can deserialize the object(s) first before doing CBR
>> (using a simple expression)?
>
> This is very good suggestion, James. To make it a little more concrete:
>
> from(...).
>   unmarshal().json(JsonLibrary.Gson, Map.class).
>     choice().
>       when().simple("${body[invoices][latest][netValue] > 1000}").to(...).
>       otherwise().to(...).
>    endChoice();
>
> You can use JSON data format [1] (I use Google GSON in the example) to
> deserialize incoming message. In the example below I deserialize it to
> Map, because I don't know the type of the message (to make things
> little more tricky). And yeah, GSON handles nested Maps pretty well.
> To analyse content of the nested maps structure you might use Simple
> [2] expression (as James suggested) because it supports nested map
> keys notation (as in the example). And nested maps keys is something
> similar to JsonPath you wanted to have :) .
>
> Cheers.
>
> [1] http://camel.apache.org/json
> [2] http://camel.apache.org/simple
>
> --
> Henryk Konsek
> http://henryk-konsek.blogspot.com



-- 
Christian Posta
http://www.christianposta.com/blog
twitter: @christianposta

Re: Content Based Routing with Camel

Posted by Henryk Konsek <he...@gmail.com>.
Hi guys,

> Perhaps you can deserialize the object(s) first before doing CBR
> (using a simple expression)?

This is very good suggestion, James. To make it a little more concrete:

from(...).
  unmarshal().json(JsonLibrary.Gson, Map.class).
    choice().
      when().simple("${body[invoices][latest][netValue] > 1000}").to(...).
      otherwise().to(...).
   endChoice();

You can use JSON data format [1] (I use Google GSON in the example) to
deserialize incoming message. In the example below I deserialize it to
Map, because I don't know the type of the message (to make things
little more tricky). And yeah, GSON handles nested Maps pretty well.
To analyse content of the nested maps structure you might use Simple
[2] expression (as James suggested) because it supports nested map
keys notation (as in the example). And nested maps keys is something
similar to JsonPath you wanted to have :) .

Cheers.

[1] http://camel.apache.org/json
[2] http://camel.apache.org/simple

-- 
Henryk Konsek
http://henryk-konsek.blogspot.com

Re: Content Based Routing with Camel

Posted by James Carman <ja...@carmanconsulting.com>.
Perhaps you can deserialize the object(s) first before doing CBR
(using a simple expression)?  Or, do you have to detect what type they
are first and then route to the appropriate deserializer?

On Mon, Dec 9, 2013 at 3:15 AM, madusanka
<ma...@gmail.com> wrote:
> Hi,
>
> I know that JSONPath component will be available as of camel 2.13. Is there
> a way to perform CBR for JSON payload in other versions of Apache Camel?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Content-Based-Routing-with-Camel-tp5744495.html
> Sent from the Camel - Users mailing list archive at Nabble.com.