1
votes

How to define a Camel Route with an HTTP for the "from" endpoint?

My goal is to define a Route that when there is an HTTP request, a Message will be enqueued on the ActiveMQ Queue.

I tried the following Route definition:

<route>
  <from uri="http://localhost:8181/cxf/crm/customerservice/customers" />
  <to uri="activemq:queue:LOG.ME" />
</route>

From a browser, I access the URL:

http://localhost:8181/cxf/crm/customerservice/customers/123

I had verified that the HTTP request had reach the web service "customerservice", since I received an XML response from the web service. However, no Message was enqueued on the ActiveMQ Queue.

Below is the Route definition that processes Messages from the ActiveMQ Queue.

<route>
  <from uri="activemq:queue:LOG.ME" />
  <multicast>
    <pipeline>
      <bean ref="processor1" method="handle" />
      <to uri="mock:result" />
    </pipeline>
    <pipeline>
      <bean ref="processor2" method="handle" />
      <to uri="mock:result" />
    </pipeline>
  </multicast>
</route>

I verified that nothing was enqueued to the ActiveMQ, because the "handle" method of my beans "processor1" and "processor2" was not executed.

How to define a Camel Route with an HTTP for the "from" endpoint?

Thanks.

2

2 Answers

2
votes

If you want to listen to HTTP requests, then you need either to use the servlet component if you are running inside a web application or the jetty component which embedds a simple http server.

Both have good documentations and examples.

The http and http4 components are for producers only (<to ... />).

1
votes

To listen to incoming http requests a proxy can be set up using jetty or cxf component which will then invoke the web service as well as log a message to activemq.

For example,

from("jetty:http://localhost:8282/xxx").
     to("http://localhost:8181/cxf/crm/customerservice/customers").
          to("activemq:queue:LOG.ME");

Now, to access the web service the proxy can be invoked as http://localhost:8282/xxx, instead of directly calling the web service. A proxy can be set up using the cxf component too, it is well documented.