You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@openwebbeans.apache.org by Mike Olson <mo...@the-olsons.net> on 2012/12/27 21:56:28 UTC
Re: OWB 1.7 ignores Alternative when using the provider interface
On 12/27/2012 3:35 AM, Mark Struberg wrote:
Hi Mark,
> Hi Mike!
>
> Thanks for your great tests, always good to get such feedback!
>
> I guess you get a Instance<Foo> as Provider, right?
Yes, that is what I am seeing.
> In that case 5.2.1 defines that we need to take the Alternative into account and filter it away.
Any thoughts on a work around until this can be fixed? I need to use
the Provider interface to decouple my implementation. I have a Mock
version of "Foo" in my unit tests, qualified as an Alternative (and
noted in the beans.xml file).
Thanks
Mike
> LieGrue,
> strub
>
>
>
>
> ----- Original Message -----
>> From: Mike Olson <mo...@the-olsons.net>
>> To: user@openwebbeans.apache.org
>> Cc:
>> Sent: Thursday, December 27, 2012 5:18 AM
>> Subject: OWN 1.7 ignores Alternative when using the provider interface
>>
>>
>> Hello,
>>
>> I have a very simple setup where I have classes Foo1 and Foo2 that implement
>> the Foo interface
>>
>> public interface Foo {
>> }
>> @Default
>> public class Foo1 implements Foo {
>>
>> }
>> @Alternative
>> public class Foo2 implements Foo {
>>
>> }
>>
>> Then a class that gets 2 Foos injected
>>
>> public class Main {
>>
>> @Inject
>> Foo fooA;
>>
>> @Inject
>> Provider<Foo> fooB;
>>
>> @PostConstruct
>> public void init() {
>> System.err.println("FooA:" + fooA);
>> System.err.println("FooB:" + fooB.get());
>> }
>> }
>>
>> If my beans.xml file is empty, then I get 2 instances of Foo1 injected into the
>> class, as expected.
>>
>> However, if I add
>>
>> <alternatives>
>> <class>Foo2</class>
>> </alternatives>
>>
>> to my beans.xml, then I get an error when I run the application.
>>
>> """
>> INFO: All injection points were validated successfully.
>> Dec 26, 2012 9:11:29 PM org.apache.webbeans.lifecycle.AbstractLifeCycle
>> startApplication
>> INFO: OpenWebBeans Container has started, it took [359] ms.
>> FooA:Foo2@152c4d9
>> Dec 26, 2012 9:11:29 PM
>> org.apache.webbeans.component.AbstractInjectionTargetBean postConstructDefault
>> SEVERE: An error occurred while executing [@PostConstruct.]
>> javax.enterprise.inject.AmbiguousResolutionException: There is more than one api
>> type with : Foo with qualifiers : Qualifiers:
>> [@javax.enterprise.inject.Default()]
>> found beans:
>> Foo1, Name:null, WebBeans Type:MANAGED, API Types:[Foo,Foo1,java.lang.Object],
>> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
>> Foo2, Name:null, WebBeans Type:MANAGED, API Types:[Foo,java.lang.Object,Foo2],
>> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
>> at
>> org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionExceptionForBeans(InjectionExceptionUtils.java:121)
>> at
>> org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionException(InjectionExceptionUtils.java:111)
>> at
>> org.apache.webbeans.container.ResolutionUtil.checkResolvedBeans(ResolutionUtil.java:80)
>> at
>> org.apache.webbeans.inject.instance.InstanceImpl.get(InstanceImpl.java:110)
>> at Main.init(Main.java:23)
>> """
>>
>> This exception happens when I call Provider.get(). I assumed that the Provider
>> interface would respect the Alternative Qualifiers, but that does not seem to be
>> the case.
>>
>> Is this a bug in what I am doing, or a bug in OWB?
>>
>> Thanks
>> Mike
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> -- Mike Olson
>>
--
Mike Olson
Re: OWB 1.7 ignores Alternative when using the provider interface
Posted by Mike Olson <mo...@the-olsons.net>.
On 12/27/2012 2:57 PM, Mark Struberg wrote:
A JIRA with my example code has been created here
https://issues.apache.org/jira/browse/OWB-742
Thanks
Mike
> Or we just gonna fix this issue and ship owb-1.8 :)
>
> Can you please create a patch with a small test case and attach it to a JIRA, please?
>
>
> txs and LieGrue,
> strub
>
>
>
> ----- Original Message -----
>> From: Mike Olson <mo...@the-olsons.net>
>> To: user@openwebbeans.apache.org
>> Cc:
>> Sent: Thursday, December 27, 2012 10:55 PM
>> Subject: Re: OWB 1.7 ignores Alternative when using the provider interface
>>
>> On 12/27/2012 2:43 PM, Mark Struberg wrote:
>>
>> It does, but I can't use @Inject in this case. I cannot statically bind
>> to a single instance of Foo.
>>
>> I suppose I could create a FooWrapper class.
>>
>> class FooWrapper {
>> @Inject Foo foo;
>> }
>>
>> Then in Main use:
>>
>> @Inject
>> Provider<FooWrapper> fooWrapperProvider;
>>
>>
>> Mike
>>
>>> And simply @Inject doesn't work?
>>>
>>> LieGrue,
>>> strub
>>>
>>>
>>>
>>>
>>> ----- Original Message -----
>>>> From: Mike Olson <mo...@the-olsons.net>
>>>> To: user@openwebbeans.apache.org
>>>> Cc:
>>>> Sent: Thursday, December 27, 2012 9:56 PM
>>>> Subject: Re: OWB 1.7 ignores Alternative when using the provider
>> interface
>>>> On 12/27/2012 3:35 AM, Mark Struberg wrote:
>>>>
>>>> Hi Mark,
>>>>
>>>>> Hi Mike!
>>>>>
>>>>> Thanks for your great tests, always good to get such feedback!
>>>>>
>>>>> I guess you get a Instance<Foo> as Provider, right?
>>>> Yes, that is what I am seeing.
>>>>
>>>>> In that case 5.2.1 defines that we need to take the Alternative
>> into
>>>> account and filter it away.
>>>>
>>>> Any thoughts on a work around until this can be fixed? I need to use
>>>> the Provider interface to decouple my implementation. I have a Mock
>>>> version of "Foo" in my unit tests, qualified as an
>> Alternative (and
>>>> noted in the beans.xml file).
>>>>
>>>> Thanks
>>>> Mike
>>>>
>>>>> LieGrue,
>>>>> strub
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> ----- Original Message -----
>>>>>> From: Mike Olson <mo...@the-olsons.net>
>>>>>> To: user@openwebbeans.apache.org
>>>>>> Cc:
>>>>>> Sent: Thursday, December 27, 2012 5:18 AM
>>>>>> Subject: OWN 1.7 ignores Alternative when using the provider
>> interface
>>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> I have a very simple setup where I have classes Foo1 and
>> Foo2 that
>>>> implement
>>>>>> the Foo interface
>>>>>>
>>>>>> public interface Foo {
>>>>>> }
>>>>>> @Default
>>>>>> public class Foo1 implements Foo {
>>>>>>
>>>>>> }
>>>>>> @Alternative
>>>>>> public class Foo2 implements Foo {
>>>>>>
>>>>>> }
>>>>>>
>>>>>> Then a class that gets 2 Foos injected
>>>>>>
>>>>>> public class Main {
>>>>>>
>>>>>> @Inject
>>>>>> Foo fooA;
>>>>>>
>>>>>> @Inject
>>>>>> Provider<Foo> fooB;
>>>>>>
>>>>>> @PostConstruct
>>>>>> public void init() {
>>>>>> System.err.println("FooA:" + fooA);
>>>>>> System.err.println("FooB:" + fooB.get());
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> If my beans.xml file is empty, then I get 2 instances of Foo1
>> injected
>>>> into the
>>>>>> class, as expected.
>>>>>>
>>>>>> However, if I add
>>>>>>
>>>>>> <alternatives>
>>>>>> <class>Foo2</class>
>>>>>> </alternatives>
>>>>>>
>>>>>> to my beans.xml, then I get an error when I run the
>> application.
>>>>>> """
>>>>>> INFO: All injection points were validated successfully.
>>>>>> Dec 26, 2012 9:11:29 PM
>> org.apache.webbeans.lifecycle.AbstractLifeCycle
>>>>>> startApplication
>>>>>> INFO: OpenWebBeans Container has started, it took [359] ms.
>>>>>> FooA:Foo2@152c4d9
>>>>>> Dec 26, 2012 9:11:29 PM
>>>>>> org.apache.webbeans.component.AbstractInjectionTargetBean
>>>> postConstructDefault
>>>>>> SEVERE: An error occurred while executing [@PostConstruct.]
>>>>>> javax.enterprise.inject.AmbiguousResolutionException: There
>> is more
>>>> than one api
>>>>>> type with : Foo with qualifiers : Qualifiers:
>>>>>> [@javax.enterprise.inject.Default()]
>>>>>> found beans:
>>>>>> Foo1, Name:null, WebBeans Type:MANAGED, API
>>>> Types:[Foo,Foo1,java.lang.Object],
>>>>
>> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
>>>>>> Foo2, Name:null, WebBeans Type:MANAGED, API
>>>> Types:[Foo,java.lang.Object,Foo2],
>>>>
>> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
>>>>>> at
>>>>>>
>> org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionExceptionForBeans(InjectionExceptionUtils.java:121)
>>>>>> at
>>>>>>
>> org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionException(InjectionExceptionUtils.java:111)
>>>>>> at
>>>>>>
>> org.apache.webbeans.container.ResolutionUtil.checkResolvedBeans(ResolutionUtil.java:80)
>>>>>> at
>>>>>>
>> org.apache.webbeans.inject.instance.InstanceImpl.get(InstanceImpl.java:110)
>>>>>> at Main.init(Main.java:23)
>>>>>> """
>>>>>>
>>>>>> This exception happens when I call Provider.get(). I assumed
>> that the
>>>> Provider
>>>>>> interface would respect the Alternative Qualifiers, but that
>> does not
>>>> seem to be
>>>>>> the case.
>>>>>>
>>>>>> Is this a bug in what I am doing, or a bug in OWB?
>>>>>>
>>>>>> Thanks
>>>>>> Mike
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> -- Mike Olson
>>>>>>
>>>> --
>>>> Mike Olson
>>>>
>>
>> --
>> Mike Olson
>>
--
Mike Olson
Re: OWB 1.7 ignores Alternative when using the provider interface
Posted by Arne Limburg <ar...@openknowledge.de>.
Yes, I take it.
Will fix it this evening,
Cheers,
Arne
Am 27.12.12 23:22 schrieb "Mark Struberg" unter <st...@yahoo.de>:
>Hi Arne, yes that sounds very reasonable!
>Do you like to take over?
>
>LIeGrue,
>strub
>
>
>
>
>----- Original Message -----
>> From: Arne Limburg <ar...@openknowledge.de>
>> To: "user@openwebbeans.apache.org" <us...@openwebbeans.apache.org>
>> Cc:
>> Sent: Thursday, December 27, 2012 11:14 PM
>> Subject: Re: OWB 1.7 ignores Alternative when using the provider
>>interface
>>
>> Hi Mark,
>>
>> I already looked into it, seems like the InstanceImpl only does an
>> InjectionResolver.implResolveByType which is equivalent to
>> BeanManager.getBeans() and simply misses the InjectionResolver.resolve
>> (wich is BeanManager.resolve).
>>
>> Mike, a test-case implemented within the owb test-suite would be very
>>cool
>>
>> Cheers,
>> Arne
>>
>>
>>
>> Am 27.12.12 23:01 schrieb "Mike Olson" unter
>> <mo...@the-olsons.net>:
>>
>>> On 12/27/2012 2:57 PM, Mark Struberg wrote:
>>>
>>>
>>> FYI, that did work.
>>>
>>>> Or we just gonna fix this issue and ship owb-1.8 :)
>>> That would be ideal :)
>>>>
>>>> Can you please create a patch with a small test case and attach it
>>>>to a
>>>> JIRA, please?
>>>
>>> Just the Foo classes as the test case?
>>>
>>> Thanks
>>> Mike
>>>
>>>>
>>>>
>>>> txs and LieGrue,
>>>> strub
>>>>
>>>>
>>>>
>>>> ----- Original Message -----
>>>>> From: Mike Olson <mo...@the-olsons.net>
>>>>> To: user@openwebbeans.apache.org
>>>>> Cc:
>>>>> Sent: Thursday, December 27, 2012 10:55 PM
>>>>> Subject: Re: OWB 1.7 ignores Alternative when using the provider
>>>>> interface
>>>>>
>>>>> On 12/27/2012 2:43 PM, Mark Struberg wrote:
>>>>>
>>>>> It does, but I can't use @Inject in this case. I cannot
>> statically
>>>>> bind
>>>>> to a single instance of Foo.
>>>>>
>>>>> I suppose I could create a FooWrapper class.
>>>>>
>>>>> class FooWrapper {
>>>>> @Inject Foo foo;
>>>>> }
>>>>>
>>>>> Then in Main use:
>>>>>
>>>>> @Inject
>>>>> Provider<FooWrapper> fooWrapperProvider;
>>>>>
>>>>>
>>>>> Mike
>>>>>
>>>>>> And simply @Inject doesn't work?
>>>>>>
>>>>>> LieGrue,
>>>>>> strub
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> ----- Original Message -----
>>>>>>> From: Mike Olson <mo...@the-olsons.net>
>>>>>>> To: user@openwebbeans.apache.org
>>>>>>> Cc:
>>>>>>> Sent: Thursday, December 27, 2012 9:56 PM
>>>>>>> Subject: Re: OWB 1.7 ignores Alternative when using the
>> provider
>>>>> interface
>>>>>>> On 12/27/2012 3:35 AM, Mark Struberg wrote:
>>>>>>>
>>>>>>> Hi Mark,
>>>>>>>
>>>>>>>> Hi Mike!
>>>>>>>>
>>>>>>>> Thanks for your great tests, always good to get
>> such feedback!
>>>>>>>>
>>>>>>>> I guess you get a Instance<Foo> as Provider,
>> right?
>>>>>>> Yes, that is what I am seeing.
>>>>>>>
>>>>>>>> In that case 5.2.1 defines that we need to take the
>> Alternative
>>>>> into
>>>>>>> account and filter it away.
>>>>>>>
>>>>>>> Any thoughts on a work around until this can be fixed? I
>> need to
>>>>>>> use
>>>>>>> the Provider interface to decouple my implementation. I
>> have a
>>>>>>> Mock
>>>>>>> version of "Foo" in my unit tests, qualified as
>> an
>>>>> Alternative (and
>>>>>>> noted in the beans.xml file).
>>>>>>>
>>>>>>> Thanks
>>>>>>> Mike
>>>>>>>
>>>>>>>> LieGrue,
>>>>>>>> strub
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> ----- Original Message -----
>>>>>>>>> From: Mike Olson <mo...@the-olsons.net>
>>>>>>>>> To: user@openwebbeans.apache.org
>>>>>>>>> Cc:
>>>>>>>>> Sent: Thursday, December 27, 2012 5:18 AM
>>>>>>>>> Subject: OWN 1.7 ignores Alternative when using
>> the provider
>>>>> interface
>>>>>>>>>
>>>>>>>>> Hello,
>>>>>>>>>
>>>>>>>>> I have a very simple setup where I have
>> classes Foo1 and
>>>>> Foo2 that
>>>>>>> implement
>>>>>>>>> the Foo interface
>>>>>>>>>
>>>>>>>>> public interface Foo {
>>>>>>>>> }
>>>>>>>>> @Default
>>>>>>>>> public class Foo1 implements Foo {
>>>>>>>>>
>>>>>>>>> }
>>>>>>>>> @Alternative
>>>>>>>>> public class Foo2 implements Foo {
>>>>>>>>>
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> Then a class that gets 2 Foos injected
>>>>>>>>>
>>>>>>>>> public class Main {
>>>>>>>>>
>>>>>>>>> @Inject
>>>>>>>>> Foo fooA;
>>>>>>>>>
>>>>>>>>> @Inject
>>>>>>>>> Provider<Foo> fooB;
>>>>>>>>>
>>>>>>>>> @PostConstruct
>>>>>>>>> public void init() {
>>>>>>>>> System.err.println("FooA:" +
>> fooA);
>>>>>>>>> System.err.println("FooB:" +
>> fooB.get());
>>>>>>>>> }
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> If my beans.xml file is empty, then I get 2
>> instances of Foo1
>>>>> injected
>>>>>>> into the
>>>>>>>>> class, as expected.
>>>>>>>>>
>>>>>>>>> However, if I add
>>>>>>>>>
>>>>>>>>> <alternatives>
>>>>>>>>> <class>Foo2</class>
>>>>>>>>> </alternatives>
>>>>>>>>>
>>>>>>>>> to my beans.xml, then I get an error when I run
>> the
>>>>> application.
>>>>>>>>> """
>>>>>>>>> INFO: All injection points were validated
>> successfully.
>>>>>>>>> Dec 26, 2012 9:11:29 PM
>>>>> org.apache.webbeans.lifecycle.AbstractLifeCycle
>>>>>>>>> startApplication
>>>>>>>>> INFO: OpenWebBeans Container has started, it
>> took [359] ms.
>>>>>>>>> FooA:Foo2@152c4d9
>>>>>>>>> Dec 26, 2012 9:11:29 PM
>>>>>>>>>
>> org.apache.webbeans.component.AbstractInjectionTargetBean
>>>>>>> postConstructDefault
>>>>>>>>> SEVERE: An error occurred while executing
>> [@PostConstruct.]
>>>>>>>>>
>> javax.enterprise.inject.AmbiguousResolutionException: There
>>>>> is more
>>>>>>> than one api
>>>>>>>>> type with : Foo with qualifiers : Qualifiers:
>>>>>>>>> [@javax.enterprise.inject.Default()]
>>>>>>>>> found beans:
>>>>>>>>> Foo1, Name:null, WebBeans Type:MANAGED, API
>>>>>>> Types:[Foo,Foo1,java.lang.Object],
>>>>>>>
>>>>>
>>>>>
>>>>>Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Defaul
>>>>>t]
>>>>>>>>> Foo2, Name:null, WebBeans Type:MANAGED, API
>>>>>>> Types:[Foo,java.lang.Object,Foo2],
>>>>>>>
>>>>>
>>>>>
>>>>>Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Defaul
>>>>>t]
>>>>>>>>> at
>>>>>>>>>
>>>>>
>>>>>
>>>>>org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolut
>>>>>io
>>>>> nExceptionForBeans(InjectionExceptionUtils.java:121)
>>>>>>>>> at
>>>>>>>>>
>>>>>
>>>>>
>>>>>org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolut
>>>>>io
>>>>> nException(InjectionExceptionUtils.java:111)
>>>>>>>>> at
>>>>>>>>>
>>>>>
>>>>>
>>>>>org.apache.webbeans.container.ResolutionUtil.checkResolvedBeans(Resolu
>>>>>ti
>>>>> onUtil.java:80)
>>>>>>>>> at
>>>>>>>>>
>>>>>
>>>>>
>>>>>org.apache.webbeans.inject.instance.InstanceImpl.get(InstanceImpl.java
>>>>>:1
>>>>> 10)
>>>>>>>>> at Main.init(Main.java:23)
>>>>>>>>> """
>>>>>>>>>
>>>>>>>>> This exception happens when I call
>> Provider.get(). I assumed
>>>>> that the
>>>>>>> Provider
>>>>>>>>> interface would respect the Alternative
>> Qualifiers, but that
>>>>> does not
>>>>>>> seem to be
>>>>>>>>> the case.
>>>>>>>>>
>>>>>>>>> Is this a bug in what I am doing, or a bug in
>> OWB?
>>>>>>>>>
>>>>>>>>> Thanks
>>>>>>>>> Mike
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> -- Mike Olson
>>>>>>>>>
>>>>>>> --
>>>>>>> Mike Olson
>>>>>>>
>>>>>
>>>>> --
>>>>> Mike Olson
>>>>>
>>>
>>>
>>> --
>>> Mike Olson
>>>
>>
Re: OWB 1.7 ignores Alternative when using the provider interface
Posted by Mark Struberg <st...@yahoo.de>.
Hi Arne, yes that sounds very reasonable!
Do you like to take over?
LIeGrue,
strub
----- Original Message -----
> From: Arne Limburg <ar...@openknowledge.de>
> To: "user@openwebbeans.apache.org" <us...@openwebbeans.apache.org>
> Cc:
> Sent: Thursday, December 27, 2012 11:14 PM
> Subject: Re: OWB 1.7 ignores Alternative when using the provider interface
>
> Hi Mark,
>
> I already looked into it, seems like the InstanceImpl only does an
> InjectionResolver.implResolveByType which is equivalent to
> BeanManager.getBeans() and simply misses the InjectionResolver.resolve
> (wich is BeanManager.resolve).
>
> Mike, a test-case implemented within the owb test-suite would be very cool
>
> Cheers,
> Arne
>
>
>
> Am 27.12.12 23:01 schrieb "Mike Olson" unter
> <mo...@the-olsons.net>:
>
>> On 12/27/2012 2:57 PM, Mark Struberg wrote:
>>
>>
>> FYI, that did work.
>>
>>> Or we just gonna fix this issue and ship owb-1.8 :)
>> That would be ideal :)
>>>
>>> Can you please create a patch with a small test case and attach it to a
>>> JIRA, please?
>>
>> Just the Foo classes as the test case?
>>
>> Thanks
>> Mike
>>
>>>
>>>
>>> txs and LieGrue,
>>> strub
>>>
>>>
>>>
>>> ----- Original Message -----
>>>> From: Mike Olson <mo...@the-olsons.net>
>>>> To: user@openwebbeans.apache.org
>>>> Cc:
>>>> Sent: Thursday, December 27, 2012 10:55 PM
>>>> Subject: Re: OWB 1.7 ignores Alternative when using the provider
>>>> interface
>>>>
>>>> On 12/27/2012 2:43 PM, Mark Struberg wrote:
>>>>
>>>> It does, but I can't use @Inject in this case. I cannot
> statically
>>>> bind
>>>> to a single instance of Foo.
>>>>
>>>> I suppose I could create a FooWrapper class.
>>>>
>>>> class FooWrapper {
>>>> @Inject Foo foo;
>>>> }
>>>>
>>>> Then in Main use:
>>>>
>>>> @Inject
>>>> Provider<FooWrapper> fooWrapperProvider;
>>>>
>>>>
>>>> Mike
>>>>
>>>>> And simply @Inject doesn't work?
>>>>>
>>>>> LieGrue,
>>>>> strub
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> ----- Original Message -----
>>>>>> From: Mike Olson <mo...@the-olsons.net>
>>>>>> To: user@openwebbeans.apache.org
>>>>>> Cc:
>>>>>> Sent: Thursday, December 27, 2012 9:56 PM
>>>>>> Subject: Re: OWB 1.7 ignores Alternative when using the
> provider
>>>> interface
>>>>>> On 12/27/2012 3:35 AM, Mark Struberg wrote:
>>>>>>
>>>>>> Hi Mark,
>>>>>>
>>>>>>> Hi Mike!
>>>>>>>
>>>>>>> Thanks for your great tests, always good to get
> such feedback!
>>>>>>>
>>>>>>> I guess you get a Instance<Foo> as Provider,
> right?
>>>>>> Yes, that is what I am seeing.
>>>>>>
>>>>>>> In that case 5.2.1 defines that we need to take the
> Alternative
>>>> into
>>>>>> account and filter it away.
>>>>>>
>>>>>> Any thoughts on a work around until this can be fixed? I
> need to
>>>>>> use
>>>>>> the Provider interface to decouple my implementation. I
> have a
>>>>>> Mock
>>>>>> version of "Foo" in my unit tests, qualified as
> an
>>>> Alternative (and
>>>>>> noted in the beans.xml file).
>>>>>>
>>>>>> Thanks
>>>>>> Mike
>>>>>>
>>>>>>> LieGrue,
>>>>>>> strub
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> ----- Original Message -----
>>>>>>>> From: Mike Olson <mo...@the-olsons.net>
>>>>>>>> To: user@openwebbeans.apache.org
>>>>>>>> Cc:
>>>>>>>> Sent: Thursday, December 27, 2012 5:18 AM
>>>>>>>> Subject: OWN 1.7 ignores Alternative when using
> the provider
>>>> interface
>>>>>>>>
>>>>>>>> Hello,
>>>>>>>>
>>>>>>>> I have a very simple setup where I have
> classes Foo1 and
>>>> Foo2 that
>>>>>> implement
>>>>>>>> the Foo interface
>>>>>>>>
>>>>>>>> public interface Foo {
>>>>>>>> }
>>>>>>>> @Default
>>>>>>>> public class Foo1 implements Foo {
>>>>>>>>
>>>>>>>> }
>>>>>>>> @Alternative
>>>>>>>> public class Foo2 implements Foo {
>>>>>>>>
>>>>>>>> }
>>>>>>>>
>>>>>>>> Then a class that gets 2 Foos injected
>>>>>>>>
>>>>>>>> public class Main {
>>>>>>>>
>>>>>>>> @Inject
>>>>>>>> Foo fooA;
>>>>>>>>
>>>>>>>> @Inject
>>>>>>>> Provider<Foo> fooB;
>>>>>>>>
>>>>>>>> @PostConstruct
>>>>>>>> public void init() {
>>>>>>>> System.err.println("FooA:" +
> fooA);
>>>>>>>> System.err.println("FooB:" +
> fooB.get());
>>>>>>>> }
>>>>>>>> }
>>>>>>>>
>>>>>>>> If my beans.xml file is empty, then I get 2
> instances of Foo1
>>>> injected
>>>>>> into the
>>>>>>>> class, as expected.
>>>>>>>>
>>>>>>>> However, if I add
>>>>>>>>
>>>>>>>> <alternatives>
>>>>>>>> <class>Foo2</class>
>>>>>>>> </alternatives>
>>>>>>>>
>>>>>>>> to my beans.xml, then I get an error when I run
> the
>>>> application.
>>>>>>>> """
>>>>>>>> INFO: All injection points were validated
> successfully.
>>>>>>>> Dec 26, 2012 9:11:29 PM
>>>> org.apache.webbeans.lifecycle.AbstractLifeCycle
>>>>>>>> startApplication
>>>>>>>> INFO: OpenWebBeans Container has started, it
> took [359] ms.
>>>>>>>> FooA:Foo2@152c4d9
>>>>>>>> Dec 26, 2012 9:11:29 PM
>>>>>>>>
> org.apache.webbeans.component.AbstractInjectionTargetBean
>>>>>> postConstructDefault
>>>>>>>> SEVERE: An error occurred while executing
> [@PostConstruct.]
>>>>>>>>
> javax.enterprise.inject.AmbiguousResolutionException: There
>>>> is more
>>>>>> than one api
>>>>>>>> type with : Foo with qualifiers : Qualifiers:
>>>>>>>> [@javax.enterprise.inject.Default()]
>>>>>>>> found beans:
>>>>>>>> Foo1, Name:null, WebBeans Type:MANAGED, API
>>>>>> Types:[Foo,Foo1,java.lang.Object],
>>>>>>
>>>>
>>>> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
>>>>>>>> Foo2, Name:null, WebBeans Type:MANAGED, API
>>>>>> Types:[Foo,java.lang.Object,Foo2],
>>>>>>
>>>>
>>>> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
>>>>>>>> at
>>>>>>>>
>>>>
>>>> org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutio
>>>> nExceptionForBeans(InjectionExceptionUtils.java:121)
>>>>>>>> at
>>>>>>>>
>>>>
>>>> org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutio
>>>> nException(InjectionExceptionUtils.java:111)
>>>>>>>> at
>>>>>>>>
>>>>
>>>> org.apache.webbeans.container.ResolutionUtil.checkResolvedBeans(Resoluti
>>>> onUtil.java:80)
>>>>>>>> at
>>>>>>>>
>>>>
>>>> org.apache.webbeans.inject.instance.InstanceImpl.get(InstanceImpl.java:1
>>>> 10)
>>>>>>>> at Main.init(Main.java:23)
>>>>>>>> """
>>>>>>>>
>>>>>>>> This exception happens when I call
> Provider.get(). I assumed
>>>> that the
>>>>>> Provider
>>>>>>>> interface would respect the Alternative
> Qualifiers, but that
>>>> does not
>>>>>> seem to be
>>>>>>>> the case.
>>>>>>>>
>>>>>>>> Is this a bug in what I am doing, or a bug in
> OWB?
>>>>>>>>
>>>>>>>> Thanks
>>>>>>>> Mike
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> -- Mike Olson
>>>>>>>>
>>>>>> --
>>>>>> Mike Olson
>>>>>>
>>>>
>>>> --
>>>> Mike Olson
>>>>
>>
>>
>> --
>> Mike Olson
>>
>
Re: OWB 1.7 ignores Alternative when using the provider interface
Posted by Arne Limburg <ar...@openknowledge.de>.
Hi Mark,
I already looked into it, seems like the InstanceImpl only does an
InjectionResolver.implResolveByType which is equivalent to
BeanManager.getBeans() and simply misses the InjectionResolver.resolve
(wich is BeanManager.resolve).
Mike, a test-case implemented within the owb test-suite would be very cool
Cheers,
Arne
Am 27.12.12 23:01 schrieb "Mike Olson" unter <mo...@the-olsons.net>:
>On 12/27/2012 2:57 PM, Mark Struberg wrote:
>
>
>FYI, that did work.
>
>> Or we just gonna fix this issue and ship owb-1.8 :)
>That would be ideal :)
>>
>> Can you please create a patch with a small test case and attach it to a
>>JIRA, please?
>
>Just the Foo classes as the test case?
>
>Thanks
>Mike
>
>>
>>
>> txs and LieGrue,
>> strub
>>
>>
>>
>> ----- Original Message -----
>>> From: Mike Olson <mo...@the-olsons.net>
>>> To: user@openwebbeans.apache.org
>>> Cc:
>>> Sent: Thursday, December 27, 2012 10:55 PM
>>> Subject: Re: OWB 1.7 ignores Alternative when using the provider
>>>interface
>>>
>>> On 12/27/2012 2:43 PM, Mark Struberg wrote:
>>>
>>> It does, but I can't use @Inject in this case. I cannot statically
>>>bind
>>> to a single instance of Foo.
>>>
>>> I suppose I could create a FooWrapper class.
>>>
>>> class FooWrapper {
>>> @Inject Foo foo;
>>> }
>>>
>>> Then in Main use:
>>>
>>> @Inject
>>> Provider<FooWrapper> fooWrapperProvider;
>>>
>>>
>>> Mike
>>>
>>>> And simply @Inject doesn't work?
>>>>
>>>> LieGrue,
>>>> strub
>>>>
>>>>
>>>>
>>>>
>>>> ----- Original Message -----
>>>>> From: Mike Olson <mo...@the-olsons.net>
>>>>> To: user@openwebbeans.apache.org
>>>>> Cc:
>>>>> Sent: Thursday, December 27, 2012 9:56 PM
>>>>> Subject: Re: OWB 1.7 ignores Alternative when using the provider
>>> interface
>>>>> On 12/27/2012 3:35 AM, Mark Struberg wrote:
>>>>>
>>>>> Hi Mark,
>>>>>
>>>>>> Hi Mike!
>>>>>>
>>>>>> Thanks for your great tests, always good to get such feedback!
>>>>>>
>>>>>> I guess you get a Instance<Foo> as Provider, right?
>>>>> Yes, that is what I am seeing.
>>>>>
>>>>>> In that case 5.2.1 defines that we need to take the Alternative
>>> into
>>>>> account and filter it away.
>>>>>
>>>>> Any thoughts on a work around until this can be fixed? I need to
>>>>>use
>>>>> the Provider interface to decouple my implementation. I have a
>>>>>Mock
>>>>> version of "Foo" in my unit tests, qualified as an
>>> Alternative (and
>>>>> noted in the beans.xml file).
>>>>>
>>>>> Thanks
>>>>> Mike
>>>>>
>>>>>> LieGrue,
>>>>>> strub
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> ----- Original Message -----
>>>>>>> From: Mike Olson <mo...@the-olsons.net>
>>>>>>> To: user@openwebbeans.apache.org
>>>>>>> Cc:
>>>>>>> Sent: Thursday, December 27, 2012 5:18 AM
>>>>>>> Subject: OWN 1.7 ignores Alternative when using the provider
>>> interface
>>>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> I have a very simple setup where I have classes Foo1 and
>>> Foo2 that
>>>>> implement
>>>>>>> the Foo interface
>>>>>>>
>>>>>>> public interface Foo {
>>>>>>> }
>>>>>>> @Default
>>>>>>> public class Foo1 implements Foo {
>>>>>>>
>>>>>>> }
>>>>>>> @Alternative
>>>>>>> public class Foo2 implements Foo {
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>> Then a class that gets 2 Foos injected
>>>>>>>
>>>>>>> public class Main {
>>>>>>>
>>>>>>> @Inject
>>>>>>> Foo fooA;
>>>>>>>
>>>>>>> @Inject
>>>>>>> Provider<Foo> fooB;
>>>>>>>
>>>>>>> @PostConstruct
>>>>>>> public void init() {
>>>>>>> System.err.println("FooA:" + fooA);
>>>>>>> System.err.println("FooB:" + fooB.get());
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> If my beans.xml file is empty, then I get 2 instances of Foo1
>>> injected
>>>>> into the
>>>>>>> class, as expected.
>>>>>>>
>>>>>>> However, if I add
>>>>>>>
>>>>>>> <alternatives>
>>>>>>> <class>Foo2</class>
>>>>>>> </alternatives>
>>>>>>>
>>>>>>> to my beans.xml, then I get an error when I run the
>>> application.
>>>>>>> """
>>>>>>> INFO: All injection points were validated successfully.
>>>>>>> Dec 26, 2012 9:11:29 PM
>>> org.apache.webbeans.lifecycle.AbstractLifeCycle
>>>>>>> startApplication
>>>>>>> INFO: OpenWebBeans Container has started, it took [359] ms.
>>>>>>> FooA:Foo2@152c4d9
>>>>>>> Dec 26, 2012 9:11:29 PM
>>>>>>> org.apache.webbeans.component.AbstractInjectionTargetBean
>>>>> postConstructDefault
>>>>>>> SEVERE: An error occurred while executing [@PostConstruct.]
>>>>>>> javax.enterprise.inject.AmbiguousResolutionException: There
>>> is more
>>>>> than one api
>>>>>>> type with : Foo with qualifiers : Qualifiers:
>>>>>>> [@javax.enterprise.inject.Default()]
>>>>>>> found beans:
>>>>>>> Foo1, Name:null, WebBeans Type:MANAGED, API
>>>>> Types:[Foo,Foo1,java.lang.Object],
>>>>>
>>>
>>>Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
>>>>>>> Foo2, Name:null, WebBeans Type:MANAGED, API
>>>>> Types:[Foo,java.lang.Object,Foo2],
>>>>>
>>>
>>>Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
>>>>>>> at
>>>>>>>
>>>
>>>org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutio
>>>nExceptionForBeans(InjectionExceptionUtils.java:121)
>>>>>>> at
>>>>>>>
>>>
>>>org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutio
>>>nException(InjectionExceptionUtils.java:111)
>>>>>>> at
>>>>>>>
>>>
>>>org.apache.webbeans.container.ResolutionUtil.checkResolvedBeans(Resoluti
>>>onUtil.java:80)
>>>>>>> at
>>>>>>>
>>>
>>>org.apache.webbeans.inject.instance.InstanceImpl.get(InstanceImpl.java:1
>>>10)
>>>>>>> at Main.init(Main.java:23)
>>>>>>> """
>>>>>>>
>>>>>>> This exception happens when I call Provider.get(). I assumed
>>> that the
>>>>> Provider
>>>>>>> interface would respect the Alternative Qualifiers, but that
>>> does not
>>>>> seem to be
>>>>>>> the case.
>>>>>>>
>>>>>>> Is this a bug in what I am doing, or a bug in OWB?
>>>>>>>
>>>>>>> Thanks
>>>>>>> Mike
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> -- Mike Olson
>>>>>>>
>>>>> --
>>>>> Mike Olson
>>>>>
>>>
>>> --
>>> Mike Olson
>>>
>
>
>--
>Mike Olson
>
Re: OWB 1.7 ignores Alternative when using the provider interface
Posted by Mike Olson <mo...@the-olsons.net>.
On 12/27/2012 2:57 PM, Mark Struberg wrote:
FYI, that did work.
> Or we just gonna fix this issue and ship owb-1.8 :)
That would be ideal :)
>
> Can you please create a patch with a small test case and attach it to a JIRA, please?
Just the Foo classes as the test case?
Thanks
Mike
>
>
> txs and LieGrue,
> strub
>
>
>
> ----- Original Message -----
>> From: Mike Olson <mo...@the-olsons.net>
>> To: user@openwebbeans.apache.org
>> Cc:
>> Sent: Thursday, December 27, 2012 10:55 PM
>> Subject: Re: OWB 1.7 ignores Alternative when using the provider interface
>>
>> On 12/27/2012 2:43 PM, Mark Struberg wrote:
>>
>> It does, but I can't use @Inject in this case. I cannot statically bind
>> to a single instance of Foo.
>>
>> I suppose I could create a FooWrapper class.
>>
>> class FooWrapper {
>> @Inject Foo foo;
>> }
>>
>> Then in Main use:
>>
>> @Inject
>> Provider<FooWrapper> fooWrapperProvider;
>>
>>
>> Mike
>>
>>> And simply @Inject doesn't work?
>>>
>>> LieGrue,
>>> strub
>>>
>>>
>>>
>>>
>>> ----- Original Message -----
>>>> From: Mike Olson <mo...@the-olsons.net>
>>>> To: user@openwebbeans.apache.org
>>>> Cc:
>>>> Sent: Thursday, December 27, 2012 9:56 PM
>>>> Subject: Re: OWB 1.7 ignores Alternative when using the provider
>> interface
>>>> On 12/27/2012 3:35 AM, Mark Struberg wrote:
>>>>
>>>> Hi Mark,
>>>>
>>>>> Hi Mike!
>>>>>
>>>>> Thanks for your great tests, always good to get such feedback!
>>>>>
>>>>> I guess you get a Instance<Foo> as Provider, right?
>>>> Yes, that is what I am seeing.
>>>>
>>>>> In that case 5.2.1 defines that we need to take the Alternative
>> into
>>>> account and filter it away.
>>>>
>>>> Any thoughts on a work around until this can be fixed? I need to use
>>>> the Provider interface to decouple my implementation. I have a Mock
>>>> version of "Foo" in my unit tests, qualified as an
>> Alternative (and
>>>> noted in the beans.xml file).
>>>>
>>>> Thanks
>>>> Mike
>>>>
>>>>> LieGrue,
>>>>> strub
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> ----- Original Message -----
>>>>>> From: Mike Olson <mo...@the-olsons.net>
>>>>>> To: user@openwebbeans.apache.org
>>>>>> Cc:
>>>>>> Sent: Thursday, December 27, 2012 5:18 AM
>>>>>> Subject: OWN 1.7 ignores Alternative when using the provider
>> interface
>>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> I have a very simple setup where I have classes Foo1 and
>> Foo2 that
>>>> implement
>>>>>> the Foo interface
>>>>>>
>>>>>> public interface Foo {
>>>>>> }
>>>>>> @Default
>>>>>> public class Foo1 implements Foo {
>>>>>>
>>>>>> }
>>>>>> @Alternative
>>>>>> public class Foo2 implements Foo {
>>>>>>
>>>>>> }
>>>>>>
>>>>>> Then a class that gets 2 Foos injected
>>>>>>
>>>>>> public class Main {
>>>>>>
>>>>>> @Inject
>>>>>> Foo fooA;
>>>>>>
>>>>>> @Inject
>>>>>> Provider<Foo> fooB;
>>>>>>
>>>>>> @PostConstruct
>>>>>> public void init() {
>>>>>> System.err.println("FooA:" + fooA);
>>>>>> System.err.println("FooB:" + fooB.get());
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> If my beans.xml file is empty, then I get 2 instances of Foo1
>> injected
>>>> into the
>>>>>> class, as expected.
>>>>>>
>>>>>> However, if I add
>>>>>>
>>>>>> <alternatives>
>>>>>> <class>Foo2</class>
>>>>>> </alternatives>
>>>>>>
>>>>>> to my beans.xml, then I get an error when I run the
>> application.
>>>>>> """
>>>>>> INFO: All injection points were validated successfully.
>>>>>> Dec 26, 2012 9:11:29 PM
>> org.apache.webbeans.lifecycle.AbstractLifeCycle
>>>>>> startApplication
>>>>>> INFO: OpenWebBeans Container has started, it took [359] ms.
>>>>>> FooA:Foo2@152c4d9
>>>>>> Dec 26, 2012 9:11:29 PM
>>>>>> org.apache.webbeans.component.AbstractInjectionTargetBean
>>>> postConstructDefault
>>>>>> SEVERE: An error occurred while executing [@PostConstruct.]
>>>>>> javax.enterprise.inject.AmbiguousResolutionException: There
>> is more
>>>> than one api
>>>>>> type with : Foo with qualifiers : Qualifiers:
>>>>>> [@javax.enterprise.inject.Default()]
>>>>>> found beans:
>>>>>> Foo1, Name:null, WebBeans Type:MANAGED, API
>>>> Types:[Foo,Foo1,java.lang.Object],
>>>>
>> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
>>>>>> Foo2, Name:null, WebBeans Type:MANAGED, API
>>>> Types:[Foo,java.lang.Object,Foo2],
>>>>
>> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
>>>>>> at
>>>>>>
>> org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionExceptionForBeans(InjectionExceptionUtils.java:121)
>>>>>> at
>>>>>>
>> org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionException(InjectionExceptionUtils.java:111)
>>>>>> at
>>>>>>
>> org.apache.webbeans.container.ResolutionUtil.checkResolvedBeans(ResolutionUtil.java:80)
>>>>>> at
>>>>>>
>> org.apache.webbeans.inject.instance.InstanceImpl.get(InstanceImpl.java:110)
>>>>>> at Main.init(Main.java:23)
>>>>>> """
>>>>>>
>>>>>> This exception happens when I call Provider.get(). I assumed
>> that the
>>>> Provider
>>>>>> interface would respect the Alternative Qualifiers, but that
>> does not
>>>> seem to be
>>>>>> the case.
>>>>>>
>>>>>> Is this a bug in what I am doing, or a bug in OWB?
>>>>>>
>>>>>> Thanks
>>>>>> Mike
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> -- Mike Olson
>>>>>>
>>>> --
>>>> Mike Olson
>>>>
>>
>> --
>> Mike Olson
>>
--
Mike Olson
Re: OWB 1.7 ignores Alternative when using the provider interface
Posted by Mark Struberg <st...@yahoo.de>.
Or we just gonna fix this issue and ship owb-1.8 :)
Can you please create a patch with a small test case and attach it to a JIRA, please?
txs and LieGrue,
strub
----- Original Message -----
> From: Mike Olson <mo...@the-olsons.net>
> To: user@openwebbeans.apache.org
> Cc:
> Sent: Thursday, December 27, 2012 10:55 PM
> Subject: Re: OWB 1.7 ignores Alternative when using the provider interface
>
> On 12/27/2012 2:43 PM, Mark Struberg wrote:
>
> It does, but I can't use @Inject in this case. I cannot statically bind
> to a single instance of Foo.
>
> I suppose I could create a FooWrapper class.
>
> class FooWrapper {
> @Inject Foo foo;
> }
>
> Then in Main use:
>
> @Inject
> Provider<FooWrapper> fooWrapperProvider;
>
>
> Mike
>
>> And simply @Inject doesn't work?
>>
>> LieGrue,
>> strub
>>
>>
>>
>>
>> ----- Original Message -----
>>> From: Mike Olson <mo...@the-olsons.net>
>>> To: user@openwebbeans.apache.org
>>> Cc:
>>> Sent: Thursday, December 27, 2012 9:56 PM
>>> Subject: Re: OWB 1.7 ignores Alternative when using the provider
> interface
>>>
>>> On 12/27/2012 3:35 AM, Mark Struberg wrote:
>>>
>>> Hi Mark,
>>>
>>>> Hi Mike!
>>>>
>>>> Thanks for your great tests, always good to get such feedback!
>>>>
>>>> I guess you get a Instance<Foo> as Provider, right?
>>> Yes, that is what I am seeing.
>>>
>>>> In that case 5.2.1 defines that we need to take the Alternative
> into
>>> account and filter it away.
>>>
>>> Any thoughts on a work around until this can be fixed? I need to use
>>> the Provider interface to decouple my implementation. I have a Mock
>>> version of "Foo" in my unit tests, qualified as an
> Alternative (and
>>> noted in the beans.xml file).
>>>
>>> Thanks
>>> Mike
>>>
>>>> LieGrue,
>>>> strub
>>>>
>>>>
>>>>
>>>>
>>>> ----- Original Message -----
>>>>> From: Mike Olson <mo...@the-olsons.net>
>>>>> To: user@openwebbeans.apache.org
>>>>> Cc:
>>>>> Sent: Thursday, December 27, 2012 5:18 AM
>>>>> Subject: OWN 1.7 ignores Alternative when using the provider
> interface
>>>>>
>>>>>
>>>>> Hello,
>>>>>
>>>>> I have a very simple setup where I have classes Foo1 and
> Foo2 that
>>> implement
>>>>> the Foo interface
>>>>>
>>>>> public interface Foo {
>>>>> }
>>>>> @Default
>>>>> public class Foo1 implements Foo {
>>>>>
>>>>> }
>>>>> @Alternative
>>>>> public class Foo2 implements Foo {
>>>>>
>>>>> }
>>>>>
>>>>> Then a class that gets 2 Foos injected
>>>>>
>>>>> public class Main {
>>>>>
>>>>> @Inject
>>>>> Foo fooA;
>>>>>
>>>>> @Inject
>>>>> Provider<Foo> fooB;
>>>>>
>>>>> @PostConstruct
>>>>> public void init() {
>>>>> System.err.println("FooA:" + fooA);
>>>>> System.err.println("FooB:" + fooB.get());
>>>>> }
>>>>> }
>>>>>
>>>>> If my beans.xml file is empty, then I get 2 instances of Foo1
> injected
>>> into the
>>>>> class, as expected.
>>>>>
>>>>> However, if I add
>>>>>
>>>>> <alternatives>
>>>>> <class>Foo2</class>
>>>>> </alternatives>
>>>>>
>>>>> to my beans.xml, then I get an error when I run the
> application.
>>>>>
>>>>> """
>>>>> INFO: All injection points were validated successfully.
>>>>> Dec 26, 2012 9:11:29 PM
> org.apache.webbeans.lifecycle.AbstractLifeCycle
>>>>> startApplication
>>>>> INFO: OpenWebBeans Container has started, it took [359] ms.
>>>>> FooA:Foo2@152c4d9
>>>>> Dec 26, 2012 9:11:29 PM
>>>>> org.apache.webbeans.component.AbstractInjectionTargetBean
>>> postConstructDefault
>>>>> SEVERE: An error occurred while executing [@PostConstruct.]
>>>>> javax.enterprise.inject.AmbiguousResolutionException: There
> is more
>>> than one api
>>>>> type with : Foo with qualifiers : Qualifiers:
>>>>> [@javax.enterprise.inject.Default()]
>>>>> found beans:
>>>>> Foo1, Name:null, WebBeans Type:MANAGED, API
>>> Types:[Foo,Foo1,java.lang.Object],
>>>
> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
>>>>> Foo2, Name:null, WebBeans Type:MANAGED, API
>>> Types:[Foo,java.lang.Object,Foo2],
>>>
> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
>>>>> at
>>>>>
>>>
> org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionExceptionForBeans(InjectionExceptionUtils.java:121)
>>>>> at
>>>>>
>>>
> org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionException(InjectionExceptionUtils.java:111)
>>>>> at
>>>>>
>>>
> org.apache.webbeans.container.ResolutionUtil.checkResolvedBeans(ResolutionUtil.java:80)
>>>>> at
>>>>>
>>>
> org.apache.webbeans.inject.instance.InstanceImpl.get(InstanceImpl.java:110)
>>>>> at Main.init(Main.java:23)
>>>>> """
>>>>>
>>>>> This exception happens when I call Provider.get(). I assumed
> that the
>>> Provider
>>>>> interface would respect the Alternative Qualifiers, but that
> does not
>>> seem to be
>>>>> the case.
>>>>>
>>>>> Is this a bug in what I am doing, or a bug in OWB?
>>>>>
>>>>> Thanks
>>>>> Mike
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> -- Mike Olson
>>>>>
>>>
>>> --
>>> Mike Olson
>>>
>
>
> --
> Mike Olson
>
Re: OWB 1.7 ignores Alternative when using the provider interface
Posted by Mike Olson <mo...@the-olsons.net>.
On 12/27/2012 2:43 PM, Mark Struberg wrote:
It does, but I can't use @Inject in this case. I cannot statically bind
to a single instance of Foo.
I suppose I could create a FooWrapper class.
class FooWrapper {
@Inject Foo foo;
}
Then in Main use:
@Inject
Provider<FooWrapper> fooWrapperProvider;
Mike
> And simply @Inject doesn't work?
>
> LieGrue,
> strub
>
>
>
>
> ----- Original Message -----
>> From: Mike Olson <mo...@the-olsons.net>
>> To: user@openwebbeans.apache.org
>> Cc:
>> Sent: Thursday, December 27, 2012 9:56 PM
>> Subject: Re: OWB 1.7 ignores Alternative when using the provider interface
>>
>> On 12/27/2012 3:35 AM, Mark Struberg wrote:
>>
>> Hi Mark,
>>
>>> Hi Mike!
>>>
>>> Thanks for your great tests, always good to get such feedback!
>>>
>>> I guess you get a Instance<Foo> as Provider, right?
>> Yes, that is what I am seeing.
>>
>>> In that case 5.2.1 defines that we need to take the Alternative into
>> account and filter it away.
>>
>> Any thoughts on a work around until this can be fixed? I need to use
>> the Provider interface to decouple my implementation. I have a Mock
>> version of "Foo" in my unit tests, qualified as an Alternative (and
>> noted in the beans.xml file).
>>
>> Thanks
>> Mike
>>
>>> LieGrue,
>>> strub
>>>
>>>
>>>
>>>
>>> ----- Original Message -----
>>>> From: Mike Olson <mo...@the-olsons.net>
>>>> To: user@openwebbeans.apache.org
>>>> Cc:
>>>> Sent: Thursday, December 27, 2012 5:18 AM
>>>> Subject: OWN 1.7 ignores Alternative when using the provider interface
>>>>
>>>>
>>>> Hello,
>>>>
>>>> I have a very simple setup where I have classes Foo1 and Foo2 that
>> implement
>>>> the Foo interface
>>>>
>>>> public interface Foo {
>>>> }
>>>> @Default
>>>> public class Foo1 implements Foo {
>>>>
>>>> }
>>>> @Alternative
>>>> public class Foo2 implements Foo {
>>>>
>>>> }
>>>>
>>>> Then a class that gets 2 Foos injected
>>>>
>>>> public class Main {
>>>>
>>>> @Inject
>>>> Foo fooA;
>>>>
>>>> @Inject
>>>> Provider<Foo> fooB;
>>>>
>>>> @PostConstruct
>>>> public void init() {
>>>> System.err.println("FooA:" + fooA);
>>>> System.err.println("FooB:" + fooB.get());
>>>> }
>>>> }
>>>>
>>>> If my beans.xml file is empty, then I get 2 instances of Foo1 injected
>> into the
>>>> class, as expected.
>>>>
>>>> However, if I add
>>>>
>>>> <alternatives>
>>>> <class>Foo2</class>
>>>> </alternatives>
>>>>
>>>> to my beans.xml, then I get an error when I run the application.
>>>>
>>>> """
>>>> INFO: All injection points were validated successfully.
>>>> Dec 26, 2012 9:11:29 PM org.apache.webbeans.lifecycle.AbstractLifeCycle
>>>> startApplication
>>>> INFO: OpenWebBeans Container has started, it took [359] ms.
>>>> FooA:Foo2@152c4d9
>>>> Dec 26, 2012 9:11:29 PM
>>>> org.apache.webbeans.component.AbstractInjectionTargetBean
>> postConstructDefault
>>>> SEVERE: An error occurred while executing [@PostConstruct.]
>>>> javax.enterprise.inject.AmbiguousResolutionException: There is more
>> than one api
>>>> type with : Foo with qualifiers : Qualifiers:
>>>> [@javax.enterprise.inject.Default()]
>>>> found beans:
>>>> Foo1, Name:null, WebBeans Type:MANAGED, API
>> Types:[Foo,Foo1,java.lang.Object],
>> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
>>>> Foo2, Name:null, WebBeans Type:MANAGED, API
>> Types:[Foo,java.lang.Object,Foo2],
>> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
>>>> at
>>>>
>> org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionExceptionForBeans(InjectionExceptionUtils.java:121)
>>>> at
>>>>
>> org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionException(InjectionExceptionUtils.java:111)
>>>> at
>>>>
>> org.apache.webbeans.container.ResolutionUtil.checkResolvedBeans(ResolutionUtil.java:80)
>>>> at
>>>>
>> org.apache.webbeans.inject.instance.InstanceImpl.get(InstanceImpl.java:110)
>>>> at Main.init(Main.java:23)
>>>> """
>>>>
>>>> This exception happens when I call Provider.get(). I assumed that the
>> Provider
>>>> interface would respect the Alternative Qualifiers, but that does not
>> seem to be
>>>> the case.
>>>>
>>>> Is this a bug in what I am doing, or a bug in OWB?
>>>>
>>>> Thanks
>>>> Mike
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> -- Mike Olson
>>>>
>>
>> --
>> Mike Olson
>>
--
Mike Olson
Re: OWB 1.7 ignores Alternative when using the provider interface
Posted by Mark Struberg <st...@yahoo.de>.
And simply @Inject doesn't work?
LieGrue,
strub
----- Original Message -----
> From: Mike Olson <mo...@the-olsons.net>
> To: user@openwebbeans.apache.org
> Cc:
> Sent: Thursday, December 27, 2012 9:56 PM
> Subject: Re: OWB 1.7 ignores Alternative when using the provider interface
>
> On 12/27/2012 3:35 AM, Mark Struberg wrote:
>
> Hi Mark,
>
>> Hi Mike!
>>
>> Thanks for your great tests, always good to get such feedback!
>>
>> I guess you get a Instance<Foo> as Provider, right?
>
> Yes, that is what I am seeing.
>
>> In that case 5.2.1 defines that we need to take the Alternative into
> account and filter it away.
>
> Any thoughts on a work around until this can be fixed? I need to use
> the Provider interface to decouple my implementation. I have a Mock
> version of "Foo" in my unit tests, qualified as an Alternative (and
> noted in the beans.xml file).
>
> Thanks
> Mike
>
>> LieGrue,
>> strub
>>
>>
>>
>>
>> ----- Original Message -----
>>> From: Mike Olson <mo...@the-olsons.net>
>>> To: user@openwebbeans.apache.org
>>> Cc:
>>> Sent: Thursday, December 27, 2012 5:18 AM
>>> Subject: OWN 1.7 ignores Alternative when using the provider interface
>>>
>>>
>>> Hello,
>>>
>>> I have a very simple setup where I have classes Foo1 and Foo2 that
> implement
>>> the Foo interface
>>>
>>> public interface Foo {
>>> }
>>> @Default
>>> public class Foo1 implements Foo {
>>>
>>> }
>>> @Alternative
>>> public class Foo2 implements Foo {
>>>
>>> }
>>>
>>> Then a class that gets 2 Foos injected
>>>
>>> public class Main {
>>>
>>> @Inject
>>> Foo fooA;
>>>
>>> @Inject
>>> Provider<Foo> fooB;
>>>
>>> @PostConstruct
>>> public void init() {
>>> System.err.println("FooA:" + fooA);
>>> System.err.println("FooB:" + fooB.get());
>>> }
>>> }
>>>
>>> If my beans.xml file is empty, then I get 2 instances of Foo1 injected
> into the
>>> class, as expected.
>>>
>>> However, if I add
>>>
>>> <alternatives>
>>> <class>Foo2</class>
>>> </alternatives>
>>>
>>> to my beans.xml, then I get an error when I run the application.
>>>
>>> """
>>> INFO: All injection points were validated successfully.
>>> Dec 26, 2012 9:11:29 PM org.apache.webbeans.lifecycle.AbstractLifeCycle
>>> startApplication
>>> INFO: OpenWebBeans Container has started, it took [359] ms.
>>> FooA:Foo2@152c4d9
>>> Dec 26, 2012 9:11:29 PM
>>> org.apache.webbeans.component.AbstractInjectionTargetBean
> postConstructDefault
>>> SEVERE: An error occurred while executing [@PostConstruct.]
>>> javax.enterprise.inject.AmbiguousResolutionException: There is more
> than one api
>>> type with : Foo with qualifiers : Qualifiers:
>>> [@javax.enterprise.inject.Default()]
>>> found beans:
>>> Foo1, Name:null, WebBeans Type:MANAGED, API
> Types:[Foo,Foo1,java.lang.Object],
>>>
> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
>>> Foo2, Name:null, WebBeans Type:MANAGED, API
> Types:[Foo,java.lang.Object,Foo2],
>>>
> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
>>> at
>>>
> org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionExceptionForBeans(InjectionExceptionUtils.java:121)
>>> at
>>>
> org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionException(InjectionExceptionUtils.java:111)
>>> at
>>>
> org.apache.webbeans.container.ResolutionUtil.checkResolvedBeans(ResolutionUtil.java:80)
>>> at
>>>
> org.apache.webbeans.inject.instance.InstanceImpl.get(InstanceImpl.java:110)
>>> at Main.init(Main.java:23)
>>> """
>>>
>>> This exception happens when I call Provider.get(). I assumed that the
> Provider
>>> interface would respect the Alternative Qualifiers, but that does not
> seem to be
>>> the case.
>>>
>>> Is this a bug in what I am doing, or a bug in OWB?
>>>
>>> Thanks
>>> Mike
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> -- Mike Olson
>>>
>
>
> --
> Mike Olson
>