users@glassfish.java.net

Re: InitialContext.lookup works but _at_Resource does not

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Fri, 12 Feb 2010 16:04:36 +0100

2010/2/11 Witold Szczerba <pljosh.mail_at_gmail.com>:
> Hi there,
> I have problem in one of my session bean deployed on Glassfish v2.1.1.
> The bean is supposed to send messages to WebSphere MQ using WebSphere
> MQ JCA Adapter. So, in order to send a message it needs two objects:
> ConnectionFactory and Queue.
> When I look for those objects using InitialContext, everything works
> and messages are sent.
>
> The code below works:
> ----------------------------------------
> ConnectionFactory ivtcf = null;
> Queue ivtQueue = null;
> try {
>    InitialContext ctx = new InitialContext();
>    ivtcf = (ConnectionFactory) ctx.lookup("jms/IVTCF");
>    ivtQueue = (Queue) ctx.lookup("jms/IVTQueue");
> } catch (NamingException ex) {
>    throw new RuntimeException(ex);
> }
>
> logger.info("ivctf="+ivtcf);
> logger.info("ivtQueue="+ivtQueue);
> ----------------------------------------
>
>
> The problem is I cannot use @Resource injection to get rod of those
> InitialContext lookups and NamingExceptions:
> ----------------------------------------
> @Resource(mappedName = "jms/IVTCF")
> private ConnectionFactory ivtcf;
> @Resource(mappedName = "jms/IVTQueue")
> private Queue ivtQueue;
> ----------------------------------------
>
> The above declarations cause exceptions when container tries to create
> that session bean:
> (bean name is wmqtest.Producer, full stacktrace in attachment)
>
> NAM0002: Exception in NamingManagerImpl copyMutableObject().
> java.io.NotSerializableException: java.lang.Object
> [...]
> EJB5070: Exception creating stateless session bean : [{0}]
> com.sun.enterprise.InjectionException: Exception attempting to inject
> Res-Ref-Env-Property:
> wmqtest.Producer/ivtcf_at_javax.jms.ConnectionFactory@ resolved as: jndi:
> jms/IVTCF_at_res principal: null_at_mail: null
> No Runtime properties
> Database Vendor : null
> Create Tables at Deploy : false
> Delete Tables at Undeploy : false into class wmqtest.Producer
> [...]
> Caused by: javax.naming.NameNotFoundException: No object bound for
> java:comp/env/wmqtest.Producer/ivtcf [Root exception is
> java.lang.RuntimeException: Cant copy Serializable object:]
> [...]
> nested exception is: javax.ejb.EJBException: nested exception is:
> javax.ejb.CreateException: Could not create stateless EJB
>
>
> Can you tell me what is wrong with all this? Could it be a bug in
> Glassfish or WebSphere MQ JCA Adapter?
> I am attaching the entire log, the source code of my session bean and
> domain.xml.
>
> Thanks,
> Witold Szczerba
>

I have found a solution for @Resource issue. Thanks to that conversation:
http://forums.java.net/jive/message.jspa?messageID=239405

I followed the solution provided by 'hildo' and added the "name" of
the resource like this:
----------------------------------------
@Resource(mappedName = "jms/IVTCF", name = "eis/IVTCF")
private ConnectionFactory ivtcf;
@Resource(mappedName = "jms/IVTQueue", name = "eis/IVTQueue")
private Queue ivtQueue;
----------------------------------------

Notice the "eis/" prefix of the "name" attribute.
So now, everything works perfect (because NamingManagerImpl does not
try to return a copy of resources).
I can use that injected resources to send messages, because there is
no longer NotSerializableException when creating that bean.


The other problem still remains: I cannot deploy MDB.
I was trying everything like adding a >name="eis/IVTQueue" into @MessageDriven<
or declaring extra @Resource annotation on the MDB class and binding
mappedName to name and then using that name in @MessageDriven and
everything I found possible to do, but always the same:

MDB00017: [eis/IVTQueue]: Exception in creating message-driven bean
container: [com.sun.enterprise.connectors.ConnectorRuntimeException:
Could not find physical destination : null]
com.sun.enterprise.connectors.ConnectorRuntimeException
com.sun.enterprise.connectors.ConnectorRuntimeException: Could not
find physical destination : null

The stack trace was attached few posts above (wmqtest-stacktrace_2.txt)
Do you think I should start a new topic on this problem?

Thanks,
Witold Szczerba