internationalizationosgiwarwab

Using OSGi WAB as a Resource bundle inside a war


I'm currently in the process of developing a translation service for a host of web applications that was developed in house. I'm faced with the problem where we have packed all of the applications with properties files containing different languages to have i18n support.

One of the things that was suggested during a brain storming session was to make a translation service an OSGi module. Problem is I have 0 experience with OSGi and don't know how to go about it. Further talks and googleing suggests developing the services as a WAB.

The problem I am faced with is how do I call a resource from a WAB? Is it possible at all or am I going in the wrong path?

Any help would be greatly appropriated.

Regards S.


Solution

  • It's hard to say for sure without knowing more details, but you probably want to use a wab instead of a war, rather than inside of a war. A wab is just a war with osgi metadata. A nice approach for internationalisation (and the reason the idea came up, I'm guessing) is to use fragments for the resource bundles. This article has a tutorial of both developing a wab and then adding fragments for internationalisation.

    I'd also advise against trying to load resources directly from an osgi bundle, since osgi encapsulation often makes the resources inaccessible unless you do ugly things with package imports and exports. Instead, look up a service and have it do the resource loading. Using something like declarative services or blueprint is much easier than programmatic service access.