You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by "louis.alexander" <lo...@gmail.com> on 2009/05/07 16:34:19 UTC
Setting alternate jndi prefix? (not java:comp/env)
All,
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. Thanks
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
version="3.0">
<enterprise-beans>
<!-- Configure the message driven bean that will listen to the
RouterEventsQueue queue -->
<message-driven>
<ejb-name>DispatcherBean</ejb-name>
<ejb-class>com.acision.router.DispatcherBean</ejb-class>
<messaging-type>javax.jms.MessageListener</messaging-type>
<transaction-type>Container</transaction-type>
<message-destination-type>javax.jms.Queue</message-destination-type>
<message-destination-link>RouterEventsQueue</message-destination-link>
<!-- Allow the connection factory to be looked up via
java:comp/env/SimpleRouterConnectionFactory -->
<resource-ref>
<res-ref-name>RouterConnectionFactory</res-ref-name>
<res-type>javax.jms.ConnectionFactory</res-type>
</resource-ref>
<!-- Allow the reply queue to looked up via
java:comp/env/TestingQueue -->
<resource-ref>
<res-ref-name>TestingTopic</res-ref-name>
<res-type>javax.jms.Topic</res-type>
</resource-ref>
<!-- Allow the dead queue to looked up via
java:comp/env/DeadEventsQueue -->
<resource-ref>
<res-ref-name>DeadEventsQueue</res-ref-name>
<res-type>javax.jms.Queue</res-type>
</resource-ref>
</message-driven>
<!-- Configure the session bean that will be sending message to the
DispatcherBean queue,
and listening for the answer -->
<session>
<ejb-name>PutterBean</ejb-name>
<business-local>com.acision.router.tools.PutterLocal</business-local>
<ejb-class>com.acision.router.tools.PutterBean</ejb-class>
<transaction-type>Container</transaction-type>
<!-- Allow the connection factory to looked up via
java:comp/env/SimpleRouterConnectionFactory -->
<resource-ref>
<res-ref-name>RouterConnectionFactory</res-ref-name>
<res-type>javax.jms.ConnectionFactory</res-type>
</resource-ref>
<!-- Allow the reply queue to looked up via
java:comp/env/TestingTopic -->
<resource-ref>
<res-ref-name>TestingTopic</res-ref-name>
<res-type>javax.jms.Topic</res-type>
</resource-ref>
<!-- Allow the reply queue to looked up via
java:comp/env/DeadEventsQueue -->
<resource-ref>
<res-ref-name>DeadEventsQueue</res-ref-name>
<res-type>javax.jms.Queue</res-type>
</resource-ref>
<!-- Allow the destination queue to looked up via
java:comp/env/RouterEventsQueue -->
<resource-ref>
<res-ref-name>jms/RouterEventsQueue</res-ref-name>
<res-type>javax.jms.Queue</res-type>
</resource-ref>
</session>
</enterprise-beans>
<!-- define the JMS queues that we need -->
<assembly-descriptor>
<message-destination>
<message-destination-name>RouterEventsQueue</message-destination-name>
</message-destination>
<message-destination>
<message-destination-name>DeadEventsQueue</message-destination-name>
</message-destination>
<message-destination>
<message-destination-name>TestingTopic</message-destination-name>
</message-destination>
</assembly-descriptor>
</ejb-jar>
--
View this message in context: http://www.nabble.com/Setting-alternate-jndi-prefix--%28not-java%3Acomp-env%29-tp23428206p23428206.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Setting alternate jndi prefix? (not java:comp/env)
Posted by David Blevins <da...@visi.com>.
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