use of org.glassfish.config.support.PropertyResolver in project Payara by payara.
the class GetApplicationLaunchURLsCommand method getURLsForServer.
private List<URL> getURLsForServer(Server server, String appName, String contextRoot, Logger logger) {
List<URL> serverURLs = new ArrayList<URL>();
String virtualServers = server.getApplicationRef(appName).getVirtualServers();
if (virtualServers == null || virtualServers.trim().equals("")) {
return serverURLs;
}
String nodeName = server.getNodeRef();
String host = null;
if (nodeName != null) {
Node node = domain.getNodeNamed(nodeName);
host = node.getNodeHost();
}
if (host == null || host.trim().equals("") || host.trim().equalsIgnoreCase("localhost")) {
host = DeploymentCommandUtils.getLocalHostName();
}
List<String> vsList = StringUtils.parseStringList(virtualServers, " ,");
Config config = domain.getConfigNamed(server.getConfigRef());
HttpService httpService = config.getHttpService();
for (String vsName : vsList) {
VirtualServer vs = httpService.getVirtualServerByName(vsName);
String vsHttpListeners = vs.getNetworkListeners();
if (vsHttpListeners == null || vsHttpListeners.trim().equals("")) {
continue;
}
List<String> vsHttpListenerList = StringUtils.parseStringList(vsHttpListeners, " ,");
List<NetworkListener> httpListenerList = config.getNetworkConfig().getNetworkListeners().getNetworkListener();
for (String vsHttpListener : vsHttpListenerList) {
for (NetworkListener httpListener : httpListenerList) {
if (!httpListener.getName().equals(vsHttpListener)) {
continue;
}
if (!Boolean.valueOf(httpListener.getEnabled())) {
continue;
}
Protocol protocol = httpListener.findHttpProtocol();
// Do not include jk enabled listeners
if (Boolean.valueOf(protocol.getHttp().getJkEnabled())) {
continue;
}
boolean securityEnabled = Boolean.valueOf(protocol.getSecurityEnabled());
String proto = (securityEnabled ? "https" : "http");
String portStr = httpListener.getPort();
String redirPort = protocol.getHttp().getRedirectPort();
if (redirPort != null && !redirPort.trim().equals("")) {
portStr = redirPort;
}
// we need to resolve port for non-DAS instances
if (!DeploymentUtils.isDASTarget(server.getName())) {
PropertyResolver resolver = new PropertyResolver(domain, server.getName());
portStr = resolver.getPropertyValue(portStr);
}
try {
int port = Integer.parseInt(portStr);
URL url = new URL(proto, host, port, contextRoot);
serverURLs.add(url);
} catch (Exception ee) {
logger.log(Level.WARNING, ee.getMessage(), ee);
}
}
}
}
return serverURLs;
}
use of org.glassfish.config.support.PropertyResolver in project Payara by payara.
the class IiopFolbGmsClient method resolvePort.
private int resolvePort(Server server, IiopListener listener) {
fineLog("resolvePort: server {0} listener {1}", server, listener);
IiopListener ilRaw = GlassFishConfigBean.getRawView(listener);
fineLog("resolvePort: ilRaw {0}", ilRaw);
PropertyResolver pr = new PropertyResolver(domain, server.getName());
fineLog("resolvePort: pr {0}", pr);
String port = pr.getPropertyValue(ilRaw.getPort());
fineLog("resolvePort: port {0}", port);
return Integer.parseInt(port);
}
use of org.glassfish.config.support.PropertyResolver in project Payara by payara.
the class InstanceReaderImpl method getListeners.
/**
* Enlists both http and https listeners of this server instance
* It will be form "http:<hostname>:<port> https:<hostname>:<port>"
*
* @return String Listener(s) info.
*/
@Override
public String getListeners() throws LbReaderException {
StringBuffer listenerStr = new StringBuffer();
Config config = _domain.getConfigNamed(_server.getConfigRef());
NetworkConfig networkConfig = config.getNetworkConfig();
Protocols protocols = networkConfig.getProtocols();
NetworkListeners nls = networkConfig.getNetworkListeners();
Iterator<NetworkListener> listenerIter = nls.getNetworkListener().iterator();
int i = 0;
PropertyResolver resolver = new PropertyResolver(_domain, _server.getName());
while (listenerIter.hasNext()) {
NetworkListener listener = listenerIter.next();
NetworkListener rawListener = GlassFishConfigBean.getRawView(listener);
if (rawListener.getName().equals(ADMIN_LISTENER)) {
continue;
}
String prot = rawListener.getProtocol();
Protocol protocol = protocols.findProtocol(prot);
if (i > 0) {
// space between listener names
listenerStr.append(' ');
}
i++;
if (Boolean.valueOf(protocol.getHttp().getJkEnabled())) {
listenerStr.append(AJP_PROTO);
} else {
if (Boolean.valueOf(protocol.getSecurityEnabled()).booleanValue()) {
listenerStr.append(HTTPS_PROTO);
} else {
listenerStr.append(HTTP_PROTO);
}
}
String hostName = getResolvedHostName(rawListener.getAddress());
listenerStr.append(hostName);
listenerStr.append(':');
// resolve the port name
String port = rawListener.getPort();
// If it is system variable, resolve it
if ((port != null) && (port.length() > 1) && (port.charAt(0) == '$') && (port.charAt(1) == '{') && (port.charAt(port.length() - 1) == '}')) {
String portVar = port.substring(2, port.length() - 1);
port = resolver.getPropertyValue(portVar);
if (port == null) {
throw new LbReaderException(LbLogUtil.getStringManager().getString("UnableToResolveSystemProperty", portVar, _server.getName()));
}
}
listenerStr.append(port);
}
return listenerStr.toString();
}
use of org.glassfish.config.support.PropertyResolver in project Payara by payara.
the class ServerHelper method translateAddressAndPort.
/**
* @param adminListener
* @param server
* @param config
* @return ret[0] == address, ret[1] == port
*/
private static String[] translateAddressAndPort(NetworkListener adminListener, Server server, Config config) {
NetworkListener adminListenerRaw = null;
String[] ret = new String[2];
String portString = null;
String addressString = null;
try {
Dom serverDom = Dom.unwrap(server);
Domain domain = serverDom.getHabitat().getService(Domain.class);
adminListenerRaw = GlassFishConfigBean.getRawView(adminListener);
portString = adminListenerRaw.getPort();
addressString = adminListenerRaw.getAddress();
PropertyResolver resolver = new PropertyResolver(domain, server.getName());
if (isToken(portString))
ret[1] = resolver.getPropertyValue(portString);
else
ret[1] = portString;
if (isToken(addressString))
ret[0] = resolver.getPropertyValue(addressString);
else
ret[0] = addressString;
} catch (ClassCastException e) {
// jc: workaround for issue 12354
// TODO severe error
ret[0] = translatePortOld(addressString, server, config);
ret[1] = translatePortOld(portString, server, config);
}
return ret;
}
use of org.glassfish.config.support.PropertyResolver in project Payara by payara.
the class GetTokensCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReporter report = (ActionReporter) context.getActionReport();
PropertyResolver resolver = new PropertyResolver(domain, target);
String sep = "";
String eol = System.getProperty("line.separator");
StringBuilder output = new StringBuilder();
Map<String, String> values = new TreeMap<String, String>();
Properties properties = new Properties();
properties.put("tokens", values);
for (String token : tokens) {
String value = resolver.getPropertyValue(token);
if ((value == null) && (checkSystemProperties)) {
value = System.getProperty(token);
}
output.append(sep).append(token).append(" = ").append(value);
sep = eol;
values.put(token, value);
}
report.setMessage(output.toString());
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
report.setExtraProperties(properties);
return;
}
Aggregations