Discussion:
[jboss-user] [JNDI and Naming] - Call JNDI Remotely outside of JAVA
Haitham Safi
2013-04-09 11:18:29 UTC
Permalink
Haitham Safi [https://community.jboss.org/people/haithamnor] created the discussion

"Call JNDI Remotely outside of JAVA"

To view the discussion, visit: https://community.jboss.org/message/807179#807179

--------------------------------------------------------------
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
*
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/807179#807179]

Start a new discussion in JNDI and Naming at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]
Arun Raj
2013-05-04 05:49:34 UTC
Permalink
Arun Raj [https://community.jboss.org/people/arun2arunraj] created the discussion

"Re: Call JNDI Remotely outside of JAVA"

To view the discussion, visit: https://community.jboss.org/message/811518#811518

--------------------------------------------------------------
Hi Safi,

    If you have fixed it, Can you help me to solve this same problem ? ? ?

Regards,
ArunRaj.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/811518#811518]

Start a new discussion in JNDI and Naming at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]
Loading...