Providing Resources

Extending the Apache Felix Web Console with new functionality is as easy as registering a javax.servlet.Servlet with at least the felix.webconsole.label service registration property set (see above). Providing resources is a bit more complex and requires more work on behalf of the plugin.

Out of the box the Apache Felix Web Console plugin servces resources through the OSGi HttpContext used to register the web console with OSGi HttpService. This is done by registering resources with the HttpService below the /res alias. This mechanism though does not lend itself for easy extensibility. Therefore another mechanism has been chosen, which relies on similar mechanisms.

A web console plugin may implement a getResource method which is looked up using reflection. This method is called by the AbstractWebConsole.doGet to check whether the request is actually for a resource.

The method has the following signature:

modifier URL getResource(String path);

Where the modifier may be public, protected, or private (if the method is declared in the class of the resource provider). It is suggested to use the private modifier if the method is declared in the resource provider class or the protected modifier if the method is declared in a base class of the resource provider.

This method is called with the path info of the request (HttpServletRequest.getPathInfo()) and expects and URL to the resource to be sent to the client. If the path cannot be resolved to a resource the getResource method is expected to return null thus causing regular processing of rendering the page.

If the getResource method returns an accessible non-null URL, the request is serviced by sending back the contents of the given URL. Simple caching support is included which handles the If-Modified-Since header and sets the Last-Modified header from the resource URL.