dev@glassfish.java.net

Re: Debugging Dependency Injection in GlassFish

From: Ken Cavanaugh <kencavanaugh_at_me.com>
Date: Tue, 04 Jan 2011 10:57:08 -0800

On 01/ 4/11 10:39 AM, Jerome Dochez wrote:
> On Jan 4, 2011, at 10:25 AM, Ken wrote:
>
>
>> On 01/ 4/11 09:58 AM, Jerome Dochez wrote:
>>
>>> On Jan 4, 2011, at 9:36 AM, Ken wrote:
>>>
>>>
>>>
>>>> I've made a few changes in the FOLB code in glassfish-naming, and now some
>>>> of the surefire tests for naming are failing. The scenario is that SerialInitContextFactory
>>>> needs to call GlassFishORBHelper.getORB(). GlassFishORBHelper is annotated
>>>> with @Service and implements PostConstruct and ORBLocator.
>>>> The PostConstruct method calls
>>>>
>>>> orbFactory = habitat.getByContract( GlassFishORBFactory.class ) ;
>>>>
>>>> where habitat was obtained from @Inject on a field.
>>>> The tests are failing because orbFactory is null.
>>>>
>>>> ORBFactory is an @Contract interface, which is implemented
>>>> by GlassFishORBFactoryImpl, which is a class annotated with @Service.
>>>> GlassFishORBFactoryImpl also implements PostConstruct.
>>>>
>>>> So how do I debug this and figure out why getByContract returned null?
>>>> I haven't changed any of the annotations, so presumably something else is failing,
>>>> but what?
>>>>
>>>> A quick look into getByContract seems to indicate that the byContract MultiList
>>>> does not contain GlassFishORBFactory, but why?
>>>>
>>>>
>>> does it contain anything ?
>>>
>>>
>> Yes, byContract had I think 52 entries in it (just not the one I needed).
>>
> There are 52 implementations of org.glassfish.enterprise.iiop.api.GlassFishORBFactory ?
>
No, there were 52 different services in byContract, none of which were
the one I needed.
>
>>> the first thing I would check is the content in the META-INF/inhabitants/default file in your implementation module.
>>> does the file exist ?
>>> does it have an entry for your GlassFishORBFactoryImpl service ?
>>>
>>>
>> It contains 3 entries, one of which is:
>>
>> class=org.glassfish.enterprise.iiop.impl.GlassFishORBFactoryImpl,index=org.glassfish.enterprise.iiop.api.GlassFishORBFactory
>>
>> which I presume is what is needed there.
>>
> yes.
>
>> Is there some runtime debugging I can do here?
>>
>>
> can you call this method on the habitat and observe the result ?
>
> public Collection<Inhabitant<?>> getAllInhabitantsByContract(String contractType)
>
> in particular do you find an Inhabitant that describe your service ?
>
>
>
>
I added

        Collection<Inhabitant<?>> objs =
             habitat.getAllInhabitantsByContract(
                 GlassFishORBFactory.class.getName() ) ;

and when running the tests, objs is an empty collection.

Ken.