activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xy_wen <wxy2...@hotmail.com>
Subject Exception occur when JNDI lookup
Date Thu, 06 Dec 2007 06:31:50 GMT

I am using tomcat 5.5 with Activemq 4.1.1.I have written a simple test
example to get the connectfatory and topic information using JNDI.
this is my test client:
         InitialContext iniContxt = new InitialContext();
         Context contxt = (Context)
iniContxt.lookup("java:comp/env/jmsConnectionFactory");
         ActiveMQConnectionFactory factory =
(ActiveMQConnectionFactory)iniContxt.lookup("jmsConnectionFactory");
         connection = factory.createConnection();
        session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
        sender =
session.createProducer((Topic)iniContxt.lookup("jmsreMsgTopic"));
        sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
But there is a exception when excute "Context contxt = (Context)
iniContxt.lookup("java:comp/env/jmsConnectionFactory");"
The exception is :
Exception in thread "main" javax.naming.NamingException: scheme java not
recognized
	at
org.apache.activemq.jndi.ReadOnlyContext.lookup(ReadOnlyContext.java:199)
	at javax.naming.InitialContext.lookup(InitialContext.java:392)
	at SentRequestMessage.run(SentRequestMessage.java:49)
	at SentRequestMessage.main(SentRequestMessage.java:43)

I added such code in the web.xml document:
 <resource-ref>
  		<description>jndi for activemq</description>
  		<res-ref-name>jmsConnectionFactory</res-ref-name>
  		<res-type>org.apache.activemq.ActiveMQConnectionFactory</res-type>
  		<res-auth>Container</res-auth>
	</resource-ref>
	 <resource-ref>
  		<description>jndi for activemq</description>
  		<res-ref-name>jmsreMsgTopic</res-ref-name>
  		<res-type>org.apache.activemq.command.ActiveMQTopic</res-type>
  		<res-auth>Container</res-auth>
	</resource-ref>
	<resource-ref>
  		<description>jndi for activemq</description>
  		<res-ref-name>jmsreMsgControl</res-ref-name>
  		<res-type>org.apache.activemq.command.ActiveMQTopic</res-type>
  		<res-auth>Container</res-auth>
	</resource-ref>

and create a context.xml at the application webcontent/meta-info.
<Context antiJARLocking="true">
    <Resource
        name="jmsConnectionFactory"
        auth="Container"
        type="org.apache.activemq.ActiveMQConnectionFactory"
        description="JMS Connection Factory"
        factory="org.apache.activemq.jndi.JNDIReferenceFactory"
        brokerURL="tcp://localhost:61616"
        brokerName="LocalActiveMQBroker"
        useEmbeddedBroker="false"/>

    <Resource name="jmsreMsgTopic"
        auth="Container"
        type="org.apache.activemq.command.ActiveMQTopic"
        factory="org.apache.activemq.jndi.JNDIReferenceFactory"
        physicalName="requestmessage_topic"/>
    <Resource name="jmsreMsgControl"
        auth="Container"
        type="org.apache.activemq.command.ActiveMQTopic"
        factory="org.apache.activemq.jndi.JNDIReferenceFactory"
        physicalName="requestmessage_control"/>
    <!--Resource name="jms/queue/MyQueue"
        auth="Container"
        type="org.apache.activemq.command.ActiveMQQueue"
        factory="org.apache.activemq.jndi.JNDIReferenceFactory"
        physicalName="MY.TEST.FOO.QUEUE"/-->
</Context>

Any one can help me ?? Thanks

-- 
View this message in context: http://www.nabble.com/Exception-occur-when-JNDI-lookup-tf4954290s2354.html#a14187093
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message