You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by lassesvestergaard <la...@gmail.com> on 2013/07/17 21:18:04 UTC

jsf and apache camel

Hi all.

I'm learning camel and jsf at the same time. What I want to do is to create
a jsf web application where it is possible to create, edit and delete
routes. This means that I need to have camel running in the background for
ever. I want to put camel inside a war, and when the application is deployed
on a tomcat server, Camel will start and I can begin making routes through a
browser.

My initial problem is that I don't know how to run camel in the background
of a jsf application. Web applications are only request scoped, so how do i
configure jsf to keep part of the web application alive constantly? I know
this is not directly related to Camel, but it's part of my problem and I
decided to start from this forum. Please post any articles you might find
relevant on this matter.

My next issue is more directly related to camel. I want to be able to create
routes with anonymous Processor objects (for simple conversion of data). As
far as I understand it, this is only possible through native java, and not
using xml. This means that I can't create anonymous Processor objects with
ex. Spring. Furthermore I can't use the "Camel web applications without
Spring example"
(http://www.javacodegeeks.com/2013/01/camel-2-11-camel-web-applications-without-spring.html).
Is this correctly understood? If not, please provide a link to where I can
learn more.

I know about hawt.io, and it seems like you can't create an anonymous
Processor objects there either.

Best regards



--
View this message in context: http://camel.465427.n5.nabble.com/jsf-and-apache-camel-tp5735818.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: jsf and apache camel

Posted by lassesvestergaard <la...@gmail.com>.
Ok. I have some clarifying questions then :-)


jstrachan wrote
> I think you're confusing anonymous processors with DI beans. A data
> format is mostly just a bean which needs to be registered in some
> registry (JNDI, spring, guice, whatever). Those are outside of the
> camel DSL and camel looks them up by name. So you don't need anonymous
> processors in the Java DSL; you just need a way to load/register beans
> by name that you can reference from your dynamic camel routes.

What I want to do is; I want a registered user (could more or less be
anyone) to be able to create a custom route, on my my Apache camel web
application (of course there are some security issues here, but this will be
solved in different ways - that's an other discussion). The user could ex.
be interested in doing some screen scraping from some arbitrary web page
once a day. I imagine that the user would log in to my jsf page, and then
start assembling (drag and drop much like Hawt.io) a camel route. The user
would initially drag in ex. a timer component, then a http component, and
setup the necessary properties, headers etc. After that he might want to
create an anonymous processor because he can't find any component that can
filter and convert the html from the scraped web page into what he want (he
might might want to get the inner html from all p tags inside a div tag that
has id="dummy"). When he has done this custom conversion/filtering he want's
to send the resulting data to a sql database, which he does through the SQL
component. This scenario is just one example, and I want users to be able to
do what ever data routing they can imagine. They might want to send an image
pixel by pixel from some arbitrary place to an other arbitrary place. 

I'm not sure I understand you correctly. Do you suggest that I can do the
above scenario without anonymous processors, and the user would be able to
do the same filtering and conversion through xml only?

Of course I want to be able, as the administrator, to feed Camel with new
components through it's lifetime, but I'm not sure I would like ordinary
users to be able to do this from the start. This means that I will develop a
backend, to the website, where I can upload a .java file, and then the
server would compile, class load and inject the component into Camel. After
that anyone can just select the component form a list (on my website) of all
accessible camel components, and drag 'n drop a route similar to Hawt.io.
Furthermore I want users to be able to edit and delete their own routes.

I'm not sure if I'm missing some important point here.

Thanks for your time.

/Lasse Vetsergaard



--
View this message in context: http://camel.465427.n5.nabble.com/jsf-and-apache-camel-tp5735818p5736300.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: jsf and apache camel

Posted by James Strachan <ja...@gmail.com>.
On 22 July 2013 11:26, lassesvestergaard <la...@gmail.com> wrote:
> Thank you very much James.
>
> I ended up using JSF. I found out how to integrate Camel into a JSF
> application. I'm not sure it's the best way, but it seems to work (please
> enlighten me if you know a better solution).

angularjs is a much better solution for building great HTML5 web apps;
but thats maybe an answer to a different question than you asked ;)


> What I did is making a new
> managed bean (in JSF 2.0), that is application scoped, and through it's
> constructor starting a camelcontext. This way I can access the full Camel
> application in the web layer, and the camelcontext exists as long as the
> webserver is not shut down.
>
> The reason why I want to be able to create anonymous processors on-the-fly,
> is that I want users to be able to create custom routes from the web
> interface.

