How can I invoke a RESTful service through Apache Camel?

jasmeet24 picture jasmeet24 · Apr 16, 2012 · Viewed 44.8k times · Source

I am currently using a HTTP method for invoking some URL which will create a JIRA issue.

Now I want to use Apache Camel, how can I use that?

I need to invoke the following link through Camel:

http://localhost:8080/rest/api/2/project/" + key + /components

As I'm new to Camel, please suggest some solutions and examples too.

Thanks

Answer

Claus Ibsen picture Claus Ibsen · Apr 16, 2012

See also this FAQ about using dynamic to endpoints in Camel http://camel.apache.org/how-do-i-use-dynamic-uri-in-to.html

Essentially the EIP pattern for this is the recipient list.

So in your case it could also be simplified to as one EIP

<recipientList>
  <simple>http://localhost:8080/rest/api/2/project/${header.myKey}/components</simple>
</recipientList>

Mind the http component in Camel is fully synchronous. If you want to do request/reply over HTTP and avoid having the caller block while waiting for the reply message, then you can use some of the other HTTP components from Camel such as:

  • camel-ahc
  • camel-http4
  • camel-jetty