-
1. Re: Using Weld to inject new JMS 2 API
mkouba Apr 25, 2013 11:33 AM (in response to jmesnil)Hi Jeff,
I don't think you should create AnnotatedType from JMSContext. There is no @JMSPasswordCredential or @JMSSessionMode defined on it... Where are these annotations supposed to be defined at all? And you should not create InjectionTarget either. Instead return an empty set for getInjectionPoints().
BTW your producer will not work because CDI doesn't know how to satisfy "ConnectionFactory cf, int ackMode, String userName, String password" parameter injection points.
Also take a look at Hibernate Validator (Bean Validation RI) integration code (AFAIK this code should be working now):
-
2. Re: Using Weld to inject new JMS 2 API
jmesnil Apr 25, 2013 11:47 AM (in response to mkouba)Martin Kouba wrote:
Hi Jeff,
I don't think you should create AnnotatedType from JMSContext. There is no @JMSPasswordCredential or @JMSSessionMode defined on it... Where are these annotations supposed to be defined at all? And you should not create InjectionTarget either. Instead return an empty set for getInjectionPoints().
@JMSPasswordCredential and @JMSSessionMode are annotations defined in the JMS 2.0[1] that can be used to qualify the injected JMSContext
BTW your producer will not work because CDI doesn't know how to satisfy "ConnectionFactory cf, int ackMode, String userName, String password" parameter injection points.
Yes, that's the thing I don't get: when I create a HornetQJMSContext from an annotated JMSContext, how do I get the associated annotations (@JMSPasswordCredential, etc.)? That's why I wanted to create an injection target for it and get its associated injection points.
Also take a look at Hibernate Validator (Bean Validation RI) integration code (AFAIK this code should be working now):
I'll take a look, thanks,
jeff
-
3. Re: Using Weld to inject new JMS 2 API
meetoblivion Apr 27, 2013 10:30 AM (in response to jmesnil)I don't believe that HornetQ is JMS 2 compliant yet. I don't see a class named "HornetQJMSContext" in their github repo.
-
4. Re: Using Weld to inject new JMS 2 API
jmesnil May 14, 2013 4:15 AM (in response to meetoblivion)John Ament wrote:
I don't believe that HornetQ is JMS 2 compliant yet. I don't see a class named "HornetQJMSContext" in their github repo.
Yes, HornetQ is not JMS 2 compliant yet (the JMS 2.0 work is done in a jms2 branch at the moment).
After reading carefully the JMS 2.0 spec, it's not HornetQ job to support injection of JMSContext. I'll do this in WildFly messaging subsystem instead.
-
5. Re: Using Weld to inject new JMS 2 API
jmesnil May 15, 2013 5:17 AM (in response to mkouba)Hi Martin,
Martin Kouba wrote:
BTW your producer will not work because CDI doesn't know how to satisfy "ConnectionFactory cf, int ackMode, String userName, String password" parameter injection points.
Also take a look at Hibernate Validator (Bean Validation RI) integration code (AFAIK this code should be working now):
I followed the Hibernate Validator code and I was able to instantiate an injected JMSContext object[1] by providing a simple bean for it[2].
However, the injected resource can be annotated with JMS 2.0 annotations (eg @JMSConnectionFactory[3]). I don't understand how I can fetch the annotations bound to the injected resource to instantiate it properly. Should I declare injection points in the Bean<JMSContext> definition for each JMS 2.0 annotations?
Looking at Weld/CDI doc, it seems I could also use a producer factory with the InjectionPoint but then I don't see how it is related to the creation of the resource in Bean<JMSContext>.create()?
Do you have any example to created such injected resources customized with annotations (that are not @Qualifier)?
thanks
[3] https://jms-spec.java.net/2.0/apidocs/javax/jms/JMSConnectionFactory.html
-
6. Re: Using Weld to inject new JMS 2 API
meetoblivion May 15, 2013 7:43 AM (in response to jmesnil)You need to work with an injection point object. You can take a look here at how Solder did this previously:
It may be worthwhile to look at how Seam JMS was doing this in the past for the core JMS objects. You can see those producers here:
https://github.com/johnament/seam-jms/tree/develop/impl/src/main/java/org/jboss/seam/jms/impl/inject
BTW, the JMS spec really doesn't say how the injection has to be done, just that it needs to be there. I think this approach will do just fine; I had also considered that implementations may end up using a portable extension to install it.
Happy Testing!
-
7. Re: Using Weld to inject new JMS 2 API
mkouba May 15, 2013 8:13 AM (in response to jmesnil)Jeff,
As I understand it you only need to make JMSContext available for injection in CDI beans. So the producer method is the best way to achieve this. As John suggested use injection point metadata -> InjectionPoint.getAnnotated(). And keep in mind that this metadata is only available for dependent scoped beans (default scope). TypedMessageBundleProducer is a good example to study Also have a look at CDI spec injection point metadata example: http://docs.jboss.org/cdi/spec/1.1/cdi-spec.html#_injection_point_metadata_example and "Injection point metadata" section: http://docs.jboss.org/cdi/spec/1.1/cdi-spec.html#injection_point
-
8. Re: Using Weld to inject new JMS 2 API
jmesnil May 16, 2013 11:38 AM (in response to meetoblivion)I finally figured it out thanks to john and martin's help.
The CDI injection code I added was correct after following the seam 3 example but there was a dependency issue preventing the injection to work.
My issue was pretty specific to WildFly:
- the CDI producer for the injected context was in the messaging subsystem
- when the bean archive was deployed, I added an annotated type for it
- however, Weld was not finding my producer method when it was validating the injection because the messaging module classes were not visible from the deployed archive module loaded.
=> I fixed it by adding a module dependency to it and it works as expected
Thanks for the help (and the awesome documentation),
jeff
-
9. Re: Using Weld to inject new JMS 2 API
meetoblivion May 16, 2013 11:51 AM (in response to jmesnil)I struggled here with a similar issue in AS7 (we use Seam3 externally, not in JARs). Can the messaging subsystem be automatically added if the container sees @Inject JMSContext or similar?