You can create custom routes on the fly using JMX, jolokia, REST or
Java just fine without using anonymous processors.


> I think anonymous processors are relevant because data formats
> can be more or less arbitrary, and therefore needs to be handled uniquely
> per route definition. I will definitely look into the build-in type
> converter and bean integration though.

I think you're confusing anonymous processors with DI beans. A data
format is mostly just a bean which needs to be registered in some
registry (JNDI, spring, guice, whatever). Those are outside of the
camel DSL and camel looks them up by name. So you don't need anonymous
processors in the Java DSL; you just need a way to load/register beans
by name that you can reference from your dynamic camel routes.

You're web app maybe needs to support letting folks edit, say, spring
XML files to define data formats so they can be loaded dynamically.

--
James
-------
Red Hat

Email: jstracha@redhat.com
Web: http://fusesource.com
Twitter: jstrachan, fusenews
Blog: http://macstrac.blogspot.com/

Open Source Integration

Re: jsf and apache camel

Posted by lassesvestergaard <la...@gmail.com>.
Thank you very much James.

I ended up using JSF. I found out how to integrate Camel into a JSF
application. I'm not sure it's the best way, but it seems to work (please
enlighten me if you know a better solution).  What I did is making a new
managed bean (in JSF 2.0), that is application scoped, and through it's
constructor starting a camelcontext. This way I can access the full Camel
application in the web layer, and the camelcontext exists as long as the
webserver is not shut down.

The reason why I want to be able to create anonymous processors on-the-fly,
is that I want users to be able to create custom routes from the web
interface. I think anonymous processors are relevant because data formats
can be more or less arbitrary, and therefore needs to be handled uniquely
per route definition. I will definitely look into the build-in type
converter and bean integration though.

Thanks

Lasse Vestergaard



--
View this message in context: http://camel.465427.n5.nabble.com/jsf-and-apache-camel-tp5735818p5736018.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: jsf and apache camel

Posted by James Strachan <ja...@gmail.com>.
You could learn angularjs (instead of JSF) and camel together, which
is way cooler and more fun - then hack on hawtio :)

More below...

On 17 July 2013 20:18, lassesvestergaard <la...@gmail.com> wrote:
> Hi all.
>
> I'm learning camel and jsf at the same time. What I want to do is to create
> a jsf web application where it is possible to create, edit and delete
> routes. This means that I need to have camel running in the background for
> ever. I want to put camel inside a war, and when the application is deployed
> on a tomcat server, Camel will start and I can begin making routes through a
> browser.
>
> My initial problem is that I don't know how to run camel in the background
> of a jsf application. Web applications are only request scoped, so how do i
> configure jsf to keep part of the web application alive constantly? I know
> this is not directly related to Camel, but it's part of my problem and I
> decided to start from this forum. Please post any articles you might find
> relevant on this matter.
>
> My next issue is more directly related to camel. I want to be able to create
> routes with anonymous Processor objects (for simple conversion of data). As
> far as I understand it, this is only possible through native java, and not
> using xml. This means that I can't create anonymous Processor objects with
> ex. Spring. Furthermore I can't use the "Camel web applications without
> Spring example"
> (http://www.javacodegeeks.com/2013/01/camel-2-11-camel-web-applications-without-spring.html).
> Is this correctly understood? If not, please provide a link to where I can
> learn more.
>
> I know about hawt.io, and it seems like you can't create an anonymous
> Processor objects there either.

In Camel XML you can't create an anonymous inner class for a Processor
(since that requires Java source and a Java compiler); so hawtio has
the same limitation. Though if you write some Java bean/processor and
register it into your registry (JNDI / Spring / CDI / guice /
whatever) you can then reference it from the XML DSL (and so from
hawtio, Fuse IDE etc)

So a simpler solution than creating anonymous Processors is just to
create Java methods and then invoke them from the Camel DSL (e.g.
method call expressions or using bean integration)
http://camel.apache.org/bean-integration.html

or if its for converting between different data types; then Camel's
type conversion approach is pretty good:
http://camel.apache.org/type-converter.html

--
James
-------
Red Hat

Email: jstracha@redhat.com
Web: http://fusesource.com
Twitter: jstrachan, fusenews
Blog: http://macstrac.blogspot.com/

Open Source Integration