users@glassfish.java.net

Remote client for JMS

From: <glassfish_at_javadesktop.org>
Date: Thu, 20 May 2010 18:51:00 PDT

Hi All,

  Anybody please post a good example of jms connectivity (USING remote JNDI).

I got fed up with this error


Could not create JNDI API context: javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.appserv.naming.S1ASCtxFactory [Root exception is java.lang.ClassNotFoundException: com.sun.appserv.naming.S1ASCtxFactory]


piece of the code
 public static void main(String[] args) {
                String queueName = null;
                Context jndiContext = null;
                QueueConnectionFactory queueConnectionFactory = null;
                QueueConnection queueConnection = null;
                QueueSession queueSession = null;
                Queue queue = null;
                QueueSender queueSender = null;
                TextMessage message = null;
                final int NUM_MSGS;
                
               
                queueName = new String("tests.queue");
                System.out.println("Queue name is " + queueName);
               
                    NUM_MSGS = 1;
               
                
                    Hashtable properties = new Hashtable(2);
            properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.appserv.naming.S1ASCtxFactory");
          // properties.put(Context.PROVIDER_URL, "iiop://127.0.0.1:3700");
                     
               // properties.put(Context.INITIAL_CONTEXT_FACTORY,
                            // "com.sun.jndi.cosnaming.CNCtxFactory");
                    properties.put(Context.PROVIDER_URL, "iiop://127.0.0.1:3700/");

                  // properties.put("MyConnectionFactory","javax.jms.ConnectionFactory");

                /*
                 * Create a JNDI API InitialContext object if none exists
                 * yet.
                 */
                try {
                        //ConnectionFactory f = new com.sun
                        jndiContext = new InitialContext(properties);
                        System.out.println("Testing over here");
                        queueConnectionFactory = (QueueConnectionFactory)jndiContext.lookup("jms/MyConnectionFactory");
                } catch (NamingException e) {
                    System.out.println("Could not create JNDI API " +
                        "context: " + e.toString());
                    System.exit(1);
                }
[Message sent by forum member 'manigovindarajulu']

http://forums.java.net/jive/thread.jspa?messageID=470819