/**
* @param securityEnabled
* @throws ServerInstanceException
*/
public HostAndPort getHostAndPort(boolean securityEnabled) throws ServerInstanceException {
HostAndPort hAndp = null;
try {
MBeanServer mbs = MBeanServerFactory.getMBeanServer();
ObjectName objectName = new ObjectName(getDomainName()+":type=configs,category=config");
String operationName1 = "getConfig";
ObjectName[] configs = (ObjectName[])mbs.invoke(objectName,operationName1, emptyParams,emptySignature);
String configName = (String)mbs.getAttribute(configs[0], "name");
ObjectName httpService = new ObjectName(getDomainName()+":type=http-service,config="+configName+",category=config");
String operationName2 = "getHttpListener";
ObjectName[] httpListener = (ObjectName[])mbs.invoke(httpService, operationName2,emptyParams,emptySignature);
String serverName = null;
int port = 0;
for (int i = 0; i < httpListener.length; i++) {
AttributeList attrs = mbs.getAttributes(httpListener[i],
httpListenerAttrNames);
Boolean bb = Boolean.valueOf((String)getNamedAttributeValue(
attrs, LISTENER_ENABLED));
boolean enabled = ((bb == null) ? false : bb.booleanValue());
if (!enabled) {
// Listener is not enabled
continue;
}
String vs = (String)getNamedAttributeValue(attrs, DEF_VS);
if (ADMIN_VS.equals(vs)) {
// Listener is reserved for administration
continue;
}
bb = Boolean.valueOf((String)getNamedAttributeValue(
attrs, SEC_ENABLED));
boolean sec_on = ((bb == null) ? false : bb.booleanValue());
if (securityEnabled == sec_on) {
serverName = (String)getNamedAttributeValue(attrs,
SERVER_NAME);
if (serverName == null || serverName.trim().equals("")) {
serverName = getDefaultHostName();
}
String portStr = (String)getNamedAttributeValue(attrs,
PORT);
String redirPort = (String)getNamedAttributeValue(attrs,
REDIRECT_PORT);
if (redirPort != null && !redirPort.trim().equals("")) {
portStr = redirPort;
}
String resolvedPort =
new PropertyResolver(getConfigContext(),
getInstanceName()).resolve(portStr);
port = Integer.parseInt(resolvedPort);
break;
}
}
hAndp = new HostAndPort(serverName, port);
}
catch (Exception e) {
ServerInstanceException sie =
new ServerInstanceException(e.getLocalizedMessage());
sie.initCause(e);