use of com.sun.enterprise.util.HostAndPort in project Payara by payara.
the class LocalServerCommand method getAdminAddress.
/**
* Returns the admin address of a particular server. Note that this method
* should be called only when you own the server that is available on
* an accessible file system.
*
* @return HostAndPort object with admin server address
* @throws CommandException in case of parsing errors
*/
protected final HostAndPort getAdminAddress(String serverName) throws CommandException {
try {
MiniXmlParser parser = new MiniXmlParser(getDomainXml(), serverName);
List<HostAndPort> addrSet = parser.getAdminAddresses();
if (addrSet.size() > 0)
return addrSet.get(0);
else
throw new CommandException(strings.get("NoAdminPort"));
} catch (MiniXmlParserException ex) {
throw new CommandException(strings.get("NoAdminPortEx", ex), ex);
}
}
use of com.sun.enterprise.util.HostAndPort in project Payara by payara.
the class GetHostAndPortCommand method getHostAndPort.
private HostAndPort getHostAndPort(HttpService httpService, VirtualServer vs, boolean securityEnabled) {
List<VirtualServer> virtualServerList = httpService.getVirtualServer();
List<NetworkListener> httpListenerList = httpService.getParent(Config.class).getNetworkConfig().getNetworkListeners().getNetworkListener();
for (VirtualServer virtualServer : virtualServerList) {
if (!virtualServer.getId().equals(vs.getId())) {
continue;
}
String vsHttpListeners = virtualServer.getNetworkListeners();
if (vsHttpListeners == null) {
continue;
}
List<String> vsHttpListenerList = StringUtils.parseStringList(vsHttpListeners, " ,");
for (String vsHttpListener : vsHttpListenerList) {
for (NetworkListener httpListener : httpListenerList) {
if (!httpListener.getName().equals(vsHttpListener)) {
continue;
}
if (!Boolean.valueOf(httpListener.getEnabled())) {
continue;
}
final Protocol protocol = httpListener.findHttpProtocol();
if (Boolean.valueOf(protocol.getSecurityEnabled()) == securityEnabled) {
String serverName = protocol.getHttp().getServerName();
if (serverName == null || serverName.trim().equals("")) {
serverName = DeploymentCommandUtils.getLocalHostName();
}
String portStr = httpListener.getPort();
String redirPort = protocol.getHttp().getRedirectPort();
if (redirPort != null && !redirPort.trim().equals("")) {
portStr = redirPort;
}
int port = Integer.parseInt(portStr);
return new HostAndPort(serverName, port, securityEnabled);
}
}
}
}
return null;
}
use of com.sun.enterprise.util.HostAndPort in project Payara by payara.
the class GetHostAndPortCommand method execute.
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
ActionReport.MessagePart part = report.getTopMessagePart();
HttpService httpService = null;
HostAndPort hostAndPort = null;
try {
if (config == null) {
throw new Exception("No such target:" + target);
}
httpService = config.getHttpService();
if (httpService != null) {
hostAndPort = getHostAndPortForRequest(httpService);
}
} catch (Exception e) {
report.setMessage(e.getMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (hostAndPort != null) {
part.setMessage(hostAndPort.getHost() + ":" + hostAndPort.getPort());
// property for REST Access
part.addProperty("host", hostAndPort.getHost());
// property for REST Access
part.addProperty("port", "" + hostAndPort.getPort());
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of com.sun.enterprise.util.HostAndPort in project Payara by payara.
the class GetHostAndPortCommand method getHostAndPort.
private HostAndPort getHostAndPort(HttpService httpService, boolean securityEnabled) {
List<NetworkListener> httpListenerList = httpService.getParent(Config.class).getNetworkConfig().getNetworkListeners().getNetworkListener();
for (NetworkListener httpListener : httpListenerList) {
if (!Boolean.valueOf(httpListener.getEnabled())) {
continue;
}
final Protocol protocol = httpListener.findHttpProtocol();
final Http http = protocol.getHttp();
if (http.getDefaultVirtualServer().equals("__asadmin")) {
continue;
}
if (Boolean.valueOf(protocol.getSecurityEnabled()) == securityEnabled) {
String serverName = http.getServerName();
if (serverName == null || serverName.trim().equals("")) {
serverName = DeploymentCommandUtils.getLocalHostName();
}
String portStr = httpListener.getPort();
String redirPort = http.getRedirectPort();
if (redirPort != null && !redirPort.trim().equals("")) {
portStr = redirPort;
}
int port = Integer.parseInt(portStr);
return new HostAndPort(serverName, port, securityEnabled);
}
}
return null;
}
use of com.sun.enterprise.util.HostAndPort in project Payara by payara.
the class GetHostAndPortCommand method getHostAndPortForRequest.
private HostAndPort getHostAndPortForRequest(HttpService httpService) throws Exception {
if (moduleId == null) {
if (virtualServer == null) {
return getHostAndPort(httpService, securityEnabled);
} else {
VirtualServer vs = httpService.getVirtualServerByName(virtualServer);
if (vs == null) {
throw new Exception("Virtual server: " + virtualServer + " does not exist!");
}
return getHostAndPort(httpService, vs, securityEnabled);
}
}
ApplicationRef appRef = domain.getApplicationRefInTarget(moduleId, target);
List<String> vsList = null;
if (appRef != null) {
vsList = StringUtils.parseStringList(appRef.getVirtualServers(), " ,");
}
if (vsList == null) {
return getHostAndPort(httpService, securityEnabled);
}
for (String virtualServer : vsList) {
HostAndPort hp = getHostAndPort(httpService, httpService.getVirtualServerByName(virtualServer), securityEnabled);
if (hp != null) {
return hp;
}
}
return null;
}
Aggregations