Search in sources :

Example 1 with XMLNode

use of org.openntf.openliberty.domino.util.xml.XMLNode in project openliberty-domino by OpenNTF.

the class LibertyServerInstance method getListeningPorts.

@Override
public Collection<Integer> getListeningPorts() {
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    Path serverXml = getWlpRoot().resolve("usr").resolve("servers").resolve(serverName).resolve("server.xml");
    if (Files.isRegularFile(serverXml)) {
        // Parse the server.xml for port information
        try {
            XMLDocument xml = new XMLDocument();
            try (InputStream is = Files.newInputStream(serverXml)) {
                xml.loadInputStream(is);
            }
            // $NON-NLS-1$
            XMLNodeList nodes = xml.selectNodes("/server/httpEndpoint");
            if (!nodes.isEmpty()) {
                // Last one wins in WLP
                XMLNode node = nodes.get(nodes.size() - 1);
                // $NON-NLS-1$
                String host = node.getAttribute("host");
                if (StringUtil.isEmpty(host)) {
                    host = InetAddress.getLocalHost().getHostName();
                }
                // $NON-NLS-1$
                String httpPort = node.getAttribute("httpPort");
                if (StringUtil.isEmpty(httpPort)) {
                    // This seems to be the default when unspecified
                    // $NON-NLS-1$
                    httpPort = "9080";
                }
                // $NON-NLS-1$
                String httpsPort = node.getAttribute("httpsPort");
                return Stream.of(httpPort, httpsPort).filter(StringUtil::isNotEmpty).filter(// $NON-NLS-1$
                p -> !"-1".equals(p)).map(port -> Integer.parseInt(port)).collect(Collectors.toList());
            }
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        } catch (SAXException | ParserConfigurationException e) {
            throw new RuntimeException(e);
        }
    }
    return Collections.emptyList();
}
Also used : Path(java.nio.file.Path) Manifest(java.util.jar.Manifest) ZipInputStream(java.util.zip.ZipInputStream) XMLDocument(org.openntf.openliberty.domino.util.xml.XMLDocument) ServerConfiguration(org.openntf.openliberty.domino.server.ServerConfiguration) HashMap(java.util.HashMap) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) XMLNode(org.openntf.openliberty.domino.util.xml.XMLNode) MessageFormat.format(java.text.MessageFormat.format) Messages(org.openntf.openliberty.domino.runtime.Messages) AbstractJavaServerInstance(org.openntf.openliberty.domino.server.AbstractJavaServerInstance) DominoThreadFactory(org.openntf.openliberty.domino.util.DominoThreadFactory) XMLNodeList(org.openntf.openliberty.domino.util.xml.XMLNodeList) Map(java.util.Map) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) RuntimeConfigurationProvider(org.openntf.openliberty.domino.config.RuntimeConfigurationProvider) StreamRedirector(org.openntf.openliberty.domino.util.StreamRedirector) OutputStream(java.io.OutputStream) PrintStream(java.io.PrintStream) LogFileWatcher(org.openntf.openliberty.domino.util.LogFileWatcher) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) Collection(java.util.Collection) StandardOpenOption(java.nio.file.StandardOpenOption) Set(java.util.Set) IOException(java.io.IOException) RuntimeDeploymentTask(org.openntf.openliberty.domino.runtime.RuntimeDeploymentTask) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) StringUtil(org.openntf.openliberty.domino.util.commons.ibm.StringUtil) UncheckedIOException(java.io.UncheckedIOException) OpenLibertyUtil(org.openntf.openliberty.domino.util.OpenLibertyUtil) List(java.util.List) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) Writer(java.io.Writer) OpenLibertyLog(org.openntf.openliberty.domino.log.OpenLibertyLog) Collections(java.util.Collections) InputStream(java.io.InputStream) XMLNode(org.openntf.openliberty.domino.util.xml.XMLNode) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) XMLDocument(org.openntf.openliberty.domino.util.xml.XMLDocument) SAXException(org.xml.sax.SAXException) XMLNodeList(org.openntf.openliberty.domino.util.xml.XMLNodeList) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 2 with XMLNode

use of org.openntf.openliberty.domino.util.xml.XMLNode in project openliberty-domino by OpenNTF.

the class LibertyServerInstance method getListeningHost.

@Override
public String getListeningHost() {
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    Path serverXml = getWlpRoot().resolve("usr").resolve("servers").resolve(serverName).resolve("server.xml");
    if (Files.isRegularFile(serverXml)) {
        // Parse the server.xml for port information
        try {
            XMLDocument xml = new XMLDocument();
            try (InputStream is = Files.newInputStream(serverXml)) {
                xml.loadInputStream(is);
            }
            // $NON-NLS-1$
            XMLNodeList nodes = xml.selectNodes("/server/httpEndpoint");
            if (!nodes.isEmpty()) {
                // Last one wins in WLP
                XMLNode node = nodes.get(nodes.size() - 1);
                // $NON-NLS-1$
                String host = node.getAttribute("host");
                if (StringUtil.isEmpty(host)) {
                    // $NON-NLS-1$
                    return "localhost";
                } else {
                    return host;
                }
            }
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        } catch (SAXException | ParserConfigurationException e) {
            throw new RuntimeException(e);
        }
    }
    // $NON-NLS-1$
    return "*";
}
Also used : Path(java.nio.file.Path) XMLNode(org.openntf.openliberty.domino.util.xml.XMLNode) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) UncheckedIOException(java.io.UncheckedIOException) XMLNodeList(org.openntf.openliberty.domino.util.xml.XMLNodeList) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLDocument(org.openntf.openliberty.domino.util.xml.XMLDocument) SAXException(org.xml.sax.SAXException)

Aggregations

IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 UncheckedIOException (java.io.UncheckedIOException)2 Path (java.nio.file.Path)2 ZipInputStream (java.util.zip.ZipInputStream)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 Writer (java.io.Writer)1 InetAddress (java.net.InetAddress)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 StandardCopyOption (java.nio.file.StandardCopyOption)1 StandardOpenOption (java.nio.file.StandardOpenOption)1 MessageFormat.format (java.text.MessageFormat.format)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1