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());
}
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());
}
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));
}
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);
}
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;
}
Aggregations