On May 7, 2009, at 7:34 AM, louis.alexander wrote:

I have a ConnectionFactory, some Queues and Topics that i would like to be made available in openejb for unit testing purposes, however our system uses
the jndi names jms/MyFactory, but when i configure  MyFactory in my
ejb-jar.xml it gets a jndi jame of java:comp/env/jms/MyFactory.  My
understanding was that when i configure a jndi resource in a JavaEE
environment i get two JNDI names one that i configure, and one prefixed with java:comp/env. I would settle for just getting the non java:comp/ env/ name.
Below is my ejb-jar.xml, any help would be appreciated.

Hi Louis,

By spec the only names an EJB or Serlvet can lookup from JNDI start with the "java:comp/" and "java:comp/env/" prefix.

There is a method on the javax.ejb.EJBContext called 'lookup' which is a convenience method around JNDI that allows the "java:comp/env/" prefix to be omitted, but this is really just doing this under the covers:

  try {
      InitialContext initialContext = new InitialContext();
      Context ctx = (Context) initialContext.lookup("java:comp/env");
      return ctx.lookup(name);
  } catch (NamingException e) {
      throw new IllegalArgumentException(e);
  } catch (RuntimeException e) {
      throw new IllegalArgumentException(e);
  }


If the ultimate goal is to get access to your Topics and Queues from your test case, than this technique will work:

  http://cwiki.apache.org/OPENEJBx30/testcase-with-testbean-inner-class.html

Hope this helps!

-David

Reply via email to