Clarification of BeanManager.getReference

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Clarification of BeanManager.getReference

John Ament

All,


A discussion popped up on a recent CXF vote.  As I understand it, per section 11.3.2 (from CDI 1.2), The Type parameter passed in to getReference is meant to be the class to proxy for the returned object, if the object requires a proxy (e.g. a normal scoped bean).  Is that accurate? Or is the underlying type the type of the returned bean, from Bean.create(CreationalContext) ?


John



NOTICE: This e-mail message and any attachments may contain confidential, proprietary, and/or privileged information which should be treated accordingly. If you are not the intended recipient, please notify the sender immediately by return e-mail, delete this message, and destroy all physical and electronic copies. Thank you.
_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
Reply | Threaded
Open this post in threaded view
|

Re: Clarification of BeanManager.getReference

Martin Kouba
Hi John,

the "beanType" parameter is de facto the same as the required type of an
injection point. So yes, the param must be one of the bean types and for
normal scoped the returned client proxy must implement this type (+ all
interfaces). Also note that a contextual reference (client for normal
scoped) is not required to implement all bean types of the bean.

Martin

Dne 11.12.2016 v 18:40 John Ament napsal(a):

> All,
>
>
> A discussion popped up on a recent CXF vote.  As I understand it, per
> section 11.3.2 (from CDI 1.2), The Type parameter passed in to
> getReference is meant to be the class to proxy for the returned object,
> if the object requires a proxy (e.g. a normal scoped bean).  Is that
> accurate? Or is the underlying type the type of the returned bean, from
> Bean.create(CreationalContext) ?
>
>
> John
>
>
> ------------------------------------------------------------------------
> NOTICE: This e-mail message and any attachments may contain
> confidential, proprietary, and/or privileged information which should be
> treated accordingly. If you are not the intended recipient, please
> notify the sender immediately by return e-mail, delete this message, and
> destroy all physical and electronic copies. Thank you.
>
>
> _______________________________________________
> cdi-dev mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/cdi-dev
>
> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
>

--
Martin Kouba
Software Engineer
Red Hat, Czech Republic
_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
Reply | Threaded
Open this post in threaded view
|

Re: Clarification of BeanManager.getReference

Mark Struberg
The main point (as mentioned over at CXF) is that one must not use bean.getBeanClass() as type parameter for getReference.

LieGrue,
strub


> Am 12.12.2016 um 09:10 schrieb Martin Kouba <[hidden email]>:
>
> Hi John,
>
> the "beanType" parameter is de facto the same as the required type of an
> injection point. So yes, the param must be one of the bean types and for
> normal scoped the returned client proxy must implement this type (+ all
> interfaces). Also note that a contextual reference (client for normal
> scoped) is not required to implement all bean types of the bean.
>
> Martin
>
> Dne 11.12.2016 v 18:40 John Ament napsal(a):
>> All,
>>
>>
>> A discussion popped up on a recent CXF vote.  As I understand it, per
>> section 11.3.2 (from CDI 1.2), The Type parameter passed in to
>> getReference is meant to be the class to proxy for the returned object,
>> if the object requires a proxy (e.g. a normal scoped bean).  Is that
>> accurate? Or is the underlying type the type of the returned bean, from
>> Bean.create(CreationalContext) ?
>>
>>
>> John
>>
>>
>> ------------------------------------------------------------------------
>> NOTICE: This e-mail message and any attachments may contain
>> confidential, proprietary, and/or privileged information which should be
>> treated accordingly. If you are not the intended recipient, please
>> notify the sender immediately by return e-mail, delete this message, and
>> destroy all physical and electronic copies. Thank you.
>>
>>
>> _______________________________________________
>> cdi-dev mailing list
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/cdi-dev
>>
>> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
>>
>
> --
> Martin Kouba
> Software Engineer
> Red Hat, Czech Republic
> _______________________________________________
> cdi-dev mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/cdi-dev
>
> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.


_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
Reply | Threaded
Open this post in threaded view
|

Re: Clarification of BeanManager.getReference

