*/
private String testModelControllerClient(HashMap<String, String> fallbackProps) throws Exception {
String host = this.installerConfiguration.getManagementHost();
int port = this.installerConfiguration.getManagementPort();
ModelControllerClient mcc = null;
CoreJBossASClient client;
String asVersion;
try {
mcc = ModelControllerClient.Factory.create(host, port);
client = new CoreJBossASClient(mcc);
Properties sysprops = client.getSystemProperties();
if (!sysprops.containsKey("rhq.server.database.connection-url")) {
throw new Exception("Not an RHQ Server");
}
asVersion = client.getAppServerVersion();
return asVersion;
} catch (Exception e) {
try {
mcc.close(); // so we don't leak threads
mcc = null;
} catch (IOException ignore) {
}
// if the caller didn't give us any fallback props, just immediately fail
if (fallbackProps == null) {
throw new Exception("Cannot obtain client connection to the RHQ app server", e);
}
try {
// try the host/port as specified in the fallbackProps
// if the host/port in the fallbackProps are the sames as the ones we tried above,
// don't bother trying again
boolean differentValues = false;
String hostStr = fallbackProps.get("jboss.bind.address.management");
if (hostStr != null && hostStr.length() > 0 && !hostStr.equals(host)) {
host = hostStr;
// BZ 1141175 - if binding address is "all addresses", then use 127.0.0.1 because 0.0.0.0 can't be used by the client
if (host.equals("0.0.0.0")) {
host = "127.0.0.1";
}
differentValues = true;
}
String portStr = fallbackProps.get("jboss.management.native.port");
if (portStr != null && !portStr.equals(String.valueOf(port))) {
port = Integer.parseInt(portStr);
differentValues = true;
}
if (!differentValues) {
throw new Exception("Cannot obtain client connection to the RHQ app server!", e);
}
mcc = ModelControllerClient.Factory.create(host, port);
client = new CoreJBossASClient(mcc);
Properties sysprops = client.getSystemProperties();
if (!sysprops.containsKey("rhq.server.database.connection-url")) {
throw new Exception("Not an RHQ Server");
}
asVersion = client.getAppServerVersion();
this.installerConfiguration.setManagementHost(host);
this.installerConfiguration.setManagementPort(port);
return asVersion;
} catch (Exception e2) {
// make the cause the very first exception in case it was something other than bad host/port as the problem