You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sushil_vsk5 <su...@yahoo.co.in> on 2012/03/25 07:25:14 UTC

Invoking Camel Routes from existing Servlets / POJOS

Hello:

I have an existing Servlet Container hosting some servlets which receive
HTTP requests. Now I am planning to develop some Camel routes which will
reside locally to my web application and shall all start using a "direct:"
URI. 

In this regard, I want to be able to invoke my routes from my existing
Servlets whenever a request arrives. What is the best way to do this? Should
I be using a ProducerTemplate? If so, how do I initialize the
ProducerTemplate to send requests to my "direct:" route endpoint?

Going forward, I will retire these Servlets and use the camel-http and
camel-servlets instead.

Also, what if I want to invoke these routes from a simple POJO? Will the
same approach work?

Regards,
Sushil

--
View this message in context: http://camel.465427.n5.nabble.com/Invoking-Camel-Routes-from-existing-Servlets-POJOS-tp5592834p5592834.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Invoking Camel Routes from existing Servlets / POJOS

Posted by Claus Ibsen <cl...@gmail.com>.
On Sun, Mar 25, 2012 at 12:09 PM, sushil_vsk5 <su...@yahoo.co.in> wrote:
> Thanks a lot for that clarification. All parts are clear but what is not
> clear is, lets say my Camel Context is configured through Spring, how can I
> get access to a Producer Template from a POJO which is not managed by either
> Spring or Camel. Its just a plain old Java class. How do I get the handle
> for a Producer Template inside it?
>

If you define Camel in the Spring XML file, eg <camelContext> in the
Spring XML file, then
you just need to figure out how to get access to Spring from your POJO.

And then from Spring you can get access to the Camel / producer template.


> --
> View this message in context: http://camel.465427.n5.nabble.com/Invoking-Camel-Routes-from-existing-Servlets-POJOS-tp5592834p5593025.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Invoking Camel Routes from existing Servlets / POJOS

Posted by sushil_vsk5 <su...@yahoo.co.in>.
Thanks a lot for that clarification. All parts are clear but what is not
clear is, lets say my Camel Context is configured through Spring, how can I
get access to a Producer Template from a POJO which is not managed by either
Spring or Camel. Its just a plain old Java class. How do I get the handle
for a Producer Template inside it?

--
View this message in context: http://camel.465427.n5.nabble.com/Invoking-Camel-Routes-from-existing-Servlets-POJOS-tp5592834p5593025.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Invoking Camel Routes from existing Servlets / POJOS

Posted by Claus Ibsen <cl...@gmail.com>.
On Sun, Mar 25, 2012 at 7:25 AM, sushil_vsk5 <su...@yahoo.co.in> wrote:
> Hello:
>
> I have an existing Servlet Container hosting some servlets which receive
> HTTP requests. Now I am planning to develop some Camel routes which will
> reside locally to my web application and shall all start using a "direct:"
> URI.
>
> In this regard, I want to be able to invoke my routes from my existing
> Servlets whenever a request arrives. What is the best way to do this? Should
> I be using a ProducerTemplate? If so, how do I initialize the
> ProducerTemplate to send requests to my "direct:" route endpoint?
>

Yes a producer template is a good way to send a message to a Camel
endpoint from any POJO.

See this FAQ
http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html

There ought to be a way with a onInit method on a servlet to get hold
of some context,
where you can lookup / create the producer template.

A very old Camel Axis 1.4 tutorial does that with some spring servlet code
http://camel.apache.org/tutorial-axis-camel.html

> Going forward, I will retire these Servlets and use the camel-http and
> camel-servlets instead.
>
> Also, what if I want to invoke these routes from a simple POJO? Will the
> same approach work?
>

Yeah using producer template from a POJO is a good way to send a
message to a camel route/endpoint.


> Regards,
> Sushil
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Invoking-Camel-Routes-from-existing-Servlets-POJOS-tp5592834p5592834.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/