Service Boss Level Part 2: Custom Web Console Plugins

Published on by Dan KlcoPicture of Me Dan Klco

You’ve got your awesome service. It performs all sorts of complex tasks and maybe even uses a Sling Service Factory to provide multiple configurations. But how do you know what it’s doing? Well, of course you need to have appropriate logging, but another tool you can leverage is the Apache Felix Web Console, by creating a custom Web Console Plugin. Your plugin can be accessed through Adobe CQ and Apache Sling’s Web Console and can display any information you can render in HTML.

Apache Felix provides a really simple class you can extend for creating custom Web Console screens, the AbstractWebConsolePlugin. This class will automatically leverage the look and feel of the Apache Felix console and makes it easy for you to create your own console screen. There are three main methods to override:

  • getLabel - This method should return the URL for the console page, ex: helloworld
  • getTitle - This method should return the text to display to the user in the Felix Console navigation and title bar
  • renderContent - This method will be executed when your Web Console page is accessed, it should write out the Web Console page content

Your WebConsole plugin class, should extend the AbstractWebConsolePlugin class and should be a standard OSGi Service. You should extend the Servlet interface and should have properties exposing the label and title for your Web Console plugin as properties. Generally, I would recommend using constants to ensure that the method and properties use the same value.

  @Property(name = WebConsoleConstants.PLUGIN_TITLE,value=HelloWorldWebConsole.TITLE)})
public class HelloWorldWebConsole extends AbstractWebConsolePlugin {
  [... code ...]

Since the Web Console plugin is an OSGi service, you can inject references to any other Service or Component. You can simply retrieve the Service you want to monitor and retrieve the information you need from it.

When you go to to write the HTML to the page, retrieve the PrintWriter from the response, ex: res.getWriter(). The console supports easily styled tables, with styled header rows, make sure to add the CSS class ‘content’ to all cells containing content to get the correct padding. Additionally, you can add the class ‘container’ to make a column header with a grey background.

Once your Web Console Plugin is complete, you should be able to access it from the Apache Felix Web Console. If you are using CQ 5.6, it will be in the Main dropdown.

Web Console Plugin Screen

As you can see Custom Web Console Plugins are easy to create and can allow administrators valuable views into the functioning of OSGi Services and the health of your application.


comments powered by Disqus