1 Reply Latest reply on May 4, 2013 1:49 AM by arun2arunraj

    Call JNDI Remotely outside of JAVA

    haithamnor

      Hi expert,

      I create JAR file for class in eclipse like:

       

      Package Haitham

      import java.io.IOException;

      import java.net.URISyntaxException;

      import java.rmi.RemoteException;

      import java.util.Properties;

      import java.util.logging.Logger;

      import javax.jms.Connection;

      import javax.jms.ConnectionFactory;

      import javax.jms.JMSException;

      import javax.jms.MessageProducer;

      import javax.jms.Session;

      import javax.jms.TextMessage;

      import javax.naming.Context;

      import javax.naming.InitialContext;

      import javax.naming.NamingException;

       

      public class TracingMessages

      {

       

                public static void main(String[] args)

                {

       

                }

                public static String SendMessages(String Queuename,String msg) throws IOException, URISyntaxException

      {

                                               

                          String body="";

       

                                  try

                                  {

                                                Context init =TracingMessages.getInitialContext();

                                            javax.jms.Queue destination =        (javax.jms.Queue) init.lookup("/queue/" +Queuename);

                                                 ConnectionFactory connectionFactory =   (ConnectionFactory) init.lookup("ConnectionFactory");

                                        Connection connection = connectionFactory.createConnection();//

                                      

                                        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

                                    

                                        MessageProducer producer = session.createProducer(destination);

                                                

                                       

                                        TextMessage message = session.createTextMessage();

                                        message.setText(msg );

                                     

                                        connection.start();

                                        System.out.println("connect strat");

                                        producer.send(message);

                                      

                                        body = message.getText();

                                     

                                        session.close();

                                        connection.close();

       

       

                                    }

                                  catch (Exception e)

                                    {

                                        return(e.toString());

                                    }

       

       

                              return body    ;

                             

                          }

       

      public static Context getInitialContext () throws JMSException,NamingException,RemoteException

                {

                          Properties prop = new Properties();

                    prop.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");

                          prop.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");

                          prop.setProperty("java.naming.provider.url", "jnp://127.0.0.1:1099");

       

       

                          Context context = new InitialContext(prop);

       

                          return context;}

       

      Then i converts JAR file to DLL after that i used in VISUAL STUDIO 2012 to send message to Jboss 4.2.3 ,it is worning Well if i used inside WINDOWS APPLICATION

      but

      if i used the same DLL class inside web application i got the follwoing error:

       

      ** javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory**

      why??????

      any one have idea?

      Thanks in advanced