Using BODY as HTTP Query String Parameter...

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

Using BODY as HTTP Query String Parameter...

James Carman
There is a web service at my company that returns XML documents, but
you have to query it using a query string.  I want to send the single
parameter (an id) as the body of the incoming message and I want to
append that body value to the HTTP URL.  So, I want something like:

http://my.service.url/service.cgi?id=${body}

Is that possible using the Java DSL?

Thanks,

James

p.s. Camel Rocks!  I've downloaded the MEAP Camel in Action book and
I'm working my way through it.  Very cool indeed!
Reply | Threaded
Open this post in threaded view
|

Re: Using BODY as HTTP Query String Parameter...

Claus Ibsen-2
On Fri, Jun 25, 2010 at 10:41 PM, James Carman
<[hidden email]> wrote:
> There is a web service at my company that returns XML documents, but
> you have to query it using a query string.  I want to send the single
> parameter (an id) as the body of the incoming message and I want to
> append that body value to the HTTP URL.  So, I want something like:
>
> http://my.service.url/service.cgi?id=${body}
>
> Is that possible using the Java DSL?
>

Yes you can for example use the setHeader to set the id header beforehand

.setHeader("id").simple("${body}").to("http://xxxx");

Or use the recipient list to construct a dynamic uri
http://camel.apache.org/recipient-list.html

.recipientList().simple("http://xxxx?id=${body}");

We use the Camel expression language, simple, to define the dynamic expression:
http://camel.apache.org/simple.html



> Thanks,
>
> James
>
> p.s. Camel Rocks!  I've downloaded the MEAP Camel in Action book and
> I'm working my way through it.  Very cool indeed!
>

--
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Reply | Threaded
Open this post in threaded view
|

Re: Using BODY as HTTP Query String Parameter...

Willem.Jiang
Administrator
In reply to this post by James Carman
Hi,

You could set the message with Exchange.HTTP_QUERY to let the http
producer pick up the query string dynamically.

Here is the example

from("direct:start").setHeader(Exchange.HTTP_QUERY).
simple("id=${body}")).to("http://XXXX");

Willem
----------------------------------
Apache Camel, Apache CXF committer
Open SOA http://www.fusesource.com
Blog http://willemjiang.blogspot.com
Tiwtter http://twitter.com/willemjiang

James Carman wrote:

> There is a web service at my company that returns XML documents, but
> you have to query it using a query string.  I want to send the single
> parameter (an id) as the body of the incoming message and I want to
> append that body value to the HTTP URL.  So, I want something like:
>
> http://my.service.url/service.cgi?id=${body}
>
> Is that possible using the Java DSL?
>
> Thanks,
>
> James
>
> p.s. Camel Rocks!  I've downloaded the MEAP Camel in Action book and
> I'm working my way through it.  Very cool indeed!
>