users@glassfish.java.net

Injected OSGiService in registered servlets

From: Robert Weeks <RWeeks_at_ext-inc.com>
Date: Mon, 25 Apr 2011 08:19:11 -0700

Hello -

I have been trying to utilize the injected osgi service annotations within a servlet that is registered via the http service. I see this is possible within a hybrid web app - but shouldn't this be possible if the servlet is registered via the osgi http service in a bundle?

Say my service is registered in our activator (example):

  context.registerService(SystemManagerService.class.getName(), new SystemManager(), props);

(props does contain the SERVICE_PID for the service).

as well there is a servlet that is registered:

  ... (getting the http service)...
  httpService.registerServlet("/myalias", new MyServlet(), null, null);


and within that servlet (I use the @WebServlet annotations - but don't think they have any merit on registered servlets):

   ...
   public class MyServlet extends HttpServlet {
      ...
      @Inject @OSGiService(dynamic=true,waitTimeout=(30*1000))
      private SystemManagerService sysMgr;

      ...
    }

I don't seem to be able to get the correct reference here at all. It is always null when I try to access it.

Is there something I am missing - or are these not able to be resolved in servlets that are registered via the HTTP Service?

Thanks for any info.




Robert Weeks
Senior Software Developer
EXTENSION, INC.
Email: rweeks_at_ext-inc.com
Office: 260-797-0200 x4228
General: 877-207-3753
www.OpenTheRedBox.com

Download the FREE EXTENSION Mobile App for iPhone and iPod Touch
http://www.opentheredbox.com/iPhone_appDemo.php