use of org.apache.catalina.Engine in project tomcat by apache.
the class FailedContext method getMBeanKeyProperties.
@Override
public String getMBeanKeyProperties() {
Container c = this;
StringBuilder keyProperties = new StringBuilder();
int containerCount = 0;
// each container
while (!(c instanceof Engine)) {
if (c instanceof Context) {
keyProperties.append(",context=");
ContextName cn = new ContextName(c.getName(), false);
keyProperties.append(cn.getDisplayName());
} else if (c instanceof Host) {
keyProperties.append(",host=");
keyProperties.append(c.getName());
} else if (c == null) {
// May happen in unit testing and/or some embedding scenarios
keyProperties.append(",container");
keyProperties.append(containerCount++);
keyProperties.append("=null");
break;
} else {
// Should never happen...
keyProperties.append(",container");
keyProperties.append(containerCount++);
keyProperties.append('=');
keyProperties.append(c.getName());
}
c = c.getParent();
}
return keyProperties.toString();
}
use of org.apache.catalina.Engine in project tomcat by apache.
the class Tomcat method getHost.
public Host getHost() {
Engine engine = getEngine();
if (engine.findChildren().length > 0) {
return (Host) engine.findChildren()[0];
}
Host host = new StandardHost();
host.setName(hostname);
getEngine().addChild(host);
return host;
}
use of org.apache.catalina.Engine in project tomcat by apache.
the class ManagerServlet method init.
/**
* Initialize this servlet.
*/
@Override
public void init() throws ServletException {
// Ensure that our ContainerServlet properties have been set
if ((wrapper == null) || (context == null))
throw new UnavailableException(sm.getString("managerServlet.noWrapper"));
// Set our properties from the initialization parameters
String value = null;
try {
value = getServletConfig().getInitParameter("debug");
debug = Integer.parseInt(value);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
}
// Acquire global JNDI resources if available
Server server = ((Engine) host.getParent()).getService().getServer();
if (server != null) {
global = server.getGlobalNamingContext();
}
// Calculate the directory into which we will be deploying applications
versioned = (File) getServletContext().getAttribute(ServletContext.TEMPDIR);
configBase = new File(context.getCatalinaBase(), "conf");
Container container = context;
Container host = null;
Container engine = null;
while (container != null) {
if (container instanceof Host)
host = container;
if (container instanceof Engine)
engine = container;
container = container.getParent();
}
if (engine != null) {
configBase = new File(configBase, engine.getName());
}
if (host != null) {
configBase = new File(configBase, host.getName());
}
// Log debugging messages as necessary
if (debug >= 1) {
log("init: Associated with Deployer '" + oname + "'");
if (global != null) {
log("init: Global resources are available");
}
}
}
use of org.apache.catalina.Engine in project tomcat by apache.
the class MapperListener method findDefaultHost.
// ------------------------------------------------------ Protected Methods
private void findDefaultHost() {
Engine engine = service.getContainer();
String defaultHost = engine.getDefaultHost();
boolean found = false;
if (defaultHost != null && defaultHost.length() > 0) {
Container[] containers = engine.findChildren();
for (Container container : containers) {
Host host = (Host) container;
if (defaultHost.equalsIgnoreCase(host.getName())) {
found = true;
break;
}
String[] aliases = host.findAliases();
for (String alias : aliases) {
if (defaultHost.equalsIgnoreCase(alias)) {
found = true;
break;
}
}
}
}
if (found) {
mapper.setDefaultHostName(defaultHost);
} else {
log.warn(sm.getString("mapperListener.unknownDefaultHost", defaultHost, service));
}
}
use of org.apache.catalina.Engine in project tomcat by apache.
the class MBeanFactory method removeContext.
/**
* Remove an existing Context.
*
* @param contextName MBean Name of the component to remove
*
* @exception Exception if a component cannot be removed
*/
public void removeContext(String contextName) throws Exception {
// Acquire a reference to the component to be removed
ObjectName oname = new ObjectName(contextName);
String domain = oname.getDomain();
StandardService service = (StandardService) getService(oname);
Engine engine = service.getContainer();
String name = oname.getKeyProperty("name");
name = name.substring(2);
int i = name.indexOf('/');
String hostName = name.substring(0, i);
String path = name.substring(i);
ObjectName deployer = new ObjectName(domain + ":type=Deployer,host=" + hostName);
String pathStr = getPathStr(path);
if (mserver.isRegistered(deployer)) {
mserver.invoke(deployer, "addServiced", new Object[] { pathStr }, new String[] { "java.lang.String" });
mserver.invoke(deployer, "unmanageApp", new Object[] { pathStr }, new String[] { "java.lang.String" });
mserver.invoke(deployer, "removeServiced", new Object[] { pathStr }, new String[] { "java.lang.String" });
} else {
log.warn("Deployer not found for " + hostName);
Host host = (Host) engine.findChild(hostName);
Context context = (Context) host.findChild(pathStr);
// Remove this component from its parent component
host.removeChild(context);
if (context instanceof StandardContext)
try {
((StandardContext) context).destroy();
} catch (Exception e) {
log.warn("Error during context [" + context.getName() + "] destroy ", e);
}
}
}
Aggregations