-
15. Re: Accessing EJB classes from an OSGi Bundle
thomas.diesler Dec 7, 2012 4:27 AM (in response to jrantav)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 Dec 17, 2012 7:28 AM (in response to jdoble)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 Dec 21, 2012 4:53 PM (in response to ralfoeldi)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 Jan 15, 2013 5:34 AM (in response to xudong4713)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 Jan 17, 2013 6:43 PM (in response to ralfoeldi)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