0 Replies Latest reply on May 4, 2009 4:20 PM by Rajesh H

    JNDI lookup for failed!

    Rajesh H Newbie

      Hi Guys,

      When i run the application, i got the following error.

      Exception in thread "main" com.lsyas.acs.common.exception.SystemException: JNDI lookup for FluegeManager failed!
      at com.lsyas.acs.advanced.handling.db.JndiAccess.lookup(JndiAccess.java:148)
      at com.lsyas.acs.advanced.handling.db.JndiAccess.lookup(JndiAccess.java:124)
      at com.lsyas.acs.advanced.handling.db.RemoteLocator.getRemoteInstance(RemoteLocator.java:106)
      at com.lsyas.acs.advanced.handling.db.TestMain.testdatamethod(TestMain.java:27)
      at com.lsyas.acs.advanced.handling.db.TestMain.main(TestMain.java:34)
      Caused by: javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:8080 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost:8080 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:8080 [Root exception is java.net.ConnectException: Connection refused: connect]]]
      at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1562)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:634)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at com.lsyas.acs.advanced.handling.db.JndiAccess.lookup(JndiAccess.java:146)
      ... 4 more
      Caused by: javax.naming.CommunicationException: Failed to connect to server localhost:8080 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:8080 [Root exception is java.net.ConnectException: Connection refused: connect]]
      at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:274)
      at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1533)
      ... 8 more
      Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server localhost:8080 [Root exception is java.net.ConnectException: Connection refused: connect]
      at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:248)
      ... 9 more
      Caused by: java.net.ConnectException: Connection refused: connect
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(Unknown Source)
      at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
      at java.net.PlainSocketImpl.connect(Unknown Source)
      at java.net.SocksSocketImpl.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at java.net.Socket.(Unknown Source)
      at java.net.Socket.(Unknown Source)
      at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:84)
      at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:77)
      at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:244)
      ... 9 more


      I am using JBoss-4.2.3.GA

      The following files are used to get the JNDI context.

      TestMain.java
      ------------------

      public class TestMain {

      private FluegeManager manager = null;
      /**
      * @param args
      */

      public void testdatamethod() {
      RemoteLocator remoteLocator = new RemoteLocator("org.jnp.interfaces.NamingContextFactory",
      "jnp://localhost:8080",
      "org.jboss.naming:org.jnp.interfaces");
      manager = remoteLocator.getRemoteInstance(FluegeManager.class);
      List fluegedata = manager.getAll();
      System.out.println("Data Size is "+ fluegedata.size());

      }
      public static void main(String[] args) {
      TestMain testMain = new TestMain();
      testMain.testdatamethod();
      }

      }


      RemoteLocater.java
      ---------------------------

      public class RemoteLocator {
      private JndiAccess jndiAccess;

      public RemoteLocator() {
      jndiAccess = new JndiAccess();
      }

      public RemoteLocator(String initialContextFactory, String providerUrl, String urlPkgPrefixes) {
      jndiAccess = new JndiAccess(initialContextFactory, providerUrl, urlPkgPrefixes);
      }

      @SuppressWarnings({"MissingClassJavaDoc"})
      public T getRemoteInstance(Class remoteInterface) {
      return jndiAccess.lookup(remoteInterface.getSimpleName(), remoteInterface);
      }
      }

      JndiAccess.java
      ---------------------

      public class JndiAccess {
      private String initialContextFactory;
      private String providerUrl;
      private String urlPkgPrefixes;
      private InitialContext initialContext = null;

      public JndiAccess() {
      initialContextFactory = null;
      providerUrl = null;
      urlPkgPrefixes = null;
      }

      public JndiAccess(String initialContextFactory, String providerUrl, String urlPkgPrefixes) {
      this.initialContextFactory = initialContextFactory;
      this.providerUrl = providerUrl;
      this.urlPkgPrefixes = urlPkgPrefixes;
      }


      private Object lookup(String dataJndiName) {
      try {
      if (initialContext == null) {
      if (initialContextFactory != null || providerUrl != null || urlPkgPrefixes != null) {
      Hashtable<String, String> env = new Hashtable<String, String>();
      env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
      env.put(Context.PROVIDER_URL, providerUrl);
      env.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
      initialContext = new InitialContext(env);
      } else {
      initialContext = new InitialContext();
      }
      }
      return initialContext.lookup(dataJndiName);
      } catch (NamingException e) {
      throw new SystemException("JNDI lookup for " + dataJndiName + " failed!", e);
      }
      }
      }


      Please help me.