Martin Kouba
Sure thing, bean.getBeanClass() does not have to be in the set of bean
types (producers, custom beans, bean class with @Typed, ...).

M

Dne 12.12.2016 v 09:15 Mark Struberg napsal(a):

> The main point (as mentioned over at CXF) is that one must not use bean.getBeanClass() as type parameter for getReference.
>
> LieGrue,
> strub
>
>
>> Am 12.12.2016 um 09:10 schrieb Martin Kouba <[hidden email]>:
>>
>> Hi John,
>>
>> the "beanType" parameter is de facto the same as the required type of an
>> injection point. So yes, the param must be one of the bean types and for
>> normal scoped the returned client proxy must implement this type (+ all
>> interfaces). Also note that a contextual reference (client for normal
>> scoped) is not required to implement all bean types of the bean.
>>
>> Martin
>>
>> Dne 11.12.2016 v 18:40 John Ament napsal(a):
>>> All,
>>>
>>>
>>> A discussion popped up on a recent CXF vote.  As I understand it, per
>>> section 11.3.2 (from CDI 1.2), The Type parameter passed in to
>>> getReference is meant to be the class to proxy for the returned object,
>>> if the object requires a proxy (e.g. a normal scoped bean).  Is that
>>> accurate? Or is the underlying type the type of the returned bean, from
>>> Bean.create(CreationalContext) ?
>>>
>>>
>>> John
>>>
>>>
>>> ------------------------------------------------------------------------
>>> NOTICE: This e-mail message and any attachments may contain
>>> confidential, proprietary, and/or privileged information which should be
>>> treated accordingly. If you are not the intended recipient, please
>>> notify the sender immediately by return e-mail, delete this message, and
>>> destroy all physical and electronic copies. Thank you.
>>>
>>>
>>> _______________________________________________
>>> cdi-dev mailing list
>>> [hidden email]
>>> https://lists.jboss.org/mailman/listinfo/cdi-dev
>>>
>>> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
>>>
>>
>> --
>> Martin Kouba
>> Software Engineer
>> Red Hat, Czech Republic
>> _______________________________________________
>> cdi-dev mailing list
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/cdi-dev
>>
>> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
>

--
Martin Kouba
Software Engineer
Red Hat, Czech Republic
_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
Reply | Threaded
Open this post in threaded view
|

Re: Clarification of BeanManager.getReference

John Ament

Well it sounds almost like a user would have to find the outer most value of getTypes to figure out which is the right type.


This means that popular CDI enabled frameworks, including Camel and DeltaSpike, are potentially doing it wrong


https://github.com/apache/deltaspike/blob/master/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/bean/BeanBuilder.java#L115

https://github.com/apache/camel/blob/master/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelExtension.java#L365




From: [hidden email] <[hidden email]> on behalf of Martin Kouba <[hidden email]>
Sent: Monday, December 12, 2016 3:19 AM
To: Mark Struberg
Cc: cdi-dev
Subject: Re: [cdi-dev] Clarification of BeanManager.getReference
 
Sure thing, bean.getBeanClass() does not have to be in the set of bean
types (producers, custom beans, bean class with @Typed, ...).

M

Dne 12.12.2016 v 09:15 Mark Struberg napsal(a):
> The main point (as mentioned over at CXF) is that one must not use bean.getBeanClass() as type parameter for getReference.
>
> LieGrue,
> strub
>
>
>> Am 12.12.2016 um 09:10 schrieb Martin Kouba <[hidden email]>:
>>
>> Hi John,
>>
>> the "beanType" parameter is de facto the same as the required type of an
>> injection point. So yes, the param must be one of the bean types and for
>> normal scoped the returned client proxy must implement this type (+ all
>> interfaces). Also note that a contextual reference (client for normal
>> scoped) is not required to implement all bean types of the bean.
>>
>> Martin
>>
>> Dne 11.12.2016 v 18:40 John Ament napsal(a):
>>> All,
>>>
>>>
>>> A discussion popped up on a recent CXF vote.  As I understand it, per
>>> section 11.3.2 (from CDI 1.2), The Type parameter passed in to
>>> getReference is meant to be the class to proxy for the returned object,
>>> if the object requires a proxy (e.g. a normal scoped bean).  Is that
>>> accurate? Or is the underlying type the type of the returned bean, from
>>> Bean.create(CreationalContext) ?
>>>
>>>
>>> John
>>>
>>>
>>> ------------------------------------------------------------------------
>>> NOTICE: This e-mail message and any attachments may contain
>>> confidential, proprietary, and/or privileged information which should be
>>> treated accordingly. If you are not the intended recipient, please
>>> notify the sender immediately by return e-mail, delete this message, and
>>> destroy all physical and electronic copies. Thank you.
>>>
>>>
>>> _______________________________________________
>>> cdi-dev mailing list
>>> [hidden email]
>>> https://lists.jboss.org/mailman/listinfo/cdi-dev
lists.jboss.org
List to discuss the development of CDI (the specification) To see the collection of prior postings to the list, visit the cdi-dev Archives.


