7 Replies Latest reply on Nov 24, 2015 9:50 PM by fernandorb_8

    Client timeout for JNDI lookup, JBoss-7.1.1.Final

    kparasam

      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
          wdfink

          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
            kparasam

            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
              ybxiang.china

              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;
              log.info("现在连接服务器...");
              try{
              //下面的XNIO的TCP连接失败异常被它自己吞没了,没有抛出,我们无法判定XNIO是否连接成功。
              //只能通过Socket来测试
              Socket clientSocket = new Socket(serverIP,4447);
              //Socket clientSocket =     new  Socket(InetAddress.getByName(serverIP), 4447);
              clientSocket.close();
              }catch(Exception e){
              log.error("client socket could NOT be connected to server.",e);
              throw ConnectionToServerFailedException.INSTANCE;
              }
              try{ 
              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.setSelector(selector);
              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;
              }
              //
              if(securedRemoteSessionProxy==null){
              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
                wdfink

                Xiang,

                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
                  kparasam

                  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

                    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
                      fernandorb_8

                      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.