use of org.apache.catalina.startup.ContextConfig in project tomcat by apache.
the class MBeanFactory method createStandardContext.
/**
* Create a new StandardContext.
*
* @param parent MBean Name of the associated parent component
* @param path The context path for this Context
* @param docBase Document base directory (or WAR) for this Context
* @param xmlValidation if XML descriptors should be validated
* @param xmlNamespaceAware if the XML processor should namespace aware
* @return the object name of the created context
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createStandardContext(String parent, String path, String docBase, boolean xmlValidation, boolean xmlNamespaceAware) throws Exception {
// Create a new StandardContext instance
StandardContext context = new StandardContext();
path = getPathStr(path);
context.setPath(path);
context.setDocBase(docBase);
context.setXmlValidation(xmlValidation);
context.setXmlNamespaceAware(xmlNamespaceAware);
ContextConfig contextConfig = new ContextConfig();
context.addLifecycleListener(contextConfig);
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ObjectName deployer = new ObjectName(pname.getDomain() + ":type=Deployer,host=" + pname.getKeyProperty("host"));
if (mserver.isRegistered(deployer)) {
String contextName = context.getName();
mserver.invoke(deployer, "addServiced", new Object[] { contextName }, new String[] { "java.lang.String" });
String configPath = (String) mserver.getAttribute(deployer, "configBaseName");
String baseName = context.getBaseName();
File configFile = new File(new File(configPath), baseName + ".xml");
if (configFile.isFile()) {
context.setConfigFile(configFile.toURI().toURL());
}
mserver.invoke(deployer, "manageApp", new Object[] { context }, new String[] { "org.apache.catalina.Context" });
mserver.invoke(deployer, "removeServiced", new Object[] { contextName }, new String[] { "java.lang.String" });
} else {
log.warn("Deployer not found for " + pname.getKeyProperty("host"));
Service service = getService(pname);
Engine engine = service.getContainer();
Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
host.addChild(context);
}
// Return the corresponding MBean name
return context.getObjectName().toString();
}
use of org.apache.catalina.startup.ContextConfig in project tomcat by apache.
the class ContainerMBean method addChild.
/**
* Add a new child Container to those associated with this Container,
* if supported. Won't start the child yet. Has to be started with a call to
* Start method after necessary configurations are done.
*
* @param type ClassName of the child to be added
* @param name Name of the child to be added
*
* @exception MBeanException if the child cannot be added
*/
public void addChild(String type, String name) throws MBeanException {
Container contained = (Container) newInstance(type);
contained.setName(name);
if (contained instanceof StandardHost) {
HostConfig config = new HostConfig();
contained.addLifecycleListener(config);
} else if (contained instanceof StandardContext) {
ContextConfig config = new ContextConfig();
contained.addLifecycleListener(config);
}
boolean oldValue = true;
ContainerBase container = doGetManagedResource();
try {
oldValue = container.getStartChildren();
container.setStartChildren(false);
container.addChild(contained);
contained.init();
} catch (LifecycleException e) {
throw new MBeanException(e);
} finally {
if (container != null) {
container.setStartChildren(oldValue);
}
}
}
use of org.apache.catalina.startup.ContextConfig in project tomee by apache.
the class TomcatWebAppBuilder method init.
/**
* {@inheritDoc}
*/
@Override
public void init(final StandardContext standardContext) {
if (isIgnored(standardContext)) {
return;
}
// just adding a carriage return to get logs more readable
logger.info("------------------------- " + Contexts.getHostname(standardContext).replace("_", hosts.getDefaultHost()) + " -> " + finalName(standardContext.getPath()));
if (FORCE_RELOADABLE) {
final ContextInfo ctxInfo = getContextInfo(standardContext);
if (ctxInfo == null || (ctxInfo.appInfo != null && ctxInfo.appInfo.webAppAlone)) {
// don't do it for ears
standardContext.setReloadable(true);
}
}
if (SKIP_TLD) {
if (standardContext.getJarScanner() != null && standardContext.getJarScanner().getJarScanFilter() != null) {
final JarScanFilter jarScanFilter = standardContext.getJarScanner().getJarScanFilter();
if (StandardJarScanFilter.class.isInstance(jarScanFilter)) {
StandardJarScanFilter.class.cast(jarScanFilter).setDefaultTldScan(false);
}
}
}
final String name = standardContext.getName();
initJ2EEInfo(standardContext);
File warFile = Contexts.warPath(standardContext);
if (!warFile.exists()) {
return;
}
if (!warFile.isDirectory()) {
try {
warFile = DeploymentLoader.unpack(warFile);
} catch (final OpenEJBException e) {
logger.error("can't unpack '" + warFile.getAbsolutePath() + "'");
}
}
standardContext.setCrossContext(SystemInstance.get().getOptions().get(OPENEJB_CROSSCONTEXT_PROPERTY, false));
standardContext.setNamingResources(new OpenEJBNamingResource(standardContext.getNamingResources()));
String sessionManager = SystemInstance.get().getOptions().get(OPENEJB_SESSION_MANAGER_PROPERTY + "." + name, (String) null);
if (sessionManager == null) {
sessionManager = SystemInstance.get().getOptions().get(OPENEJB_SESSION_MANAGER_PROPERTY, (String) null);
}
if (sessionManager != null) {
if (sessionManagerClass == null) {
try {
// the manager should be in standardclassloader
sessionManagerClass = ParentClassLoaderFinder.Helper.get().loadClass(sessionManager);
} catch (final ClassNotFoundException e) {
logger.error("can't find '" + sessionManager + "', StandardManager will be used", e);
sessionManagerClass = StandardManager.class;
}
}
try {
final Manager mgr = (Manager) sessionManagerClass.newInstance();
standardContext.setManager(mgr);
} catch (final Exception e) {
logger.error("can't instantiate '" + sessionManager + "', StandardManager will be used", e);
}
}
final LifecycleListener[] listeners = standardContext.findLifecycleListeners();
for (final LifecycleListener l : listeners) {
if (l instanceof ContextConfig) {
standardContext.removeLifecycleListener(l);
}
}
standardContext.addLifecycleListener(new OpenEJBContextConfig(new StandardContextInfo(standardContext)));
// force manually the namingContextListener to merge jndi in an easier way
final NamingContextListener ncl = new NamingContextListener();
try {
ncl.setName((String) getNamingContextName.invoke(standardContext));
} catch (final Exception e) {
ncl.setName(getId(standardContext));
}
ncl.setExceptionOnFailedWrite(standardContext.getJndiExceptionOnFailedWrite());
standardContext.setNamingContextListener(ncl);
standardContext.addLifecycleListener(ncl);
standardContext.addLifecycleListener(new TomcatJavaJndiBinder());
// listen some events
standardContext.addContainerListener(new TomEEContainerListener());
}
Aggregations