use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.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 org.eclipse.jst.server.tomcat.core.internal.xml.server40.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 org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server in project webtools.servertools by eclipse.
the class Tomcat50Configuration method getServerPorts.
/**
* Returns a list of ServerPorts that this configuration uses.
*
* @return java.util.List
*/
public List getServerPorts() {
List<ServerPort> ports = new ArrayList<ServerPort>();
// first add server port
try {
int port = Integer.parseInt(server.getPort());
ports.add(new ServerPort("server", Messages.portServer, port, "TCPIP"));
} catch (Exception e) {
// ignore
}
// add connectors
try {
String instanceServiceName = serverInstance.getService().getName();
int size = server.getServiceCount();
for (int i = 0; i < size; i++) {
Service service = server.getService(i);
int size2 = service.getConnectorCount();
for (int j = 0; j < size2; j++) {
Connector connector = service.getConnector(j);
String name = "HTTP/1.1";
String protocol2 = "HTTP";
boolean advanced = true;
String[] contentTypes = null;
int port = -1;
try {
port = Integer.parseInt(connector.getPort());
} catch (Exception e) {
// ignore
}
String protocol = connector.getProtocol();
if (protocol != null && protocol.length() > 0) {
if (protocol.startsWith("HTTP")) {
name = protocol;
} else if (protocol.startsWith("AJP")) {
name = protocol;
protocol2 = "AJP";
} else {
// Get Tomcat equivalent name if protocol handler class specified
name = protocolHandlerMap.get(protocol);
if (name != null) {
// Prepare simple protocol string for ServerPort protocol
int index = name.indexOf('/');
if (index > 0)
protocol2 = name.substring(0, index);
else
protocol2 = name;
} else // Specified protocol is unknown, just use as is
{
name = protocol;
protocol2 = protocol;
}
}
}
if (protocol2.toLowerCase().equals("http"))
contentTypes = new String[] { "web", "webservices" };
String secure = connector.getSecure();
if (secure != null && secure.length() > 0) {
name = "SSL";
protocol2 = "SSL";
} else
advanced = false;
String portId;
if (instanceServiceName != null && instanceServiceName.equals(service.getName()))
portId = Integer.toString(j);
else
portId = i + "/" + j;
ports.add(new ServerPort(portId, name, port, protocol2, contentTypes, advanced));
}
}
} catch (Exception e) {
Trace.trace(Trace.SEVERE, "Error getting server ports", e);
}
return ports;
}
use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server in project webtools.servertools by eclipse.
the class Tomcat55Configuration method load.
/**
* @see TomcatConfiguration#load(IPath, IProgressMonitor)
*/
public void load(IPath path, IProgressMonitor monitor) throws CoreException {
try {
monitor = ProgressUtil.getMonitorFor(monitor);
monitor.beginTask(Messages.loadingTask, 7);
// check for catalina.policy to verify that this is a v5.5 config
InputStream in = new FileInputStream(path.append("catalina.policy").toFile());
in.read();
in.close();
monitor.worked(1);
serverFactory = new Factory();
serverFactory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
server = (Server) serverFactory.loadDocument(new FileInputStream(path.append("server.xml").toFile()));
serverInstance = new ServerInstance(server, null, null);
monitor.worked(1);
webAppDocument = new WebAppDocument(path.append("web.xml"));
monitor.worked(1);
// load context.xml file
File file = path.append("context.xml").toFile();
if (file.exists())
contextDocument = XMLUtil.getDocumentBuilder().parse(new InputSource(new FileInputStream(file)));
else
contextDocument = null;
monitor.worked(1);
tomcatUsersDocument = XMLUtil.getDocumentBuilder().parse(new InputSource(new FileInputStream(path.append("tomcat-users.xml").toFile())));
monitor.worked(1);
// load policy file
policyFile = TomcatVersionHelper.getFileContents(new FileInputStream(path.append("catalina.policy").toFile()));
monitor.worked(1);
// load properties file
file = path.append("catalina.properties").toFile();
if (file.exists())
propertiesFile = TomcatVersionHelper.getFileContents(new FileInputStream(file));
else
propertiesFile = null;
monitor.worked(1);
if (monitor.isCanceled())
return;
monitor.done();
} catch (Exception e) {
Trace.trace(Trace.WARNING, "Could not load Tomcat v5.5 configuration from " + path.toOSString() + ": " + e.getMessage());
throw new CoreException(new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCouldNotLoadConfiguration, path.toOSString()), e));
}
}
use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server in project webtools.servertools by eclipse.
the class Tomcat55Configuration method modifyServerPort.
/**
* Modify the port with the given id.
*
* @param id java.lang.String
* @param port int
*/
public void modifyServerPort(String id, int port) {
try {
if ("server".equals(id)) {
server.setPort(port + "");
isServerDirty = true;
firePropertyChangeEvent(MODIFY_PORT_PROPERTY, id, new Integer(port));
return;
}
int i = id.indexOf("/");
// If a connector in the instance Service
if (i < 0) {
int connNum = Integer.parseInt(id);
Connector connector = serverInstance.getConnector(connNum);
if (connector != null) {
connector.setPort(port + "");
isServerDirty = true;
firePropertyChangeEvent(MODIFY_PORT_PROPERTY, id, new Integer(port));
}
} else // Else a connector in another Service
{
int servNum = Integer.parseInt(id.substring(0, i));
int connNum = Integer.parseInt(id.substring(i + 1));
Service service = server.getService(servNum);
Connector connector = service.getConnector(connNum);
connector.setPort(port + "");
isServerDirty = true;
firePropertyChangeEvent(MODIFY_PORT_PROPERTY, id, new Integer(port));
}
} catch (Exception e) {
Trace.trace(Trace.SEVERE, "Error modifying server port " + id, e);
}
}
Aggregations