How to enrich message with the result of other invocation

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

How to enrich message with the result of other invocation

RomKal
Hello!

I'm looking for elegant solution for following problem:

I receive request that is an XML document or object. I need to enrich
it (add new element or set a property). The problem is that the value
I want to enrich with is the result of some endpoint invocation.

I know that I can do it using custom processor, but maybe there is
some Expression instance that evaluates to result of endpoint
invocation? this way I can simply use setBody() or setHeader() methods
with such Expression.

Or maybe there is better way to do it? I'm just curious if I can avoid
using custom processors and express everything in DSL.

Thanks,
Romek
Reply | Threaded
Open this post in threaded view
|

Re: How to enrich message with the result of other invocation

jstrachan
On 29/10/2007, Roman Kalukiewicz <[hidden email]> wrote:

> Hello!
>
> I'm looking for elegant solution for following problem:
>
> I receive request that is an XML document or object. I need to enrich
> it (add new element or set a property). The problem is that the value
> I want to enrich with is the result of some endpoint invocation.
>
> I know that I can do it using custom processor, but maybe there is
> some Expression instance that evaluates to result of endpoint
> invocation? this way I can simply use setBody() or setHeader() methods
> with such Expression.
>
> Or maybe there is better way to do it? I'm just curious if I can avoid
> using custom processors and express everything in DSL.

Interesting use case! :) Am sure over time we'll figure out nicer and
richer ways of putting all kinds of things like this into the DSL.

I wonder if we could expose 'invoke an endpoint' nicely inside XSLT or
XQuery to make it easy to enrich messages that way?

Am sure we could do something like

