In order to get access to the BundleContext from servlets (in this case Seam, but same thing),
I had to add a static method in org.glassfish.web.DirContextURLStreamHandlerService
called getBundleContext(). I also changed DirContextURLStreamHandlerService to save the
bundlecontext in a static when start(BundleContext context) is executed.
This allow me to load/find dynamic osgi services from my servlets/Seam components, which is
really nice to take full advantage of the glassfish osgi capabilities.
I was also able to restart glassfish, and the LogService did reload automatically and getBundleContext() still worked, did not go stale etc..
example from the servlet side of glassfish:
public void getDeviceList(HttpServletRequest request, HttpServletResponse response)
throws IOException {
LogService ls = null;
BundleContext bc = org.glassfish.web.DirContextURLStreamHandlerService.getBundleContext();
ServiceReference ref = bc.getServiceReference(LogService.class.getName());
if (ref != null) {
ls = (LogService) bc.getService(ref);
ls.log("got the osgi logService bundle, let's log something...");
}...
}
I am thinking there should be a more elegant way to get to the BundleContext from the
glassfish servlets etc..
any idea?
[Message sent by forum member 'christian_cadieux' (christian_cadieux)]
http://forums.java.net/jive/thread.jspa?messageID=318199