How to connect local context to global jndi context

map local context to global jndi context How do we connect local context (logical jndi name) to global JNDI context (physical jndi name)?
This question got asked quite often and yesterday again. So I thought I'd post the question and my answer here.

Question:
==============
I'm a little lost here. I'm trying to create an MDB, but I'm not sure how to look up the mapped resources - I have a queue and a connection factory defined, but when I use the canonical names, they never resolve. When I use netbeans to create the references, it uses a "Name" attribute, but using that name doesn't resolve either; I guess I'm just not sure how to connect local contexts to the global JNDI context.

Can anyone explain how this works in glassfish for me?


Answer:
============
There are two ways you can map the logical jndi name (the resource reference name that you use to look up in your code, or the local jndi name your referred to) to the physical logic name (the name that you create the resource with, or the global jndi name you referred to).

1. Using the sun specific deployment descriptor files
2. Using the mappedName attribute of the Resource annotation (this is new in Sun Java System Application Server 9.0 / Glassfish)

You can look at this simple mdb test as an example:

In this example, a message connector factory "jms/ejb_ejb30_hello_mdb_QCF" (i.e. the physical jndi name) is created:
asadmin create-jms-resource --restype javax.jms.QueueConnectionFactory jms/ejb_ejb30_hello_mdb_QCF

1. And in the Client code, it uses the mappedName attribute to map the logical jndi name "FooCF" to the physical jndi name "jms/ejb_ejb30_hello_mdb_QCF"
    @Resource(name="FooCF", mappedName="jms/ejb_ejb30_hello_mdb_QCF")
    private static QueueConnectionFactory queueConFactory;

2. Alternatively, you could have this in the Client code without the mappedName attribute:
    @Resource(name="FooCF")
    private static QueueConnectionFactory queueConFactory;

   Then in the sun-application-client.xml, you will provide this mapping
     <resource-ref>
       <res-ref-name>FooCF</res-ref-name>
       <jndi-name>jms/ejb_ejb30_hello_mdb_QCF</jndi-name>
       <default-resource-principal>
         <name>guest</name>
         <password>guest</password>
       </default-resource-principal>
     </resource-ref>


Lastly, in the Sun Java System Application Server 9.0 / Glassfish, we have implemented some runtime defaulting mechanism for global jndi names. When the logical jndi name is the same as physical jndi name, no mapping is needed. You could get more details on this from my runtime defaults blog.
Comments:

But why doesn't Glassfish allow the \*deployer\* to bind the local/logical JNDI name (used by the application) to the actual physical JNDI name?

Posted by David Bullock on October 17, 2006 at 02:26 AM EDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

hzhang

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today