-
1. Re: Hornetq and CDI
jbertram Nov 19, 2012 9:58 PM (in response to ron_sigal)For what it's worth, WebLogic appears to suffer from the same issue. See https://forums.oracle.com/forums/thread.jspa?threadID=2320522&tstart=105.
It appears we need something more clever than instanceof here, but I don't have any ideas off the top of my head. Clebert, what do you think?
-
2. Re: Hornetq and CDI
jbertram Nov 19, 2012 10:08 PM (in response to ron_sigal)Ron, you got any clue where the source code for org.jboss.weldx.jms.Destination is?
-
3. Re: Hornetq and CDI
ron_sigal Nov 19, 2012 11:01 PM (in response to jbertram)Hey Justin,
I suspect that it's nowhere, in the sense that it's a proxy of some sort created by Weld. But not a regular proxy. I tried
log.info("isProxy(): " + Proxy.isProxyClass(bookQueue.getClass()));
and it was false. I don't know for sure, but maybe it's created here: https://github.com/weld/core/blob/master/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java
-Ron
-
4. Re: Hornetq and CDI
jmesnil Nov 20, 2012 2:34 AM (in response to jbertram)Justin Bertram wrote:
For what it's worth, WebLogic appears to suffer from the same issue. See https://forums.oracle.com/forums/thread.jspa?threadID=2320522&tstart=105.
It appears we need something more clever than instanceof here, but I don't have any ideas off the top of my head. Clebert, what do you think?
It's a wild guess but we could use Class.isInstance[1] instead of instanceof. This is the dynamic version of instanceof and it might work with Weld proxies.
[1] http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#isInstance(java.lang.Object)
-
5. Re: Hornetq and CDI
ron_sigal Nov 20, 2012 1:13 PM (in response to jmesnil)I just added
log.info("Class.isInstance(): " + HornetQDestination.class.isInstance(bookQueue));
to my test and got
Class.isInstance(): false
Maybe there's something in Weld that could give the right answer. Maybe Ales can help. He's co-author of ProxyFactory. I'll ask him to take a look at this thread.
Of course, that would mean adding Weld as a dependency.
-Ron
-
6. Re: Hornetq and CDI
ron_sigal Nov 20, 2012 1:26 PM (in response to ron_sigal)I just tried
try { HornetQDestination hqd = HornetQDestination.class.cast(bookQueue); log.info("bookQueue can be cast to HornetQDestination"); } catch (Exception e) { l og.info("bookQueue can't be cast to HornetQDestination"); } and got
13:24:24,967 INFO [org.jboss.resteasy.cdi.injection.BookResource] (http--127.0.0.1-8080-12) bookQueue can't be cast to HornetQDestination
-
7. Re: Hornetq and CDI
clebert.suconic Nov 20, 2012 3:02 PM (in response to ron_sigal)Different classpaths for sure!
-
8. Re: Hornetq and CDI
clebert.suconic Nov 20, 2012 3:02 PM (in response to clebert.suconic)I meant.. different classloaders!
-
9. Re: Hornetq and CDI
alesj Nov 20, 2012 3:06 PM (in response to clebert.suconic)@Ron: how do you get a hold of Destination, I mean, how does CDI / Weld get a hold of it - to wrap it into proxy
-
10. Re: Hornetq and CDI
ron_sigal Nov 20, 2012 8:38 PM (in response to alesj)Hi Clebert,
When I added:
log.info("getClass().getClassLoader(): " + getClass().getClassLoader()); log.info("HornetQDestination.class.getClassLoader(): " + HornetQDestination.class.getClassLoader()); to my test code, I got:
... getClass().getClassLoader(): ModuleClassLoader for Module "deployment.resteasy-cdi-ejb-test.war:main" from Service Module Loader ... HornetQDestination.class.getClassLoader(): ModuleClassLoader for Module "org.jboss.resteasy.resteasy-jaxrs:main" from local module loader @4c5e176f (roots: /home/rsigal/git.master/Resteasy/jaxrs/arquillian/resteasy-cdi-ejb-test/target/jboss-as-7.1.1.Final/modules)
The first one is the war copied to AS 7 by arquillian. The second one is explained by the fact that I added hornetq-jms-client-2.2.13.Final.jar and jboss-jms-api_1.1_spec-1.0.0.Final.jar as resources in the resteasy-jaxrs module. So I took them out of the resteasy-jaxrs module and added them as libraries in the arquillian war, and now I get
... getClass().getClassLoader(): ModuleClassLoader for Module "deployment.resteasy-cdi-ejb-test.war:main" from Service Module Loader ... HornetQDestination.class.getClassLoader(): ModuleClassLoader for Module "deployment.resteasy-cdi-ejb-test.war:main" from Service Module Loader
and I still get
... javax.jms.InvalidDestinationException: Not a HornetQ Destination:HornetQQueue[testQueue]
-Ron
-
11. Re: Hornetq and CDI
ron_sigal Nov 20, 2012 8:48 PM (in response to ron_sigal)Hi Ales,
The following utility class generates a Session and a Queue:
@Resource(name="queue/test")
public class ResourceProducer
{
private static Connection connection;
private static Session session;
@Produces
@ResourceBinding
@Resource(mappedName="java:jboss/exported/jms/queue/test")
Queue bookQueue;
@Resource(mappedName="java:jboss/exported/jms/RemoteConnectionFactory")
ConnectionFactory connectionFactory;
@Produces
@ResourceBinding
public Session getSession() throws JMSException
{
if (connection == null)
{
connection = connectionFactory.createConnection("guest", "pass");
}
if (session == null)
{
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
}
return session;
}
}
and they are injected into another class here:
@Inject
@ResourceBinding
private Session session;
@Inject
@ResourceBinding
private Queue bookQueue;
They are used here
MessageProducer producer = session.createProducer(bookQueue); TextMessage message = session.createTextMessage(book.getName()); producer.send(message); and here:
MessageConsumer consumer = session.createConsumer(bookQueue); TextMessage message = (TextMessage) consumer.receive(); -Ron
-
12. Re: Hornetq and CDI
gaohoward Nov 21, 2012 3:27 AM (in response to ron_sigal)may be the proxy is really a wrap of a different class. Did you try to print out the proxy's fields and methods?
Howard
-
13. Re: Hornetq and CDI
gaohoward Nov 21, 2012 3:28 AM (in response to gaohoward)also its class hierarchy?
-