>>>
>>> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
www.apache.org
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION. 1. Definitions.


>>>
>>
>> --
>> Martin Kouba
>> Software Engineer
>> Red Hat, Czech Republic
>> _______________________________________________
>> cdi-dev mailing list
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/cdi-dev
lists.jboss.org
List to discuss the development of CDI (the specification) To see the collection of prior postings to the list, visit the cdi-dev Archives.


>>
>> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
www.apache.org
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION. 1. Definitions.


>

--
Martin Kouba
Software Engineer
Red Hat, Czech Republic
_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev
lists.jboss.org
List to discuss the development of CDI (the specification) To see the collection of prior postings to the list, visit the cdi-dev Archives.



Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
www.apache.org
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION. 1. Definitions.



NOTICE: This e-mail message and any attachments may contain confidential, proprietary, and/or privileged information which should be treated accordingly. If you are not the intended recipient, please notify the sender immediately by return e-mail, delete this message, and destroy all physical and electronic copies. Thank you.
_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
Reply | Threaded
Open this post in threaded view
|

Re: Clarification of BeanManager.getReference

Martin Kouba
Dne 12.12.2016 v 12:49 John Ament napsal(a):
> Well it sounds almost like a user would have to find the outer most
> value of getTypes to figure out which is the right type.

Well, as I said - it's the same as if you're injecting a contextual
reference. And the user of BM.getReference() - probably extension author
or integrator - should be aware of this. In practice, this beanType
paramater is often ignored and the proxy implements all bean types (this
is what Weld does in most cases).

>
>
> This means that popular CDI enabled frameworks, including Camel
> and DeltaSpike, are potentially doing it wrong
>
>
> https://github.com/apache/deltaspike/blob/master/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/bean/BeanBuilder.java#L115
>
> https://github.com/apache/camel/blob/master/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelExtension.java#L365

For a custom impl of Bean, I think it's ok to return the class of the
extension which registered the bean.

