2 Replies Latest reply on Apr 21, 2015 4:07 AM by ehugonnet

    java.io.IOException: java.net.ConnectException: JBAS012144: Could not connect to remote://127.0.0.1:9990. The connection timed out

    Jessie Ling Newbie

      User ModelControllerClient to create a queue, the related code as following, when deploy the war to wildfly, it always report connection timeout(remote://127.0.0.1:9990) error. Can anyone help on this? The username and password is added by command add-user.bat.

       

      @Inject
      private Logger logger;
      @Resource(mappedName = "java:/ConnectionFactory")
      private ConnectionFactory cf;

      @PostConstruct

      public void initializeEndpoints() {
        for (int i = 0; i < 5; i++) {
         String queueName = "endpoint" + Integer.toString(i);
         String jndiName = "java:/" + queueName;
         try {
          createQueue(queueName, jndiName);
         } catch (Exception e) { // TODO Auto-generated catch block
          System.out.println("create endpoint queue error");
          e.printStackTrace();
         }
        }
      }

       

      private void createQueue(String queueName, String jndiName)
         throws Exception { 
        Authentication auth = new Authentication("user01", "user01");
        ModelControllerClient client = ModelControllerClient.Factory.create(
          "127.0.0.1", 9990, auth.getCallbackHandler());

        jndiName = jndiName.replaceFirst("/", "");
        ModelNode operation = new ModelNode();
        operation.get("operation").set("read-resource");
        operation.get("address").add("subsystem", "messaging");
        ModelNode result = client.execute(operation, null);
        if (!result.get("result").get("jms-queue").toString()
          .contains("\"" + queueName + "\"")) {
         operation = new ModelNode();
         operation.get("operation").set("add");
         operation.get("address").add("subsystem", "messaging");
         operation.get("address").add("jms-queue", queueName);
         operation.get("entries").add("queue/" + jndiName);
         client.executeAsync(operation, null);
        }

        client.close();
      }

       

      Here is the class authentication code, just use the code :

      import java.io.IOException;

      import javax.security.auth.callback.Callback;
      import javax.security.auth.callback.NameCallback;
      import javax.security.auth.callback.PasswordCallback;
      import javax.security.auth.callback.UnsupportedCallbackException;
      import javax.security.sasl.RealmCallback;

      public class Authentication {
      public static String username = "";
          public static String password = "";

          public Authentication(String user, String password){
           this.username = user;
           this.password = password;
          }
          public CallbackHandler getCallbackHandler() {
              return new CallbackHandler();
          }

          public class CallbackHandler implements javax.security.auth.callback.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());
                      } else if (current instanceof RealmCallback) {
                          RealmCallback rcb = (RealmCallback) current;
                          rcb.setText(rcb.getDefaultText());
                      } else {
                          throw new UnsupportedCallbackException(current);
                      }
                  }
              }
          }
      }

       

       

      When deploy the war on Wildfly, it report error as following:

       

      2015-04-20 18:12:57,037 INFO  [stdout] (ServerService Thread Pool -- 174) create endpoint queue error

      2015-04-20 18:12:57,037 ERROR [stderr] (ServerService Thread Pool -- 174) java.io.IOException: java.net.ConnectException: JBAS012144: Could not connect to remote://127.0.0.1:9990. The connection timed out

      2015-04-20 18:12:57,037 ERROR [stderr] (ServerService Thread Pool -- 174)  at org.jboss.as.controller.client.impl.AbstractModelControllerClient.executeForResult(AbstractModelControllerClient.java:129)

      2015-04-20 18:12:57,037 ERROR [stderr] (ServerService Thread Pool -- 174)  at org.jboss.as.controller.client.impl.AbstractModelControllerClient.execute(AbstractModelControllerClient.java:81)

      2015-04-20 18:12:57,037 ERROR [stderr] (ServerService Thread Pool -- 174)  at com.ericsson.queueService.EndpointManager.createQueue(EndpointManager.java:61)

      2015-04-20 18:12:57,037 ERROR [stderr] (ServerService Thread Pool -- 174)  at com.ericsson.queueService.EndpointManager.initializeEndpoints(EndpointManager.java:43)

      2015-04-20 18:12:57,037 ERROR [stderr] (ServerService Thread Pool -- 174)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      2015-04-20 18:12:57,037 ERROR [stderr] (ServerService Thread Pool -- 174)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

      2015-04-20 18:12:57,037 ERROR [stderr] (ServerService Thread Pool -- 174)  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

      2015-04-20 18:12:57,037 ERROR [stderr] (ServerService Thread Pool -- 174)  at java.lang.reflect.Method.invoke(Method.java:497)

      ..................................