InitialContext.lookup returns null for default ConnectionFac
mark_a_loper Mar 29, 2006 8:41 AMHi, I'm hoping this is an easy fix, I think it has to do with Configuration, but I can't find anything to answer the question. I'm trying to set up a simple servlet that dump text into the topic/testTopic topic that is configured on JBoss 4.0.4RC1. I've pretty much pulled the code out of Ch6 of the documentation and adjusted it for Web App use. See Source:
public void setupPubSub() throws JMSException, NamingException { InitialContext iniCtx = new InitialContext(); TopicConnectionFactory tcf = (TopicConnectionFactory)iniCtx.lookup("java:comp/env/jms/ConnectionFactory"); if (tcf == null) System.out.println("tcf is null"); else System.out.println("tcf is NOT null"); conn = tcf.createTopicConnection(); topic = (Topic) iniCtx.lookup("java:comp/env/jms/testTopic"); if (topic == null) System.out.println("topic is null"); else System.out.println("topic is NOT null"); session = conn.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); conn.start(); }
A NullPointerException is thrown at:
conn = tcf.createTopicConnection();
The "if" block directly above it confirms that tcf is indeed null. Originally I had been having problems getting the naming correct through the jboss-web.xml, and web.xml, however that all seems to be working now. FYI: the "topic" returned is not null, so I know that call works anyway.
It seems that I am getting the naming correct, but for some reason the object returned by the lookup is null. Help please.
web.xml (parts):
<resource-ref> <description> Testing the reference info for a TopicConnection Factory </description> <res-ref-name>jms/ConnectionFactory</res-ref-name> <res-type>javax.jms.TopicConnectionFactory</res-type> <res-auth>Container</res-auth> </resource-ref> <resource-env-ref> <resource-env-ref-name>jms/testTopic</resource-env-ref-name> <resource-env-ref-type>javax.jms.Topic</resource-env-ref-type> </resource-env-ref>
jboss-web.xml:
<jboss-web> <!-- Jboss web XML file to set mapping for JMS to test topic --> <resource-ref> <res-ref-name>jms/ConnectionFactory</res-ref-name> <res-type>javax.jms.TopicConnectionFactory</res-type> <jndi-name>java:ConnectionFactory</jndi-name> </resource-ref> <resource-env-ref> <resource-env-ref-name>jms/testTopic</resource-env-ref-name> <jndi-name>java:topic/testTopic</jndi-name> </resource-env-ref> </jboss-web>
Thanks,
Mark Loper
mark_a_loper@yahoo.com