I want to build a web application which basically is a restful web-service serving json messages. I would like it to be as simple as possible. I was thinking about using servlets (with annotations). JPA as a database layer is a must – Toplink or Hibernate. Preferably working on Tomcat. I want to have app divided into modules serving different functionality (auth service, customer service, etc..). And I would like to be able to update those modules without reinstalling whole application on the server – like eclipse plugins, user is notified (when he enters webapp’s home url) that update is available, clicks it, and app is downloading and installing updated module.
I think this functionality can be made with OSGI, but I can’t find any example code, or tutorial with simple hello world updatable servlet providing some data from database through jpa.
I’m looking for an advice:
– Is OSGI the right tool for this or it can be done with something simpler?
– Where can I find some examples covering topic (or topics) which I need for this project.
– Which OSGI implementation would be best-simplest for this task.
*My knowledge of OSGI is basic. I know how bundles are described, I understand concept of OSGI container and what it does. I have never created any OSGI app yet.
I think OSGi is a good fit for what you’re describing, yes. Once you add servlets and JPA into the mix you’re looking at using what’s known as enterprise OSGi, which is a layer of functionality on top of core OSGi. There are two main implementations, Apache Aries and Eclipse Gemini. These come pre-integrated into various servers, including Apache Geronimo, or you can roll your own stack. (I’m an Aries committer.)
For a tutorial on web development using Aries, have a look at http://www.javabeat.net/articles/378-writing-an-osgi-web-application-1.html. Aries themselves have a sample you can download and play with, apache.org/downloads/blogsample-0.3.html. However, it’s a bit more complex than Hello World, and you may need a bit more OSGi knowledge than your current level to get the most out of it. As a starting point, I’d recommend getting familiar with an OSGi console (the blog sample uses the equinox one) to see what’s going on in your system. For equinox, the ss command is most useful, and the bundle command is the one I use next most often.
If you search for enterprise OSGi, servlet, and JPA, you should find some useful resources. DeveloperWorks have several articles.