Friday, January 31, 2014

OSGi based web applications

OSGi attracts a lot nowadays but being a well spread technology for lightweight embedded systems and such things as Eclipse, Glassfish, etc. it is not so well spread in enterprise scenarios (despite existence of OSGi Enterprise Specification, but I've still heard success story about Apache Karaf production usage). OSGi as it breaks your application into modules and provides service registry and event bus is a right way to maintain medium to huge codebase and overcome issues with integration in big distributed teams. Live code and configuration updates support is what must have if you want availability. See beautiful article Why OSGi service dynamics are useful.
The question I was wondering recently is there a good web application framework that plays nice with OSGi (something like JSF in Java EE or Spring MVC). I found the answer on stackoverflow:
I'm developing OSGi based web applications on a daily base. We have a slightly alternative approach which works very well:
  1. RESTful web services implemented using OSGi services 
  2. Modular AngularJS based user interface, packaged in OSGi bundles Although AngularJS is obviously not a Java web framework, it fits modern web development perfectly. If you are familiar with Java MVC web frameworks it's also easy to understand Angular.
The main question is how to modularize your code. At the backend we implement everything as OSGi services. RESTful webservices are implemented with JAX-RS using the Amdatu (amdatu.org). With Amdatu you can use JAX-RS in a way that fits OSGi well. Each RESTful resource and lower level services are packaged in separate bundles as well, so the backend is fully modular.
To modularize the UI itself we separate functional different parts of the application as different Angular applications. Each Angular application is packaged in separate bundles as well, using the Amdatu resource provider.
The idea is a good one regardless OSGi part. If you are about to build a web app consider providing just REST endpoint and put on top of it something like AngularJS/Backbone/Knockout. And providing REST endpoint itself is a simple task with amdatu-web.

No comments:

Post a Comment