users@glassfish.java.net

Re: Glassfishv3 and Tuscany

From: Jerome Dochez <Jerome.Dochez_at_Sun.COM>
Date: Wed, 09 Dec 2009 05:55:02 -0800

Hi Alexander

seems like a bug in our service tracker code, we are not safeguarding against the OSGi ServiceReference returning a null instance when the service is retrieved using the bundle context getService(serviceRef).

I am not sure what might cause this to happen, since a new service is added, I am not sure why its instance is null (maybe you have an idea). In any case, we should protect the code in HK2 to safeguard against that situation.

can you file a bug against hk2 (with steps to reproduce if possible) ?

thx, jerome

On Dec 9, 2009, at 3:52 AM, Alexander Blotny wrote:

> Hi,
>
> I am trying to run the tuscany framework (milestone 4) in the glassfischv3
> web container. So far I managed to start everything without errors or
> exceptions...
>
> Trying some examples for the tuscany framework I run into a NPE:
>
> java.lang.NullPointerException
> at
> com.sun.hk2.component.ExistingSingletonInhabitant.<init>(ExistingSingletonIn
> habitant.java:54)
> at
> org.jvnet.hk2.osgiadapter.HK2Main$HK2ServiceTrackerCustomizer.addingService(
> HK2Main.java:212)
> at
> org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker
> .java:896)
> at
> org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:261)
> at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:233)
> at
> org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.j
> ava:840)
> at
> org.apache.felix.framework.util.EventDispatcher.invokeServiceListenerCallbac
> k(EventDispatcher.java:878)
> at
> org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDi
> spatcher.java:732)
> at
> org.apache.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispat
> cher.java:662)
> at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:3587)
> at org.apache.felix.framework.Felix.access$000(Felix.java:40)
> at org.apache.felix.framework.Felix$1.serviceChanged(Felix.java:625)
> at
> org.apache.felix.framework.ServiceRegistry.registerService(ServiceRegistry.j
> ava:97)
> at org.apache.felix.framework.Felix.registerService(Felix.java:2711)
> at
> org.apache.felix.framework.BundleContextImpl.registerService(BundleContextIm
> pl.java:252)
> at
> org.apache.felix.framework.BundleContextImpl.registerService(BundleContextIm
> pl.java:230)
> at
> org.apache.tuscany.sca.implementation.osgi.runtime.OSGiImplementationProvide
> r$1.run(OSGiImplementationProvider.java:125)
> at
> org.apache.tuscany.sca.implementation.osgi.runtime.OSGiImplementationProvide
> r$1.run(OSGiImplementationProvider.java:1)
> at java.security.AccessController.doPrivileged(Native Method)
> at
> org.apache.tuscany.sca.implementation.osgi.runtime.OSGiImplementationProvide
> r.start(OSGiImplementationProvider.java:120)
> at
> org.apache.tuscany.sca.core.assembly.impl.CompositeActivatorImpl.start(Compo
> siteActivatorImpl.java:510)
> at
> org.apache.tuscany.sca.core.assembly.impl.CompositeActivatorImpl.start(Compo
> siteActivatorImpl.java:475)
> at org.apache.tuscany.sca.node.impl.NodeImpl.start(NodeImpl.java:148)
> at
> org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiServiceImporter.impo
> rtService(OSGiServiceImporter.java:71)
> at
> org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.RemoteServiceAdminImpl.i
> mportService(RemoteServiceAdminImpl.java:265)
> at
> org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.TopologyManagerImpl.impo
> rtService(TopologyManagerImpl.java:369)
> at
> org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.TopologyManagerImpl.endp
> ointAdded(TopologyManagerImpl.java:336)
> at
> org.apache.tuscany.sca.osgi.service.discovery.impl.AbstractDiscoveryService.
> triggerCallbacks(AbstractDiscoveryService.java:197)
> at
> org.apache.tuscany.sca.osgi.service.discovery.impl.AbstractDiscoveryService.
> endpointChanged(AbstractDiscoveryService.java:274)
> at
> org.apache.tuscany.sca.osgi.service.discovery.impl.DomainDiscoveryService.en
> dpointAdded(DomainDiscoveryService.java:90)
> at
> org.apache.tuscany.sca.core.assembly.impl.EndpointRegistryImpl.addEndpoint(E
> ndpointRegistryImpl.java:50)
> at
> org.apache.tuscany.sca.core.assembly.impl.CompositeActivatorImpl.start(Compo
> siteActivatorImpl.java:543)
> at
> org.apache.tuscany.sca.core.assembly.impl.CompositeActivatorImpl.start(Compo
> siteActivatorImpl.java:475)
> at org.apache.tuscany.sca.node.impl.NodeImpl.start(NodeImpl.java:148)
> at
> org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiServiceExporter.expo
> rtService(OSGiServiceExporter.java:96)
> at
> org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.RemoteServiceAdminImpl.e
> xportService(RemoteServiceAdminImpl.java:123)
> at
> org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.TopologyManagerImpl.expo
> rtService(TopologyManagerImpl.java:181)
> at
> org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.TopologyManagerImpl.addi
> ngService(TopologyManagerImpl.java:147)
> at
> org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker
> .java:896)
> at
> org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:261)
> at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:233)
> at
> org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.j
> ava:840)
> at
> org.apache.felix.framework.util.EventDispatcher.invokeServiceListenerCallbac
> k(EventDispatcher.java:878)
> at
> org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDi
> spatcher.java:732)
> at
> org.apache.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispat
> cher.java:662)
> at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:3587)
> at org.apache.felix.framework.Felix.access$000(Felix.java:40)
> at org.apache.felix.framework.Felix$1.serviceChanged(Felix.java:625)
> at
> org.apache.felix.framework.ServiceRegistry.registerService(ServiceRegistry.j
> ava:97)
> at org.apache.felix.framework.Felix.registerService(Felix.java:2711)
> at
> org.apache.felix.framework.BundleContextImpl.registerService(BundleContextIm
> pl.java:252)
> at
> org.apache.felix.framework.BundleContextImpl.registerService(BundleContextIm
> pl.java:230)
> at
> calculator.dosgi.operations.impl.OperationsActivator.start(OperationsActivat
> or.java:68)
> at
> org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.jav
> a:640)
> at org.apache.felix.framework.Felix.activateBundle(Felix.java:1700)
> at org.apache.felix.framework.Felix.startBundle(Felix.java:1622)
> at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:915)
> at
> org.apache.felix.shell.impl.StartCommandImpl.execute(StartCommandImpl.java:1
> 14)
> at
> org.apache.felix.shell.impl.Activator$ShellServiceImpl.executeCommand(Activa
> tor.java:286)
> at org.apache.felix.shell.remote.Shell.run(Shell.java:109)
> at java.lang.Thread.run(Thread.java:637)
>
> I have already posted that problem on the tuscany mailing list and got
> following answer:
>
>> Further investigation shows that GlassFish (HK2) is a bit aggressive to
>> get the service object when the OSGi service is registered. We use a
>> ServiceFactory to create a service proxy for the client bundle that calls
>> BundleContext.getService(ServiceReference ...). As a result, the bundle is
>> the HK2 which doesn't have access to the SCA component business interface.
>> So a null is returned to the getService() call and HK2 doesn't like that.
>>
>> public Object getService(Bundle bundle, ServiceRegistration
>> registration) {
>> Class<?> interfaceClass = null;
>> try {
>> interfaceClass = bundle.loadClass(interfaceName);
>> } catch (ClassNotFoundException e) {
>> return null;
>> }
>> ...
>> }
>>
>> I'm not sure if you should get GlassFish to fix the NPE or we should try
>> to return a non-null dummy object to work around it. My understanding of
>> the OSGi API [1] is that it's possible that getService() returns a null.
>>
>> [1]
>>
> http://www.osgi.org/javadoc/r4v42/org/osgi/framework/BundleContext.html#getServi
> ce(org.osgi.framework.ServiceReference)
>
> Maybe there is a work around for that problem?
>
> Does anyone has experience in combining glassfish and tuscany?
>
> Thanks
> Alex
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>