use of com.reprezen.kaizen.oasparser.model3.Server in project liferay-ide by liferay.
the class LiferayTomcatServerBehavior method moveContextToAutoDeployDir.
public IStatus moveContextToAutoDeployDir(IModule module, IPath deployDir, IPath baseDir, IPath autoDeployDir, boolean noPath, boolean serverStopped) {
// $NON-NLS-1$
IPath confDir = baseDir.append("conf");
// $NON-NLS-1$
IPath serverXml = confDir.append("server.xml");
try (InputStream newInputStream = Files.newInputStream(serverXml.toFile().toPath())) {
Factory factory = new Factory();
// $NON-NLS-1$
factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
Server publishedServer = (Server) factory.loadDocument(newInputStream);
ServerInstance publishedInstance = new ServerInstance(publishedServer, null, null);
IPath contextPath = null;
if (autoDeployDir.isAbsolute()) {
contextPath = autoDeployDir;
} else {
contextPath = baseDir.append(autoDeployDir);
}
File contextDir = contextPath.toFile();
if (!contextDir.exists()) {
contextDir.mkdirs();
}
Context context = publishedInstance.createContext(-1);
// $NON-NLS-1$
context.setReloadable("true");
final String moduleName = module.getName();
final String requiredSuffix = ProjectUtil.getRequiredSuffix(module.getProject());
String contextName = moduleName;
if (!moduleName.endsWith(requiredSuffix)) {
contextName = moduleName + requiredSuffix;
}
// $NON-NLS-1$
context.setSource("org.eclipse.jst.jee.server:" + contextName);
if (// $NON-NLS-1$
Boolean.valueOf(context.getAttributeValue("antiResourceLocking")).booleanValue()) {
// $NON-NLS-1$ //$NON-NLS-2$
context.setAttributeValue("antiResourceLocking", "false");
}
// $NON-NLS-1$
File contextFile = new File(contextDir, contextName + ".xml");
if (!LiferayTomcatUtil.isExtProjectContext(context)) {
// If requested, remove path attribute
if (noPath) {
// $NON-NLS-1$
context.removeAttribute("path");
}
// need to fix the doc base to contain entire path to help autoDeployer for Liferay
context.setDocBase(deployDir.toOSString());
// context.setAttributeValue("antiJARLocking", "true");
// check to see if we need to move from conf folder
// IPath existingContextPath = confDir.append("Catalina/localhost").append(contextFile.getName());
// if (existingContextPath.toFile().exists()) {
// existingContextPath.toFile().delete();
// }
DocumentBuilder builder = XMLUtil.getDocumentBuilder();
Document contextDoc = builder.newDocument();
contextDoc.appendChild(contextDoc.importNode(context.getElementNode(), true));
XMLUtil.save(contextFile.getAbsolutePath(), contextDoc);
}
} catch (Exception e) {
// 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;
}
use of com.reprezen.kaizen.oasparser.model3.Server in project webtools.servertools by eclipse.
the class TomcatVersionHelper method publishCatalinaContextConfig.
/**
* Add context configuration found in META-INF/context.xml files
* present in projects to published server.xml. Used by
* Tomcat 4.1, 5.0, and 5.5 which support use of META-INF/context.xml
* in some form.
*
* @param baseDir absolute path to catalina instance directory
* @param webappsDir absolute path to deployment directory
* @param monitor a progress monitor or null
* @return result of operation
*/
public static IStatus publishCatalinaContextConfig(IPath baseDir, IPath webappsDir, IProgressMonitor monitor) {
if (Trace.isTraceEnabled())
Trace.trace(Trace.FINER, "Apply context configurations");
IPath confDir = baseDir.append("conf");
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(confDir.append("server.xml").toFile()));
ServerInstance publishedInstance = new ServerInstance(publishedServer, null, null);
monitor.worked(100);
boolean modified = false;
MultiStatus ms = new MultiStatus(TomcatPlugin.PLUGIN_ID, 0, Messages.publishContextConfigTask, null);
Context[] contexts = publishedInstance.getContexts();
if (contexts != null) {
for (int i = 0; i < contexts.length; i++) {
Context context = contexts[i];
monitor.subTask(NLS.bind(Messages.checkingContextTask, new String[] { context.getPath() }));
if (addCatalinaContextConfig(webappsDir, context, ms)) {
modified = true;
}
}
}
monitor.worked(100);
if (modified) {
monitor.subTask(Messages.savingContextConfigTask);
factory.save(confDir.append("server.xml").toOSString());
}
// If problem(s) occurred adding context configurations, return error status
if (ms.getChildren().length > 0) {
return ms;
}
if (Trace.isTraceEnabled())
Trace.trace(Trace.FINER, "Server.xml updated with context.xml configurations");
return Status.OK_STATUS;
} catch (Exception e) {
Trace.trace(Trace.WARNING, "Could not apply context configurations to published Tomcat configuration from " + 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();
}
}
use of com.reprezen.kaizen.oasparser.model3.Server in project webtools.servertools by eclipse.
the class TomcatVersionHelper method getCatalinaServerInstance.
/**
* Gets a ServerInstance for the specified server.xml, Service name,
* and Host name. Returns null if server.xml does not exist
* or an error occurs.
*
* @param serverXml path to previously published server.xml
* @param serviceName name of Service to be used by this instance or null
* @param hostName name of Host to be used by this instance or null
* @return ServerInstance for specified server.xml using specified
* Service and Host names. null if server.xml does not exist.
* @throws FileNotFoundException should not occur since existence is tested
* @throws IOException if there is an error reading server.xml
* @throws SAXException if there is a syntax error in server.xml
*/
public static ServerInstance getCatalinaServerInstance(IPath serverXml, String serviceName, String hostName) throws FileNotFoundException, IOException, SAXException {
ServerInstance serverInstance = null;
Factory factory = new Factory();
factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
File serverFile = serverXml.toFile();
if (serverFile.exists()) {
Server server = (Server) factory.loadDocument(new FileInputStream(serverFile));
serverInstance = new ServerInstance(server, serviceName, hostName);
IPath contextPath = serverInstance.getContextXmlDirectory(serverXml.removeLastSegments(1));
File contextDir = contextPath.toFile();
if (contextDir.exists()) {
Map<File, Context> projectContexts = new HashMap<File, Context>();
loadSeparateContextFiles(contextPath.toFile(), factory, projectContexts);
// add any separately saved contexts
Host host = serverInstance.getHost();
Collection contexts = projectContexts.values();
Iterator iter = contexts.iterator();
while (iter.hasNext()) {
Context context = (Context) iter.next();
host.importNode(context.getElementNode(), true);
}
// TODO Add handling for non-project contexts when there removal can be addressed
}
}
return serverInstance;
}
use of com.reprezen.kaizen.oasparser.model3.Server in project webtools.servertools by eclipse.
the class XmlTestCase method testServerInstance2.
/**
* Test behavior of ServerInstance
*/
public void testServerInstance2() {
Server server = getXml40Server("serverxml.test2");
assertNotNull(server);
ServerInstance si = new ServerInstance(server, "Service", "nonexistent_host");
assertNotNull(si.getService());
assertNotNull(si.getEngine());
assertEquals("Engine", si.getEngine().getName());
assertNull(si.getHost());
assertEquals("Host \"nonexistent_host\" was not found under Engine \"Engine\" and Service \"Service\".", si.getStatus().getMessage());
si = new ServerInstance(server, "Service", null);
assertNotNull(si.getService());
assertNotNull(si.getEngine());
assertEquals("Engine", si.getEngine().getName());
assertNotNull(si.getHost());
assertEquals("localhost", si.getHost().getName());
assertEquals((new Path("/Base")).append("Engine").append("localhost"), si.getContextXmlDirectory(new Path("/Base")));
Context context = si.getContext(0);
assertNotNull(context);
assertEquals("/WebApp1", context.getPath());
context = si.getContext(1);
assertNotNull(context);
assertEquals("/WebApp2", context.getPath());
context = si.getContext(2);
assertNotNull(context);
assertEquals("/WebApp3", context.getPath());
// create new context
context = si.getContext(3);
context.setPath("/WebApp4");
Context[] contexts = si.getContexts();
assertEquals(4, contexts.length);
assertEquals("/WebApp1", contexts[0].getPath());
assertEquals("/WebApp2", contexts[1].getPath());
assertEquals("/WebApp3", contexts[2].getPath());
assertEquals("/WebApp4", contexts[3].getPath());
context = si.createContext(2);
context.setPath("/WebApp2b");
contexts = si.getContexts();
assertEquals(5, contexts.length);
assertEquals("/WebApp1", contexts[0].getPath());
assertEquals("/WebApp2", contexts[1].getPath());
assertEquals("/WebApp2b", contexts[2].getPath());
assertEquals("/WebApp3", contexts[3].getPath());
assertEquals("/WebApp4", contexts[4].getPath());
assertTrue(si.removeContext("WebApp2b"));
contexts = si.getContexts();
assertEquals(4, contexts.length);
assertEquals("/WebApp1", contexts[0].getPath());
assertEquals("/WebApp2", contexts[1].getPath());
assertEquals("/WebApp3", contexts[2].getPath());
assertEquals("/WebApp4", contexts[3].getPath());
assertTrue(si.removeContext(3));
contexts = si.getContexts();
assertEquals(3, contexts.length);
assertEquals("/WebApp1", contexts[0].getPath());
assertEquals("/WebApp2", contexts[1].getPath());
assertEquals("/WebApp3", contexts[2].getPath());
context = si.getContext("/WebApp1");
assertNotNull(context);
assertEquals("/WebApp1", context.getPath());
assertEquals(new Path("/Base/work/Engine/localhost/WebApp1"), si.getContextWorkDirectory(new Path("/Base"), context));
context = si.getContext("WebApp2");
assertNotNull(context);
assertEquals("/WebApp2", context.getPath());
assertEquals(new Path("/Base/relative/workdir"), si.getContextWorkDirectory(new Path("/Base"), context));
context = si.getContext("WebApp3");
assertNotNull(context);
assertEquals("/WebApp3", context.getPath());
assertEquals(new Path("/absolute/workdir"), si.getContextWorkDirectory(new Path("/Base"), context));
context = si.createContext(3);
context.setPath("");
context = si.getContext("");
assertNotNull(context);
assertEquals("", context.getPath());
assertEquals(new Path("/Base/work/Engine/localhost/_"), si.getContextWorkDirectory(new Path("/Base"), context));
assertEquals(new Path("/Base/work/Engine/localhost"), si.getHostWorkDirectory(new Path("/Base")));
assertNull(si.getContext("nonexistent"));
assertEquals("Context with path \"/nonexistent\" was not found under Service \"Service\", Engine \"Engine\", and Host \"localhost\".", si.getStatus().getMessage());
}
use of com.reprezen.kaizen.oasparser.model3.Server in project webtools.servertools by eclipse.
the class XmlTestCase method testDefaultServerXml50.
/**
* Test reading of the default server.xml provided by the
* current Tomcat 5.0 release (28).
*/
public void testDefaultServerXml50() {
Server server = getXml40Server("default.serverxml.50");
assertNotNull(server);
// Check contents of XML
String port = server.getPort();
assertEquals("8005", port);
assertEquals(server.getListenerCount(), 2);
Listener listener = server.getListener(0);
assertNotNull(listener);
assertEquals("org.apache.catalina.mbeans.ServerLifecycleListener", listener.getClassName());
listener = server.getListener(1);
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());
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(engine.getHostCount(), 1);
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());
}
Aggregations