3 Replies Latest reply on Dec 16, 2016 4:41 AM by Wolfgang Mayer

    javax.naming.CommunicationException: Receive timed out

    fhighlander Newbie

      I'm trying to lookup a EJB deployed on Wildfly 10, but I'm getting this exception:

       

      Could not obtain connection to any of these urls: jnp://localhost:1099  and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]

       

      Through console inside Eclipse IDE, I can see this information:

       

      18:00:06,937 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-3) WFLYEJB0473: JNDI bindings for session bean named 'MyProducer' in deployment unit 'deployment "test.war"' are as follows:

        java:global/test/MyProducer!foo.bar.MyProducer

        java:app/test/MyProducer!foo.bar.MyProducer

        java:module/MyProducer!foo.bar.MyProducer

        java:global/test/MyProducer

        java:app/test/MyProducer

        java:module/MyProducer

       

      So I assume that my EJB is deployed correctly. But using this code to do the lookup, I got aforementioned exception.

       

      public static void main(String[] args) {

        try{

        Properties properties = new Properties();

        properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");

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

        properties.put("java.naming.provider.url", "jnp://localhost:1099 ");

        InitialContext ic = new InitialContext(properties);

        MyProducer producer = (MyProducer) ic.lookup("java:global/test/MyProducer");

        ic.close();

        producer.enqueue("teste");

        System.out.println("Funcionou...");

        } catch(Exception e){

        System.out.println(e.getMessage());

        }

      }

       

      Any ideas?

        • 1. Re: javax.naming.CommunicationException: Receive timed out
          Wolfgang Mayer Master

          The remote access to the ejbs changed in WildFly.

           

          The propties section should now look like this:

           

                      Properties jndiProperties = new Properties();

                      jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

                      jndiProperties.put(Context.PROVIDER_URL, "http-remoting://" + ${host} + ":" + ${port});

                      jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

                     

                      jndiProperties.put(Context.SECURITY_PRINCIPAL, ${userName});

                     

                      jndiProperties.put(Context.SECURITY_CREDENTIALS, ${password});

           

                      // This is an important property to set if you want to do EJB invocations via the remote-naming project

                      jndiProperties.put("jboss.naming.client.ejb.context", "true");

           

                      // create a context passing these properties

                      remotingContext = new InitialContext(jndiProperties);

           

          The standard port number is 8080 and the standard host is localhost.

           

          Syntax for ejbs is: ${appName}/${moduleName}/${beanName}!${remoteView}

                  // appName = name of EAR deployment (or empty for single EJB/WAR deployments)

                  // moduleName = name of EJB/WAR deployment

                  // beanName = name of the EJB (Simple name of EJB class)

                  // remoteView = fully qualified remote interface class

          for example:  lookup(TestRemoteJNDI/TestRemoteJNDI-ejb/CalculateBean!ejb.CalculateBeanRemote)

           

          I' suggest to check the GitHub - wildfly/quickstart: Holds all versioned docs & samples for more details.

          • 2. Re: javax.naming.CommunicationException: Receive timed out
            fhighlander Newbie

            Wolfgang, thanks for your reply.

             

            I already tried using quickstart example and I got this message:

             

            javax.naming.NoInitialContextException: Cannot instantiate class: org.jboss.naming.remote.client.InitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory]

             

            I googled about this issue, but this solution didn't work out.

             

            Any other idea?

            • 3. Re: javax.naming.CommunicationException: Receive timed out
              Wolfgang Mayer Master

              You should add the jboss-remote-naming-2.0.4.Final.jar