users@glassfish.java.net

Re: Resource injection in servlet (JMS)

From: Sivakumar Thyagarajan <Sivakumar.Thyagarajan_at_Sun.COM>
Date: Mon, 08 Oct 2007 16:12:13 +0530

> The first way to fix the problem is to use "mappedName" instead of "name" in
> the annotation.

Yes, this is right. Please see Ken's response at
http://forums.java.net/jive/thread.jspa?messageID=213415 for a detailed
explanation on using mappedName. mappedName is the vendor-specific
representation of your global JNDI resource and using it is not equivalent to
using a non-portable "vendor-specific" API for binding to a global JNDI resource.

> The second way is to add an entry in sun-web.xml, to declare the mapping
> between the content of the "name" field in the annotation and the JNDI name
> of the Queue in Glassfish. (in my case, a mappting between
> "jms/ProcessingQueue" and "jms/ProcessingQueue")

If you do not want the resource mapping to be done in the bean-code itself via
mappedName, sun-web.xml is the alternative to tie the local JNDI reference to
the global JNDI resource, but this would result in one-additional
vendor-specific deployment descriptor [sun-web.xml] to be added to your
deployment archive.

HTH,
Thanks
--Siva.


glassfish_at_javadesktop.org wrote:
> Hello,
>
> I would like some advice regarding the use of resource injection in servlets, and in particular for JMS resources.
>
> What I would like to do, is to develop a Web Application (war) and have one servlet use a connection factory and a queue defined in Glassfish. I thought that I should do the following:
>
> - in Glassfish, create a physical queue, the ConnectionFactory and the Queue
> - in my servlet, inject dependency on the resources with the following code:
>
> @Resource(name = "jms/ProcessingQueue")
> private Queue processingQueue;
> @Resource(name = "jms/ProcessingQueueFactory")
> private ConnectionFactory cf;
>
> - in the deploymen descriptors, (web.xml and sun-web.xml), do nothing.
>
> I tried this, but got the following exception:
>
> com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Message-Destination-Ref jms/ProcessingQueue_at_java.lang.String_at_null into class ch.unifr.ase.TestServlet
>
> I have actually found two ways to fix the problem, but I don't completely understand what is happening (not sure if it is the expected behavior or a bug) and I am looking for advice on the question.
>
> The first way to fix the problem is to use "mappedName" instead of "name" in the annotation.
> The second way is to add an entry in sun-web.xml, to declare the mapping between the content of the "name" field in the annotation and the JNDI name of the Queue in Glassfish. (in my case, a mappting between "jms/ProcessingQueue" and "jms/ProcessingQueue")
>
> I have to admit that I don't completely grasp the use of "mappedName"... I know that it is used to specify "application-server specific" ways to name components (and thus should be avoided to ensure portability). The Java EE tutorial uses this field in the JMS examples.
>
> Any comment/suggestion would be greatly appreciated :-)
>
> Cheers,
>
> Olivier
> [Message sent by forum member 'oliechti' (oliechti)]
>
> http://forums.java.net/jive/thread.jspa?messageID=238818
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>