7 Replies Latest reply on Nov 24, 2015 9:50 PM by Fernando Reyes Bejarano

    Client timeout for JNDI lookup, JBoss-7.1.1.Final

    Kaushik Parasam Newbie

      Hi, I need to have a quick way to check if a host is reachable via JNDI (Host is down or an invalid IP or virtual IP is wrongly configured - any such cases). I tried the following timeout settings, but none worked when doing a JNDI lookup. Any other ideas ?

      1. envProp.put("jboss.naming.client.connect.timeout", 2000);

      2. envProp.put("remote.connection.default.connect.timeout", 2000);

      3. envProp.put("jnp.socketFactory", "org.jnp.interfaces.TimedSocketFactory");

          envProp.put("jnp.timeout", 2000);

          envProp.put("jnp.sotimeout", 2000);

        • 1. Re: Client timeout for JNDI lookup, JBoss-7.1.1.Final
          Wolf-Dieter Fink Master

          The "jnp.*" properties are old (for AS4/5)

          How your lookup code look like?

          • 2. Re: Client timeout for JNDI lookup, JBoss-7.1.1.Final
            Kaushik Parasam Newbie

            Ok. Here's my code:


            envProp.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

            envProp.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

            envProp.setProperty(Context.PROVIDER_URL, connectToHost);

            envProp.put(Context.SECURITY_PRINCIPAL, appUser);

            envProp.put(Context.SECURITY_CREDENTIALS, appPwd);


            InitialContext initialContext = new InitialContext(envProp);

            Object conObject = initialContext.lookup("jms/RemoteConnectionFactory");


            As an update, I tested some scenarios today.

            1. If its a VIP(Virtual IP), then the client code would immediately know the server(s) are down.

            2. If its a actual host IP and its down, then it would take ~5 seconds (consistently). There must be some setting for this I believe.

            3. If its not a valid IP then it would take really long to get the response, or it doesn't ? I didn't wait.


            Any thoughts.

            • 3. Re: Client timeout for JNDI lookup, JBoss-7.1.1.Final
              xiang yingbing Master

              You should use:

                            p.put("remote.connection.default.connect.timeout", "30000");//for xnio


              public void connectToServer(String serverIP, String username, String password) throws Exception{
              this.username = username;//握手过程中,可能会检测到密码过期,要求用户重新设置密码。
              this.serverIP = serverIP;
              InitialContext context;
              Socket clientSocket = new Socket(serverIP,4447);
              //Socket clientSocket =     new  Socket(InetAddress.getByName(serverIP), 4447);
              }catch(Exception e){
              log.error("client socket could NOT be connected to server.",e);
              throw ConnectionToServerFailedException.INSTANCE;
              Properties p = new Properties();
              p.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "true");
              p.put("remote.connections", "default");
              p.put("remote.connection.default.host", serverIP);
              p.put("remote.connection.default.port", "4447");
              p.put("remote.connection.default.username", username);
              p.put("remote.connection.default.password", password);
              p.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
              p.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER");
              p.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
              p.put("remote.connection.default.connect.options.org.xnio.Options.SSL_STARTTLS", "true");
              p.put("remote.connection.default.connect.timeout", "30000");//for xnio
              //p.put("remote.connection.default.callback.handler.class", "com.wefend.services.authentication.DelegatingCallbackHandler");//JAAS LOGIN callback


              EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(p);
              ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(cc);
              EJBClientContext.getCurrent().registerInterceptor(0,new ClientSessionTokenInterceptor());
              EJBClientContext.getCurrent().registerInterceptor(1,new ClientExceptionInterceptor());
              Properties props = new Properties();
              props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
              context = new InitialContext(props);
              securedRemoteSessionProxy = (ISecuredRemoteSession)context.lookup(jndiName);
              }catch(Exception e){
              throw ConnectionToServerFailedException.INSTANCE;
              log.error("securedRemoteSessionProxy 不应为空!");
              throw ConnectionToServerFailedException.INSTANCE;


              shakeHands(username, password);
              initJmsResource(serverIP, username, password);


              • 4. Re: Client timeout for JNDI lookup, JBoss-7.1.1.Final
                Wolf-Dieter Fink Master


                this properties are used for EJBClient configuration and it is not possible to use it as IC for lookup other stuff, like a JMS factory here.

                • 5. Re: Client timeout for JNDI lookup, JBoss-7.1.1.Final
                  Kaushik Parasam Newbie

                  That didn't work either, I already tried it - envProp.put("remote.connection.default.connect.timeout", 2000);


                  Is there any other way ? The client would wait for 5+ seconds each time if it fails to connect and this would impact a lot on performance, since I'm making lots of remote calls from client. Please reply.

                  • 6. Re: Client timeout for JNDI lookup, JBoss-7.1.1.Final
                    jaikiran pai Master

                    You are using remote-naming project for the lookups. The correct timeout property for that is mentioned in your other thread here Re: Source code for - org.jboss.naming.remote.client.InitialContextFactory - jboss 7.1.1.Final

                    • 7. Re: Client timeout for JNDI lookup, JBoss-7.1.1.Final
                      Fernando Reyes Bejarano Newbie

                      The correct property is

                      props.put("jboss.naming.client.connect.timeout", "10000");

                      Notice that the parameter is in quotes. That's why yours wasn't working.