>
>
>
> ------------------------------------------------------------------------
> *From:* [hidden email]
> <[hidden email]> on behalf of Martin Kouba
> <[hidden email]>
> *Sent:* Monday, December 12, 2016 3:19 AM
> *To:* Mark Struberg
> *Cc:* cdi-dev
> *Subject:* Re: [cdi-dev] Clarification of BeanManager.getReference
>
> Sure thing, bean.getBeanClass() does not have to be in the set of bean
> types (producers, custom beans, bean class with @Typed, ...).
>
> M
>
> Dne 12.12.2016 v 09:15 Mark Struberg napsal(a):
>> The main point (as mentioned over at CXF) is that one must not use bean.getBeanClass() as type parameter for getReference.
>>
>> LieGrue,
>> strub
>>
>>
>>> Am 12.12.2016 um 09:10 schrieb Martin Kouba <[hidden email]>:
>>>
>>> Hi John,
>>>
>>> the "beanType" parameter is de facto the same as the required type of an
>>> injection point. So yes, the param must be one of the bean types and for
>>> normal scoped the returned client proxy must implement this type (+ all
>>> interfaces). Also note that a contextual reference (client for normal
>>> scoped) is not required to implement all bean types of the bean.
>>>
>>> Martin
>>>
>>> Dne 11.12.2016 v 18:40 John Ament napsal(a):
>>>> All,
>>>>
>>>>
>>>> A discussion popped up on a recent CXF vote.  As I understand it, per
>>>> section 11.3.2 (from CDI 1.2), The Type parameter passed in to
>>>> getReference is meant to be the class to proxy for the returned object,
>>>> if the object requires a proxy (e.g. a normal scoped bean).  Is that
>>>> accurate? Or is the underlying type the type of the returned bean, from
>>>> Bean.create(CreationalContext) ?
>>>>
>>>>
>>>> John
>>>>
>>>>
>>>> ------------------------------------------------------------------------
>>>> NOTICE: This e-mail message and any attachments may contain
>>>> confidential, proprietary, and/or privileged information which should be
>>>> treated accordingly. If you are not the intended recipient, please
>>>> notify the sender immediately by return e-mail, delete this message, and
>>>> destroy all physical and electronic copies. Thank you.
>>>>
>>>>
>>>> _______________________________________________
>>>> cdi-dev mailing list
>>>> [hidden email]
>>>> https://lists.jboss.org/mailman/listinfo/cdi-dev
> cdi-dev Info Page - JBoss Developer
> <https://lists.jboss.org/mailman/listinfo/cdi-dev>
> lists.jboss.org
> List to discuss the development of CDI (the specification) To see the
> collection of prior postings to the list, visit the cdi-dev Archives.
>
>
>
>>>>
>>>> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas
> provided on this list, the provider waives all patent and other
> intellectual property rights inherent in such information.
> Apache License, Version 2.0
> <http://www.apache.org/licenses/LICENSE-2.0.html>
> www.apache.org
> Apache License Version 2.0, January 2004 http://www.apache.org/licenses/
> TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION. 1.
> Definitions.
>
>
>
>>>>
>>>
>>> --
>>> Martin Kouba
>>> Software Engineer
>>> Red Hat, Czech Republic
>>> _______________________________________________
>>> cdi-dev mailing list
>>> [hidden email]
>>> https://lists.jboss.org/mailman/listinfo/cdi-dev
> cdi-dev Info Page - JBoss Developer
> <https://lists.jboss.org/mailman/listinfo/cdi-dev>
> lists.jboss.org
> List to discuss the development of CDI (the specification) To see the
> collection of prior postings to the list, visit the cdi-dev Archives.
>
>
>
>>>
>>> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas
> provided on this list, the provider waives all patent and other
> intellectual property rights inherent in such information.
> Apache License, Version 2.0
> <http://www.apache.org/licenses/LICENSE-2.0.html>
> www.apache.org
> Apache License Version 2.0, January 2004 http://www.apache.org/licenses/
> TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION. 1.
> Definitions.
>
>
>
>>
>
> --
> Martin Kouba
> Software Engineer
> Red Hat, Czech Republic
> _______________________________________________
> cdi-dev mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/cdi-dev
> cdi-dev Info Page - JBoss Developer
> <https://lists.jboss.org/mailman/listinfo/cdi-dev>
> lists.jboss.org
> List to discuss the development of CDI (the specification) To see the
> collection of prior postings to the list, visit the cdi-dev Archives.
>
>
>
>
> Note that for all code provided on this list, the provider licenses the
> code under the Apache License, Version 2
> (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas
> provided on this list, the provider waives all patent and other
> intellectual property rights inherent in such information.
> Apache License, Version 2.0
> <http://www.apache.org/licenses/LICENSE-2.0.html>
> www.apache.org
> Apache License Version 2.0, January 2004 http://www.apache.org/licenses/
> TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION. 1.
> Definitions.
>
>
>
> ------------------------------------------------------------------------
> NOTICE: This e-mail message and any attachments may contain
> confidential, proprietary, and/or privileged information which should be
> treated accordingly. If you are not the intended recipient, please
> notify the sender immediately by return e-mail, delete this message, and
> destroy all physical and electronic copies. Thank you.

--
Martin Kouba
Software Engineer
Red Hat, Czech Republic
_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.