Search in sources :

Example 6 with Host

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Host in project webtools.servertools by eclipse.

the class XmlTestCase method testDefaultServerXml55.

/**
 * Test reading of the default server.xml provided by the
 * current Tomcat 5.5 release (20).
 */
public void testDefaultServerXml55() {
    Server server = getXml40Server("default.serverxml.55");
    assertNotNull(server);
    // Check contents of XML
    String port = server.getPort();
    assertEquals("8005", port);
    assertEquals(server.getListenerCount(), 4);
    Listener listener = server.getListener(0);
    assertNotNull(listener);
    assertEquals("org.apache.catalina.core.AprLifecycleListener", listener.getClassName());
    listener = server.getListener(1);
    assertNotNull(listener);
    assertEquals("org.apache.catalina.mbeans.ServerLifecycleListener", listener.getClassName());
    listener = server.getListener(2);
    assertNotNull(listener);
    assertEquals("org.apache.catalina.mbeans.GlobalResourcesLifecycleListener", listener.getClassName());
    listener = server.getListener(3);
    assertNotNull(listener);
    assertEquals("org.apache.catalina.storeconfig.StoreConfigLifecycleListener", listener.getClassName());
    assertEquals(server.getServiceCount(), 1);
    Service service = server.getService(0);
    assertNotNull(service);
    assertEquals("Catalina", service.getName());
    assertEquals(2, service.getConnectorCount());
    Connector connector = service.getConnector(0);
    assertNotNull(connector);
    assertEquals("8080", connector.getPort());
    assertNull(connector.getProtocol());
    connector = service.getConnector(1);
    assertNotNull(connector);
    assertEquals("8009", connector.getPort());
    assertEquals("AJP/1.3", connector.getProtocol());
    Engine engine = service.getEngine();
    assertNotNull(engine);
    assertEquals("Catalina", engine.getName());
    assertEquals("localhost", engine.getDefaultHost());
    assertEquals(1, engine.getHostCount());
    Host host = engine.getHost(0);
    assertNotNull(host);
    assertEquals("localhost", host.getName());
    assertEquals("webapps", host.getAppBase());
    assertEquals("true", host.getAttributeValue("unpackWARs"));
    assertEquals("true", host.getAttributeValue("autoDeploy"));
    assertEquals(0, host.getContextCount());
}
Also used : Connector(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector) Listener(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Listener) Server(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server) Service(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service) Host(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Host) Engine(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Engine)

Example 7 with Host

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Host in project webtools.servertools by eclipse.

the class XmlTestCase method testDefaultServerXml60.

/**
 * Test reading of the default server.xml provided by the
 * current Tomcat 6.0 release.
 */
public void testDefaultServerXml60() {
    Server server = getXml40Server("default.serverxml.60");
    assertNotNull(server);
    // Check contents of XML
    String port = server.getPort();
    assertEquals("8005", port);
    assertEquals(4, server.getListenerCount());
    Listener listener = server.getListener(0);
    assertNotNull(listener);
    assertEquals("org.apache.catalina.core.AprLifecycleListener", listener.getClassName());
    listener = server.getListener(1);
    assertNotNull(listener);
    assertEquals("org.apache.catalina.core.JasperListener", listener.getClassName());
    listener = server.getListener(2);
    assertNotNull(listener);
    assertEquals("org.apache.catalina.mbeans.ServerLifecycleListener", listener.getClassName());
    listener = server.getListener(3);
    assertNotNull(listener);
    assertEquals("org.apache.catalina.mbeans.GlobalResourcesLifecycleListener", listener.getClassName());
    assertEquals(1, server.getServiceCount());
    Service service = server.getService(0);
    assertNotNull(service);
    assertEquals("Catalina", service.getName());
    assertEquals(2, service.getConnectorCount());
    Connector connector = service.getConnector(0);
    assertNotNull(connector);
    assertEquals("8080", connector.getPort());
    assertEquals("HTTP/1.1", connector.getProtocol());
    connector = service.getConnector(1);
    assertNotNull(connector);
    assertEquals("8009", connector.getPort());
    assertEquals("AJP/1.3", connector.getProtocol());
    Engine engine = service.getEngine();
    assertNotNull(engine);
    assertEquals("Catalina", engine.getName());
    assertEquals("localhost", engine.getDefaultHost());
    assertEquals(1, engine.getHostCount());
    Host host = engine.getHost(0);
    assertNotNull(host);
    assertEquals("localhost", host.getName());
    assertEquals("webapps", host.getAppBase());
    assertEquals("true", host.getAttributeValue("unpackWARs"));
    assertEquals("true", host.getAttributeValue("autoDeploy"));
    assertEquals(0, host.getContextCount());
}
Also used : Connector(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector) Listener(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Listener) Server(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server) Service(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service) Host(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Host) Engine(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Engine)

