1 2 Previous Next 19 Replies Latest reply on Jan 17, 2013 6:43 PM by xudong4713 Go to original post
      • 15. Re: Accessing EJB classes from an OSGi Bundle
        thomas.diesler

        If you have stuff you like to contribute (and maintain) you are very welcome. The umbrella project is the home of examples and documentation.

        • 16. Re: Accessing EJB classes from an OSGi Bundle
          ralfoeldi

          The easiest way to access EJB functionality in OSGi Bundles is to register instances as OSGi Services.

           

          {code}

          /**

          * Registers osgi services with the (system) bundle injected by the JEE

          * container.

          *

          * @author Rainer Alföldi

          *

          */

          @Singleton

          @Startup

          public class Init {

            private static Logger LOGGER = Logger.getLogger(Init.class.getName());

           

            @Resource

            private BundleContext _bundleContext;

           

            @Resource

            private XXXResolver _userNameResolver;

           

          ....

           

            @PostConstruct

            private void postConstruct() {

            {

              Dictionary<String, Object> properties = new Hashtable<String, Object>();

           

            _serviceRegs.add(_bundleContext.registerService(

                    UserNameResolver.SERVICE_NAME, _userNameResolver, properties));

            }

           

          ....

           

          {code}

          • 17. Re: Accessing EJB classes from an OSGi Bundle
            xudong4713

            I assume XXXResolver is the same as UserNameResolver, which is the EJB being registered as an OSGi service. What is _serviceRegs? Do I get an instance of it through @Resource?

             

            Thanks

            • 18. Re: Accessing EJB classes from an OSGi Bundle
              ralfoeldi

              Sorry for the late reply.

               

              _serviceRegs is just a Collection of the ServiceRegistrations returned when you register a service.

               

              It is used in

               

                @PreDestroy

                private void preDestroy() {

               

                  LOGGER.log(Level.INFO, "preDestroy()");

               

                  for (ServiceRegistration serviceReg : _serviceRegs) {

                    serviceReg.unregister();

                  }

                }

              • 19. Re: Accessing EJB classes from an OSGi Bundle
                xudong4713

                Thanks Rainer.

                 

                I get a null for _userNameResolver when I deploy Init as a Singleton EJB in JBoss AS 7.1.1.Final. What is your AS version? Or it’s something else?

                        @Resource

                        private XXXResolver _userNameResolver;

                 

                If I change @Resource to @EJB, it complains about "cannot find EJB with interface XXXResolver". Here I made XXXResolver an interface.

                 

                It works if I use JNDI to get hold of EJB XXXResolver. At least it works in a way!

                 

                X

                1 2 Previous Next