Search in sources :

Example 1 with PropertyResolver

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;
}
Also used : ArrayList(java.util.ArrayList) PropertyResolver(org.glassfish.config.support.PropertyResolver) URL(java.net.URL) RestEndpoint(org.glassfish.api.admin.RestEndpoint) Protocol(org.glassfish.grizzly.config.dom.Protocol) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 2 with PropertyResolver

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);
}
Also used : IiopListener(org.glassfish.orb.admin.config.IiopListener) PropertyResolver(org.glassfish.config.support.PropertyResolver)

Example 3 with PropertyResolver

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();
}
Also used : Protocols(org.glassfish.grizzly.config.dom.Protocols) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) PropertyResolver(org.glassfish.config.support.PropertyResolver) Protocol(org.glassfish.grizzly.config.dom.Protocol) LbReaderException(org.glassfish.loadbalancer.admin.cli.reader.api.LbReaderException) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 4 with PropertyResolver

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;
}
Also used : Dom(org.jvnet.hk2.config.Dom) Domain(com.sun.enterprise.config.serverbeans.Domain) PropertyResolver(org.glassfish.config.support.PropertyResolver) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 5 with PropertyResolver

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;
}
Also used : ActionReporter(com.sun.enterprise.v3.common.ActionReporter) PropertyResolver(org.glassfish.config.support.PropertyResolver) TreeMap(java.util.TreeMap) Properties(java.util.Properties)

Aggregations

PropertyResolver (org.glassfish.config.support.PropertyResolver)5 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)3 Protocol (org.glassfish.grizzly.config.dom.Protocol)2 Config (com.sun.enterprise.config.serverbeans.Config)1 Domain (com.sun.enterprise.config.serverbeans.Domain)1 ActionReporter (com.sun.enterprise.v3.common.ActionReporter)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 TreeMap (java.util.TreeMap)1 RestEndpoint (org.glassfish.api.admin.RestEndpoint)1 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)1 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)1 Protocols (org.glassfish.grizzly.config.dom.Protocols)1 LbReaderException (org.glassfish.loadbalancer.admin.cli.reader.api.LbReaderException)1 IiopListener (org.glassfish.orb.admin.config.IiopListener)1 Dom (org.jvnet.hk2.config.Dom)1