Example 8 with Host

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Host in project webtools.servertools by eclipse.

the class XmlTestCase method testServerInstance3.

/**
 * Test behavior of ServerInstance
 */
public void testServerInstance3() {
    Server server = getXml40Server("serverxml.test3");
    assertNotNull(server);
    ServerInstance si = new ServerInstance(server, "Service", null);
    Context context = si.getContext("/WebApp1");
    assertNotNull(context);
    assertEquals(new Path("/Base/relative/host/WebApp1"), si.getContextWorkDirectory(new Path("/Base"), context));
    context = si.getContext("WebApp2");
    assertNotNull(context);
    assertEquals(new Path("/Base/relative/workdir"), si.getContextWorkDirectory(new Path("/Base"), context));
    context = si.getContext("WebApp3");
    assertNotNull(context);
    assertEquals(new Path("/absolute/workdir"), si.getContextWorkDirectory(new Path("/Base"), context));
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) Path(org.eclipse.core.runtime.Path) Server(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)

Example 9 with Host

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Host in project webtools.servertools by eclipse.

the class XmlTestCase method testServerInstance50.

/**
 * Test reading of the default server.xml provided by the
 * current Tomcat 5.0 release using ServerInstance.
 */
public void testServerInstance50() {
    Server server = getXml40Server("default.serverxml.50");
    assertNotNull(server);
    ServerInstance si = new ServerInstance(server, null, null);
    assertEquals(2, server.getListenerCount());
    Listener[] listeners = si.getListeners();
    assertEquals("org.apache.catalina.mbeans.ServerLifecycleListener", listeners[0].getClassName());
    assertEquals("org.apache.catalina.mbeans.GlobalResourcesLifecycleListener", listeners[1].getClassName());
    Service service = si.getService();
    assertNotNull(service);
    assertEquals("Catalina", service.getName());
    assertEquals("8080", si.getConnector(0).getPort());
    assertNull(si.getConnector(0).getProtocol());
    assertEquals("8009", si.getConnector(1).getPort());
    assertEquals("AJP/1.3", si.getConnector(1).getProtocol());
    Connector[] connectors = si.getConnectors();
    assertEquals(2, connectors.length);
    assertEquals("8080", connectors[0].getPort());
    assertNull(connectors[0].getProtocol());
    assertEquals("8009", connectors[1].getPort());
    assertEquals("AJP/1.3", connectors[1].getProtocol());
    Engine engine = si.getEngine();
    assertNotNull(engine);
    assertEquals("Catalina", engine.getName());
    assertEquals("localhost", engine.getDefaultHost());
    Host host = si.getHost();
    assertNotNull(host);
    assertEquals("localhost", host.getName());
    assertEquals("webapps", host.getAppBase());
    assertEquals("true", host.getAttributeValue("unpackWARs"));
    assertEquals("true", host.getAttributeValue("autoDeploy"));
    Context[] contexts = si.getContexts();
    assertEquals(0, contexts.length);
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) Connector(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector) Listener(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Listener) Server(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server) Service(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service) Host(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Host) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance) Engine(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Engine)

Example 10 with Host

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Host in project webtools.servertools by eclipse.

the class TomcatVersionHelper method moveContextsToSeparateFiles.

/**
 * Moves contexts out of current published server.xml and into individual
 * context XML files.
 *
 * @param baseDir directory where the Catalina instance is found
 * @param noPath true if path attribute should be removed from the context
 * @param serverStopped true if the server is stopped
 * @param monitor a progress monitor
 * @return result of operation
 */
