0 Replies Latest reply on Apr 30, 2012 4:48 PM by gyarbrough

    JBOSS Management API

    gyarbrough

      Executing a short timeframe project that requires accessing management data for several JBOSS AS servers.

      Development environment is Windows XP SP3, NetBeans 7.1.1, Java 1.6 EE

      JBOSS 7.1.1 Final installed from zip

       

      I got the following example code from an Inet site. It seems to agree with the API doc, but it doesn't work for me. Continuing to get the following error:

      Exception: java.net.ConnectException: JBAS012144: Could not connect to remote://localhost:9999. The connection timed out

       

      Note that the intended production version will be much more extensive than this test. But since the test doesn't work yet.....

      We're running standalone for testing. I've adjusted the standalone.xml file to include the native interface. netstat shows both ports 9990 and 9999 as active in listening mode. I can telnet and connect to both ports....

       

      Some help forum suggested I needed the CallBack in order to handle userid/password logon. However neither of the "client" statements makes any difference as regards the error. The error occurs on the 

      ModelNode returnVal = client.execute(op);

      statement.

       

      Running loopback precludes a sniffer, so I can't see what, if anything, is being written to the "wire".

       

       

       

      public class JBossCLI {

       

          
          static String host = "localhost";
          static String password = "wally";

          static String userid = "wally99";  


          public static void main (String[] args) {

          ModelControllerClient client = null;       
          try {
            client = ModelControllerClient.Factory.create(InetAddress.getByName("localhost"), 9999);
      //    client = createClient (InetAddress.getByName(host), 9999, userid, password.toCharArray(), "ManagementRealm" );
          }

          catch ( UnknownHostException uhe) {
          System.out.println("UHE: " + uhe.getMessage());
      }

       

      try {
            ModelNode op = new ModelNode();
            op.get("operation").set("read-resource-description");
            ModelNode address = op.get("address");
            address.add("subsystem", "web");
            address.add("connector", "http");
       
            op.get("recursive").set(true);
            op.get("operations").set(true);

       

            ModelNode returnVal = client.execute(op);
            System.out.println(returnVal.get("result").toString());

             
            if (client != null ) client.close();
      }

      catch (Exception e) {
            System.out.println ("Exception: " + e.getMessage());
           }

      }


         
      static ModelControllerClient createClient (final InetAddress host, final int port, 
                        final String username, final char[] password, final String securityRealmName)
          {
       
          final CallbackHandler callbackHandler = new CallbackHandler() {
       
              public void handle(Callback[] callbacks) throws IOException,
                      UnsupportedCallbackException {
                 
                  for (Callback current : callbacks) {
                      if (current instanceof NameCallback) {
                          NameCallback ncb = (NameCallback) current;
                          ncb.setName(username);
                      } else if (current instanceof PasswordCallback) {
                          PasswordCallback pcb = (PasswordCallback) current;
      //                    pcb.setPassword(password.toCharArray());
                             pcb.setPassword(password);
                      } else if (current instanceof RealmCallback) {
                          RealmCallback rcb = (RealmCallback) current;
                          rcb.setText(rcb.getDefaultText());
                      } else {
                          throw new UnsupportedCallbackException(current);
                      }
                  }
              }
          };
               
          return ModelControllerClient.Factory.create(host, port, callbackHandler);
          }
      }