Hi,
 
I am using the basic example and modified the code to drop the "quartz"
timer. I want to take input from a servlet which shoudl connect to a queue
called "servicemix.source". I have written the servlet JNDI and JMS code as
follows :
Context context = null;
        ConnectionFactory factory = null;
        Connection connection = null;

//  String factoryName = "JmsQueueConnectionFactory";
         String factoryName = "ConnectionFactory";
    
    String destName = "servicemix.source";

        Destination dest = null;
        int count = 1;
        Session session = null;
        MessageProducer sender = null;
        MessageConsumer receiver = null;

 try {
Hashtable properties = new Hashtable();
    properties.put(Context.INITIAL_CONTEXT_FACTORY, 
                  
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
        System.out.println("1");
    properties.put(Context.PROVIDER_URL, "tcp://localhost:61616/");
        System.out.println("2");
            // create the JNDI initial context.
            context = new InitialContext(properties);
        System.out.println("3");
            // look up the ConnectionFactory
            factory = (ConnectionFactory) context.lookup(factoryName);
        System.out.println("4");
            // look up the Destination
            dest = (Destination) context.lookup(destName);
        System.out.println("5");
            // create the connection
            connection = factory.createConnection();
        System.out.println("6");
            // create the session
            session = connection.createSession(
                false, Session.AUTO_ACKNOWLEDGE);
        System.out.println("7");
            // create the sender
            sender = session.createProducer(dest);
//receiver = session.createConsumer(dest);
        System.out.println("8");
            // start the connection, to enable message sends
            connection.start();
        System.out.println("9");

        for (int i = 0; i < count; ++i) {
                TextMessage message = session.createTextMessage();
                message.setText(information);
                sender.send(message);
            }



        } catch (JMSException e) {
         System.out.println(e); 
            e.printStackTrace();
        } catch (NamingException e) {
        System.out.println(e);
            e.printStackTrace();
        }
        catch(Exception e)
        {
        out.println(e);
        }
         finally {
            // close the context
            if (context != null) {
                try {
                    context.close();
                } catch (NamingException e) {
                        System.out.println(e);
                    e.printStackTrace();
                }
            }

            // close the connection
            if (connection != null) {
                try {
                    connection.close();
                } catch (JMSException e) {
                System.out.println(e);
                    e.printStackTrace();
                }

I started the basic example using mvn jbi:embeddedServicemix and all
components have been initialized. Now when i run the servlet i get the
following error in Tomcat which hosts my servlet
The stack trace:

javax.naming.NameNotFoundException: servicemix.source
        at
org.apache.activemq.jndi.ReadOnlyContext.lookup(ReadOnlyContext.java:215)
        at javax.naming.InitialContext.lookup(InitialContext.java:351)
        at JmsServlet.doGet(JmsServlet.java:59)
        at JmsServlet.doPost(JmsServlet.java:125)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
        at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
        at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java)

This means Servlet wasnt able to find the queue in JNDI look up. Can someone
tell me where i am going wrong and what i need to do. I searched the site of
Activemq and realised that a file named jndi.properties might be needed. But
the link is not active and i havent been able to find any such file. Can
anyone help me with this? Thanks in advance


-- 
View this message in context: 
http://www.nabble.com/Problem-with-JNDI-in-basic-example-tf4487224s12049.html#a12796088
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Reply via email to