public static IStatus moveContextsToSeparateFiles(IPath baseDir, boolean noPath, boolean serverStopped, IProgressMonitor monitor) {
    IPath confDir = baseDir.append("conf");
    IPath serverXml = confDir.append("server.xml");
    try {
        monitor = ProgressUtil.getMonitorFor(monitor);
        monitor.beginTask(Messages.publishConfigurationTask, 300);
        monitor.subTask(Messages.publishContextConfigTask);
        Factory factory = new Factory();
        factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
        Server publishedServer = (Server) factory.loadDocument(new FileInputStream(serverXml.toFile()));
        ServerInstance publishedInstance = new ServerInstance(publishedServer, null, null);
        monitor.worked(100);
        boolean modified = false;
        Host host = publishedInstance.getHost();
        Context[] wtpContexts = publishedInstance.getContexts();
        if (wtpContexts != null && wtpContexts.length > 0) {
            IPath contextPath = publishedInstance.getContextXmlDirectory(serverXml.removeLastSegments(1));
            File contextDir = contextPath.toFile();
            if (!contextDir.exists()) {
                contextDir.mkdirs();
            }
            // Process in reverse order, since contexts may be removed
            for (int i = wtpContexts.length - 1; i >= 0; i--) {
                Context context = wtpContexts[i];
                // TODO Handle non-project contexts when their removal can be addressed
                if (context.getSource() == null)
                    continue;
                String name = context.getPath();
                if (name.startsWith("/")) {
                    name = name.substring(1);
                }
                // If the default context, adjust the file name
                if (name.length() == 0) {
                    name = "ROOT";
                }
                // Update name if multi-level path.  For 5.5 and later the "#" has been
                // "reserved" as a legal file name placeholder for "/".  For Tomcat 5.0,
                // we just need a legal unique file name since "/" will fail.  Prior to
                // 5.0, this feature is not supported.
                name = name.replace('/', '#');
                // TODO Determine circumstances, if any, where setting antiResourceLocking true can cause the original docBase content to be deleted.
                if (Boolean.valueOf(context.getAttributeValue("antiResourceLocking")).booleanValue())
                    context.setAttributeValue("antiResourceLocking", "false");
                File contextFile = new File(contextDir, name + ".xml");
                Context existingContext = loadContextFile(contextFile);
                // If server is stopped or if contexts are not the equivalent, write the context file
                if (serverStopped || !context.isEquivalent(existingContext)) {
                    // If requested, remove path attribute
                    if (noPath)
                        context.removeAttribute("path");
                    DocumentBuilder builder = XMLUtil.getDocumentBuilder();
                    Document contextDoc = builder.newDocument();
                    contextDoc.appendChild(contextDoc.importNode(context.getElementNode(), true));
                    XMLUtil.save(contextFile.getAbsolutePath(), contextDoc);
                }
                host.removeElement("Context", i);
                modified = true;
            }
        }
        monitor.worked(100);
        if (modified) {
            monitor.subTask(Messages.savingContextConfigTask);
            factory.save(serverXml.toOSString());
        }
        monitor.worked(100);
        if (Trace.isTraceEnabled())
            Trace.trace(Trace.FINER, "Context docBase settings updated in server.xml.");
    } catch (Exception e) {
        Trace.trace(Trace.SEVERE, "Could not modify context configurations to serve directly for Tomcat configuration " + confDir.toOSString() + ": " + e.getMessage());
        return new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorPublishConfiguration, new String[] { e.getLocalizedMessage() }), e);
    } finally {
        monitor.done();
    }
    return Status.OK_STATUS;
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) Server(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) Host(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Host) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance) JarFile(java.util.jar.JarFile) File(java.io.File)

Aggregations

Server (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server)8 Context (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context)7 Host (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Host)6 ServerInstance (org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)5 Factory (org.eclipse.jst.server.tomcat.core.internal.xml.Factory)4 Connector (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector)4 Engine (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Engine)4 Listener (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Listener)4 Service (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service)4 FileInputStream (java.io.FileInputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 File (java.io.File)2 JarFile (java.util.jar.JarFile)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 SAXException (org.xml.sax.SAXException)2 InputStream (java.io.InputStream)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 Collection (java.util.Collection)1