Search in sources :

Example 6 with HostAndPort

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);
    }
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) MiniXmlParserException(com.sun.enterprise.universal.xml.MiniXmlParserException) CommandException(org.glassfish.api.admin.CommandException) MiniXmlParser(com.sun.enterprise.universal.xml.MiniXmlParser)

Example 7 with HostAndPort

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;
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) Config(com.sun.enterprise.config.serverbeans.Config) Protocol(org.glassfish.grizzly.config.dom.Protocol) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) RestEndpoint(org.glassfish.api.admin.RestEndpoint) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 8 with HostAndPort

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);
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) HttpService(com.sun.enterprise.config.serverbeans.HttpService) ActionReport(org.glassfish.api.ActionReport)

Example 9 with HostAndPort

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;
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) Config(com.sun.enterprise.config.serverbeans.Config) Http(org.glassfish.grizzly.config.dom.Http) Protocol(org.glassfish.grizzly.config.dom.Protocol) RestEndpoint(org.glassfish.api.admin.RestEndpoint) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 10 with HostAndPort

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;
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer)

Aggregations

HostAndPort (com.sun.enterprise.util.HostAndPort)16 CommandException (org.glassfish.api.admin.CommandException)4 MiniXmlParser (com.sun.enterprise.universal.xml.MiniXmlParser)3 MiniXmlParserException (com.sun.enterprise.universal.xml.MiniXmlParserException)3 File (java.io.File)3 Test (org.junit.Test)3 Config (com.sun.enterprise.config.serverbeans.Config)2 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)2 IOException (java.io.IOException)2 RestEndpoint (org.glassfish.api.admin.RestEndpoint)2 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)2 Protocol (org.glassfish.grizzly.config.dom.Protocol)2 GFLauncherException (com.sun.enterprise.admin.launcher.GFLauncherException)1 DomainConfig (com.sun.enterprise.admin.servermgmt.DomainConfig)1 PEDomainsManager (com.sun.enterprise.admin.servermgmt.pe.PEDomainsManager)1 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)1 HttpService (com.sun.enterprise.config.serverbeans.HttpService)1 SmartFile (com.sun.enterprise.universal.io.SmartFile)1 ProcessStreamDrainer (com.sun.enterprise.universal.process.ProcessStreamDrainer)1 MalformedURLException (java.net.MalformedURLException)1