use of org.apache.catalina.LifecycleListener in project tomcat by apache.
the class Tomcat method addWebapp.
/**
* @param host The host in which the context will be deployed
* @param contextPath The context mapping to use, "" for root context.
* @param docBase Base directory for the context, for static files.
* Must exist, relative to the server home
* @return the deployed context
* @see #addWebapp(String, String)
*/
public Context addWebapp(Host host, String contextPath, String docBase) {
LifecycleListener listener = null;
try {
Class<?> clazz = Class.forName(getHost().getConfigClass());
listener = (LifecycleListener) clazz.newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
// to throw the specific checked exceptions
throw new IllegalArgumentException(e);
}
return addWebapp(host, contextPath, docBase, listener);
}
use of org.apache.catalina.LifecycleListener in project tomcat by apache.
the class UserConfig method deploy.
/**
* Deploy a web application for the specified user if they have such an
* application in the defined directory within their home directory.
*
* @param user Username owning the application to be deployed
* @param home Home directory of this user
*/
private void deploy(String user, String home) {
// Does this user have a web application to be deployed?
String contextPath = "/~" + user;
if (host.findChild(contextPath) != null)
return;
File app = new File(home, directoryName);
if (!app.exists() || !app.isDirectory())
return;
host.getLogger().info(sm.getString("userConfig.deploy", user));
// Deploy the web application for this user
try {
Class<?> clazz = Class.forName(contextClass);
Context context = (Context) clazz.newInstance();
context.setPath(contextPath);
context.setDocBase(app.toString());
clazz = Class.forName(configClass);
LifecycleListener listener = (LifecycleListener) clazz.newInstance();
context.addLifecycleListener(listener);
host.addChild(context);
} catch (Exception e) {
host.getLogger().error(sm.getString("userConfig.error", user), e);
}
}
use of org.apache.catalina.LifecycleListener in project tomcat by apache.
the class StandardContextSF method storeChildren.
/**
* Store the specified context element children.
*
* @param aWriter Current output writer
* @param indent Indentation level
* @param aContext Context to store
* @param parentDesc The element description
* @throws Exception Configuration storing error
*/
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aContext, StoreDescription parentDesc) throws Exception {
if (aContext instanceof StandardContext) {
StandardContext context = (StandardContext) aContext;
// Store nested <Listener> elements
LifecycleListener[] listeners = context.findLifecycleListeners();
ArrayList<LifecycleListener> listenersArray = new ArrayList<>();
for (LifecycleListener listener : listeners) {
if (!(listener instanceof ThreadLocalLeakPreventionListener)) {
listenersArray.add(listener);
}
}
storeElementArray(aWriter, indent, listenersArray.toArray());
// Store nested <Valve> elements
Valve[] valves = context.getPipeline().getValves();
storeElementArray(aWriter, indent, valves);
// Store nested <Loader> elements
Loader loader = context.getLoader();
storeElement(aWriter, indent, loader);
// Store nested <Manager> elements
if (context.getCluster() == null || !context.getDistributable()) {
Manager manager = context.getManager();
storeElement(aWriter, indent, manager);
}
// Store nested <Realm> element
Realm realm = context.getRealm();
if (realm != null) {
Realm parentRealm = null;
// @TODO is this case possible?
if (context.getParent() != null) {
parentRealm = context.getParent().getRealm();
}
if (realm != parentRealm) {
storeElement(aWriter, indent, realm);
}
}
// Store nested resources
WebResourceRoot resources = context.getResources();
storeElement(aWriter, indent, resources);
// Store nested <WrapperListener> elements
String[] wLifecycles = context.findWrapperLifecycles();
getStoreAppender().printTagArray(aWriter, "WrapperListener", indent + 2, wLifecycles);
// Store nested <WrapperLifecycle> elements
String[] wListeners = context.findWrapperListeners();
getStoreAppender().printTagArray(aWriter, "WrapperLifecycle", indent + 2, wListeners);
// Store nested <Parameter> elements
ApplicationParameter[] appParams = context.findApplicationParameters();
storeElementArray(aWriter, indent, appParams);
// Store nested naming resources elements (EJB,Resource,...)
NamingResourcesImpl nresources = context.getNamingResources();
storeElement(aWriter, indent, nresources);
// Store nested watched resources <WatchedResource>
String[] wresources = context.findWatchedResources();
wresources = filterWatchedResources(context, wresources);
getStoreAppender().printTagArray(aWriter, "WatchedResource", indent + 2, wresources);
// Store nested <JarScanner> elements
JarScanner jarScanner = context.getJarScanner();
storeElement(aWriter, indent, jarScanner);
// Store nested <CookieProcessor> elements
CookieProcessor cookieProcessor = context.getCookieProcessor();
storeElement(aWriter, indent, cookieProcessor);
}
}
use of org.apache.catalina.LifecycleListener in project tomcat by apache.
the class CatalinaClusterSF method storeChildren.
/**
* Store the specified Cluster children.
*
* @param aWriter
* PrintWriter to which we are storing
* @param indent
* Number of spaces to indent this element
* @param aCluster
* Cluster whose properties are being stored
*
* @exception Exception
* if an exception occurs while storing
*/
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aCluster, StoreDescription parentDesc) throws Exception {
if (aCluster instanceof CatalinaCluster) {
CatalinaCluster cluster = (CatalinaCluster) aCluster;
if (cluster instanceof SimpleTcpCluster) {
SimpleTcpCluster tcpCluster = (SimpleTcpCluster) cluster;
// Store nested <Manager> element
ClusterManager manager = tcpCluster.getManagerTemplate();
if (manager != null) {
storeElement(aWriter, indent, manager);
}
}
// Store nested <Channel> element
Channel channel = cluster.getChannel();
if (channel != null) {
storeElement(aWriter, indent, channel);
}
// Store nested <Deployer> element
ClusterDeployer deployer = cluster.getClusterDeployer();
if (deployer != null) {
storeElement(aWriter, indent, deployer);
}
// Store nested <Valve> element
// ClusterValve are not store at Hosts element, see
Valve[] valves = cluster.getValves();
storeElementArray(aWriter, indent, valves);
if (aCluster instanceof SimpleTcpCluster) {
// Store nested <Listener> elements
LifecycleListener[] listeners = ((SimpleTcpCluster) cluster).findLifecycleListeners();
storeElementArray(aWriter, indent, listeners);
// Store nested <ClusterListener> elements
ClusterListener[] mlisteners = ((SimpleTcpCluster) cluster).findClusterListeners();
List<ClusterListener> clusterListeners = new ArrayList<>();
for (ClusterListener clusterListener : mlisteners) {
if (clusterListener != deployer) {
clusterListeners.add(clusterListener);
}
}
storeElementArray(aWriter, indent, clusterListeners.toArray());
}
}
}
use of org.apache.catalina.LifecycleListener in project tomcat by apache.
the class ConnectorSF method storeChildren.
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aConnector, StoreDescription parentDesc) throws Exception {
if (aConnector instanceof Connector) {
Connector connector = (Connector) aConnector;
// Store nested <Listener> elements
LifecycleListener[] listeners = connector.findLifecycleListeners();
storeElementArray(aWriter, indent, listeners);
// Store nested <UpgradeProtocol> elements
UpgradeProtocol[] upgradeProtocols = connector.findUpgradeProtocols();
storeElementArray(aWriter, indent, upgradeProtocols);
// Store nested <SSLHostConfig> elements
SSLHostConfig[] hostConfigs = connector.findSslHostConfigs();
storeElementArray(aWriter, indent, hostConfigs);
}
}
Aggregations