users@glassfish.java.net

Re: Accessing OSGi Context / Bundles from a standard WAR/EAR/etc in GF v3.0

From: Sahoo <Sahoo_at_Sun.COM>
Date: Wed, 28 Apr 2010 16:35:28 +0530

glassfish_at_javadesktop.org wrote:
>> Here is a sample that shows how to invoke a OSGi
>> service from a JAX-WS
>> endpoint:
>>
>> http://blogs.sun.com/arungupta/entry/totd_130_invoking
>> _a_osgi
>>
>> This is deployed in v3.0.
>>
>> HTH,
>> -Arun
>>
>
> Hello,
>
> thank you for your answer!
>
> In your tutorial you are deploying your war as a web application bundle (so it is a real bundle in terms of a OSGi), because of that you can use all OSGi services... My application uses JSF with custom components, so it does not work in 30 as a WAB, it requires changes available in 3.1 branch. (There is a thread in this forum about this issue...) I have been using nightly build of 3.1 where everything were working correctly.
>
> The release plan of the 3.1 is not yet available (in wiki) and in a real development we cannot rely on a nightly builds for a long time, so I was thinking about some temporary work around, which makes it possible to access OSGi services from a normal WAR, which is deployed as a normal WAR.
>
> BundleContext ctx = BundleReference.class.cast(
> App.class.getClassLoader()).getBundle().getBundleContext();
>
> Maybe if I use instead of App class some system bundle activator class that is already available in GlassFish, then I can get a bundle context of some module bundle and use it? I understand that this is really weird hack..... but anyway it can be used as a temporary work around..
>
One mis-feature of GFv3 is that every app has access to every exported
class. So, you can actually make App.class as part of your own OSGi
bundle and use the above work around to access an OSGi context.

Thanks,
Sahoo