You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by stpdave <da...@stpenable.com> on 2007/09/02 22:12:26 UTC

So many options, which to chose

Hi,

The problem I first want to solve with Camel is this:
My servlet based application produces a file with a set of arguments in it.
Like so
arg1,arg2,argN
I want to pick up this file content, and append it to the end of a http url,
like so
http://www.example.com/cgi/getres?arg1,arg2,argN
using POST.
The http server response is a set of data I want to write to a file.

I already have a client class I used to use with Mule (yes I am a refugee).
It encapsulates an endpoint uri, whether there is a return payload, whether
it is syncronous and another piece of String data. I can change this but for
the moment prefer not to, just reuse it with Camel.

The problem I have is I am spoilt for choice with Camel in the number of
options I have to achieve this end. so if someone can advise on the optimum
approach I will give it a whirl.

My current thinking is I can use the uri method of adding components I need.
Then store the routing in the spare String object in my current client class
as Groovy script.

I am a little uncertain of the way these components are strung together. I
would guess like this:
from("file://test").to("http://www.example.com/cgi/getres?"+outputFromFileAsString).to("file://outputfile");
but am not sure how you get the content of the source file into a string.
Also whether the return from the http POST can automatically be mapped into
the outputfile via a file endpoint.

I realise my ideas are still abstract at this stage so help in making them
real is much appreciated.

Thx.

David
-- 
View this message in context: http://www.nabble.com/So-many-options%2C-which-to-chose-tf4369068s22882.html#a12452890
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: So many options, which to chose

Posted by James Strachan <ja...@gmail.com>.
On 9/2/07, stpdave <da...@stpenable.com> wrote:
> Hi,
>
> The problem I first want to solve with Camel is this:
> My servlet based application produces a file with a set of arguments in it.
> Like so
> arg1,arg2,argN
> I want to pick up this file content, and append it to the end of a http url,
> like so
> http://www.example.com/cgi/getres?arg1,arg2,argN
> using POST.
> The http server response is a set of data I want to write to a file.
>
> I already have a client class I used to use with Mule (yes I am a refugee).

LOL!


> It encapsulates an endpoint uri, whether there is a return payload, whether
> it is syncronous and another piece of String data. I can change this but for
> the moment prefer not to, just reuse it with Camel.
>
> The problem I have is I am spoilt for choice with Camel in the number of
> options I have to achieve this end. so if someone can advise on the optimum
> approach I will give it a whirl.
>
> My current thinking is I can use the uri method of adding components I need.
> Then store the routing in the spare String object in my current client class
> as Groovy script.
>
> I am a little uncertain of the way these components are strung together. I
> would guess like this:
> from("file://test").to("http://www.example.com/cgi/getres?"+outputFromFileAsString).to("file://outputfile");
> but am not sure how you get the content of the source file into a string.
> Also whether the return from the http POST can automatically be mapped into
> the outputfile via a file endpoint.
>
> I realise my ideas are still abstract at this stage so help in making them
> real is much appreciated.

I guess there's a few different ways to do this. Maybe a good start is
the Dynamic Recipient List...
http://activemq.apache.org/camel/recipient-list.html

which basically means an expression defines the endpoint URI to send a
message exchange to.

So you could do something like this...

from("file://test").convertBody(String.class).
  recipientList(el("http://www.example.com/cgi/getres?${body}")).
  to("file://outputfile");

This would use EL (though any other language would be fine too, like Groovy)
http://activemq.apache.org/camel/el.html

to create the URI dynamically from the in messages's body.

If the processing of the file differs, it might be you want to write
some POJO to represent the body; or a custom transformer, to
parse/tokenize the file first.
e.g. something vaguely like this...

from("file://test").setBody(body().tokenize(",")).
  recipientList(el("http://www.example.com/cgi/getres?${body[0]}=${body[1]}&${body[2]}=${body[3]}")).
  to("file://outputfile");

If the creation of that URI gets really complex, you could just have
your own Expression object (or even Language plugin) which can be used
to turn the input message into the URL.

  recipientList(new Expression() {...})

So there's a few different ways to approach this, but at its core I'd
say starting with the dynamic recipient list is a good place to start.
-- 
James
-------
http://macstrac.blogspot.com/