let $doc := .
for $invoke in camel-invoke("some-uri")/*
return <result>{ $doc, $invoke }</result >

I couldn't see an easy way to use XQuery to say effectively, 'add the
XQuery expression into the context node as a child' - am sure with
more XQuery ninja there's a way to do it a bit cleaner.

I've just added some XQuery tutorial links to the site BTW:
http://cwiki.apache.org/CAMEL/xquery.html
--
James
-------
http://macstrac.blogspot.com/

Open Source SOA
http://open.iona.com
Reply | Threaded
Open this post in threaded view
|

Re: How to enrich message with the result of other invocation

RomKal
2007/10/30, James Strachan <[hidden email]>:
> I've just added some XQuery tutorial links to the site BTW:
> http://cwiki.apache.org/CAMEL/xquery.html

BTW link you added to wiki doesn't work (the one with XQuery Primer).
It starts to work if you add an 'l' letter at the end of the address
;)

Romek
Reply | Threaded
Open this post in threaded view
|

Re: How to enrich message with the result of other invocation

jstrachan
On 30/10/2007, Roman Kalukiewicz <[hidden email]> wrote:
> 2007/10/30, James Strachan <[hidden email]>:
> > I've just added some XQuery tutorial links to the site BTW:
> > http://cwiki.apache.org/CAMEL/xquery.html
>
> BTW link you added to wiki doesn't work (the one with XQuery Primer).
> It starts to work if you add an 'l' letter at the end of the address
> ;)

Great catch, fixed - thanks! :)

BTW the website is a wiki...
http://activemq.apache.org/camel/how-do-i-edit-the-website.html
--
James
-------
http://macstrac.blogspot.com/

Open Source SOA
http://open.iona.com
Reply | Threaded
Open this post in threaded view
|

Re: How to enrich message with the result of other invocation

jstrachan
In reply to this post by jstrachan
On 30/10/2007, James Strachan <[hidden email]> wrote:

> On 29/10/2007, Roman Kalukiewicz <[hidden email]> wrote:
> > Hello!
> >
> > I'm looking for elegant solution for following problem:
> >
> > I receive request that is an XML document or object. I need to enrich
> > it (add new element or set a property). The problem is that the value
> > I want to enrich with is the result of some endpoint invocation.
> >
> > I know that I can do it using custom processor, but maybe there is
> > some Expression instance that evaluates to result of endpoint
> > invocation? this way I can simply use setBody() or setHeader() methods
> > with such Expression.
> >
> > Or maybe there is better way to do it? I'm just curious if I can avoid
> > using custom processors and express everything in DSL.
>
> Interesting use case! :) Am sure over time we'll figure out nicer and
> richer ways of putting all kinds of things like this into the DSL.
>
> I wonder if we could expose 'invoke an endpoint' nicely inside XSLT or
> XQuery to make it easy to enrich messages that way?
>
> Am sure we could do something like
>
> let $doc := .
> for $invoke in camel-invoke("some-uri")/*
> return <result>{ $doc, $invoke }</result >
>
> I couldn't see an easy way to use XQuery to say effectively, 'add the
> XQuery expression into the context node as a child' - am sure with
> more XQuery ninja there's a way to do it a bit cleaner.

A maybe cleaner way to do it in XQuery is something like this...

<result>
{/*}
{camel-invoke('some-uri')}
</result>

This will embed the original document inside <result> then the result
of the camel-invoke method in there too.

I've not seen a cleaner way to put the invocation inside the first
child of the input yet though.

--
James
-------
http://macstrac.blogspot.com/

Open Source SOA
http://open.iona.com
Reply | Threaded
Open this post in threaded view
|

Re: How to enrich message with the result of other invocation

Nicky Sandhu
In reply to this post by RomKal

RomKal wrote
I know that I can do it using custom processor, but maybe there is
some Expression instance that evaluates to result of endpoint
invocation? this way I can simply use setBody() or setHeader() methods
with such Expression.
 Thats a good idea. I have needed this myself. Its along the lines of ContentEnricher .

One way to do this would be to define ContentEnricherProcessor and the Resource would be replaced by an invocation of any Processor. The original message (before enrichment) could be saved of in either a header or could be appended with the new message (after enrichment) with the out response of the processor.

Looks like a JIRA issue is needed to track this
Reply | Threaded
Open this post in threaded view
|

Re: How to enrich message with the result of other invocation

Nicky Sandhu
Opened this issue https://issues.apache.org/activemq/browse/CAMEL-209
Nicky Sandhu wrote
RomKal wrote
I know that I can do it using custom processor, but maybe there is
some Expression instance that evaluates to result of endpoint
invocation? this way I can simply use setBody() or setHeader() methods
with such Expression.
 Thats a good idea. I have needed this myself. Its along the lines of ContentEnricher .

One way to do this would be to define ContentEnricherProcessor and the Resource would be replaced by an invocation of any Processor. The original message (before enrichment) could be saved of in either a header or could be appended with the new message (after enrichment) with the out response of the processor.

Looks like a JIRA issue is needed to track this
Reply | Threaded
Open this post in threaded view
|

Re: How to enrich message with the result of other invocation

RomKal
In reply to this post by Nicky Sandhu
>  Thats a good idea. I have needed this myself. Its along the lines of
> http://www.enterpriseintegrationpatterns.com/DataEnricher.html
> ContentEnricher  .
>
> One way to do this would be to define ContentEnricherProcessor and the
> Resource would be replaced by an invocation of any Processor. The original
> message (before enrichment) could be saved of in either a header or could be
> appended with the new message (after enrichment) with the out response of
> the processor.

Anyway now it can easily be solved using such construct which is just
clear without any magic behind:

            setHeader("original", body()).
            setBody(constant("some other request")).
            to("someEndpoint").
            setOutHeader("additionalData", body()).
            setOutBody(header("original"));

Unfortunately two last lines doesn't work because of
http://issues.apache.org/activemq/browse/CAMEL-208 but I've already
send a patch for this problem.

Of course if we can find out an easy and natural way of expressing
ContentEnricherProcessor in DSL/XML it could be interesting
improvement.

Romek