use of org.apache.catalina.Engine in project tomcat by apache.
the class StandardServiceSF method storeChildren.
/**
* Store the specified service element children.
*
* @param aWriter Current output writer
* @param indent Indentation level
* @param aService Service to store
* @param parentDesc The element description
* @throws Exception Configuration storing error
*/
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aService, StoreDescription parentDesc) throws Exception {
if (aService instanceof StandardService) {
StandardService service = (StandardService) aService;
// Store nested <Listener> elements
LifecycleListener[] listeners = ((Lifecycle) service).findLifecycleListeners();
storeElementArray(aWriter, indent, listeners);
// Store nested <Executor> elements
Executor[] executors = service.findExecutors();
storeElementArray(aWriter, indent, executors);
Connector[] connectors = service.findConnectors();
storeElementArray(aWriter, indent, connectors);
// Store nested <Engine> element
Engine container = service.getContainer();
if (container != null) {
StoreDescription elementDesc = getRegistry().findDescription(container.getClass());
if (elementDesc != null) {
IStoreFactory factory = elementDesc.getStoreFactory();
factory.store(aWriter, indent, container);
}
}
}
}
use of org.apache.catalina.Engine in project tomcat by apache.
the class Tomcat method getEngine.
/**
* Access to the engine, for further customization.
* @return The engine
*/
public Engine getEngine() {
Service service = getServer().findServices()[0];
if (service.getContainer() != null) {
return service.getContainer();
}
Engine engine = new StandardEngine();
engine.setName("Tomcat");
engine.setDefaultHost(hostname);
engine.setRealm(createDefaultRealm());
service.setContainer(engine);
return engine;
}
use of org.apache.catalina.Engine in project tomcat by apache.
the class Tomcat method setHost.
/**
* Sets the current host - all future webapps will
* be added to this host. When tomcat starts, the
* host will be the default host.
*
* @param host The current host
*/
public void setHost(Host host) {
Engine engine = getEngine();
boolean found = false;
for (Container engineHost : engine.findChildren()) {
if (engineHost == host) {
found = true;
}
}
if (!found) {
engine.addChild(host);
}
}
use of org.apache.catalina.Engine in project tomcat by apache.
the class ContainerBase 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 Wrapper) {
keyProperties.insert(0, ",servlet=");
keyProperties.insert(9, c.getName());
} else if (c instanceof Context) {
keyProperties.insert(0, ",context=");
ContextName cn = new ContextName(c.getName(), false);
keyProperties.insert(9, cn.getDisplayName());
} else if (c instanceof Host) {
keyProperties.insert(0, ",host=");
keyProperties.insert(6, 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 ApplicationContext method getContext.
@Override
public ServletContext getContext(String uri) {
// Validate the format of the specified argument
if (uri == null || !uri.startsWith("/")) {
return null;
}
Context child = null;
try {
// Look for an exact match
Container host = context.getParent();
child = (Context) host.findChild(uri);
// Non-running contexts should be ignored.
if (child != null && !child.getState().isAvailable()) {
child = null;
}
// Remove any version information and use the mapper
if (child == null) {
int i = uri.indexOf("##");
if (i > -1) {
uri = uri.substring(0, i);
}
// Note: This could be more efficient with a dedicated Mapper
// method but such an implementation would require some
// refactoring of the Mapper to avoid copy/paste of
// existing code.
MessageBytes hostMB = MessageBytes.newInstance();
hostMB.setString(host.getName());
MessageBytes pathMB = MessageBytes.newInstance();
pathMB.setString(uri);
MappingData mappingData = new MappingData();
((Engine) host.getParent()).getService().getMapper().map(hostMB, pathMB, null, mappingData);
child = mappingData.context;
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
return null;
}
if (child == null) {
return null;
}
if (context.getCrossContext()) {
// If crossContext is enabled, can always return the context
return child.getServletContext();
} else if (child == context) {
// Can still return the current context
return context.getServletContext();
} else {
// Nothing to return
return null;
}
}
Aggregations