Wednesday 21 February 2018

OSGi plugin framework using Http Whiteboard

It is not uncommon to have extensibility feature in software today. Browsers, IDEs, Text Editors(Notepad++) etc. allow installing plugins to augment the user experience.  I had to create a proof of concept(PoC) of a plugin framework for my academic project. I have been asking around people but nobody had a detailed solution about how to build it. So, here is my little contribution to save your efforts!

I needed to make a web app which provides the feature to install/uninstall plugins. Think of something like Eclipse IDE like software. The only difference is you cannot restart it like Eclipse to apply changes. I guess I can say, it would be similar to Wordpress.

I thought of implementing this using OSGi as follows: Whenever a new plugin is installed, new HTTP servlet will be registered at Http Whiteboard. These exposed servlet endpoints will be used by other bundles as well as third-party apps which are present outside. Each plugin will be developed separately as an OSGi bundle. I can use Apache Felix web console to allow the user to install/uninstall bundle of his choice.

To try out whether this is really possible, I decided to create PoC as follows:

For PoC, I added two modules named opcua and id. Both will register their servlets as well as register at manager module's end. Manager module is responsible for persisting passed information in a database. Web App can can fetch this info and show plugin buttons. This buttons may redirect to plugin UI. This persistence facility is not demonstrated in PoC. For demo purpose, manager will print a message as registering module calls register methods.

Proposed plugin framework


Eclipse Workspace


The run bundle is optional but highly recommended to package all your bundles in single JAR. You can create it use BndTool's empty template. You have to create .bndrun file manually. Remember to include required bundles in runtime. You .bndrun file should look like: https://raw.githubusercontent.com/nikhilbchilwant/OSGI-HTTP-Whiteboard-Plugin-Framework/master/run/all.bndrun

Use run OSGi and you will see following output on the console:

ID module activated
Registered ID module @Manager
OPC-UA module activated
Registered Opcua module @Manager

You should be able to browse following links:

  1. http://localhost:8080/id
  2. http://localhost:8080/opcua

Tools used for this: Windows 7, 64 bit, Eclipse Oxygen.2, Java 8, OSGi enroute template, Bndtool 3.3.0

No comments:

Post a Comment