Search in sources :

Example 1 with LifecycleListener

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);
}
Also used : LifecycleListener(org.apache.catalina.LifecycleListener)

Example 2 with LifecycleListener

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);
    }
}
Also used : Context(org.apache.catalina.Context) LifecycleListener(org.apache.catalina.LifecycleListener) File(java.io.File)

Example 3 with LifecycleListener

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);
    }
}
Also used : ApplicationParameter(org.apache.tomcat.util.descriptor.web.ApplicationParameter) ArrayList(java.util.ArrayList) Loader(org.apache.catalina.Loader) LifecycleListener(org.apache.catalina.LifecycleListener) Manager(org.apache.catalina.Manager) JarScanner(org.apache.tomcat.JarScanner) ThreadLocalLeakPreventionListener(org.apache.catalina.core.ThreadLocalLeakPreventionListener) CookieProcessor(org.apache.tomcat.util.http.CookieProcessor) StandardContext(org.apache.catalina.core.StandardContext) Valve(org.apache.catalina.Valve) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) Realm(org.apache.catalina.Realm) WebResourceRoot(org.apache.catalina.WebResourceRoot)

Example 4 with LifecycleListener

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());
        }
    }
}
Also used : ClusterDeployer(org.apache.catalina.ha.ClusterDeployer) Channel(org.apache.catalina.tribes.Channel) ArrayList(java.util.ArrayList) LifecycleListener(org.apache.catalina.LifecycleListener) CatalinaCluster(org.apache.catalina.ha.CatalinaCluster) SimpleTcpCluster(org.apache.catalina.ha.tcp.SimpleTcpCluster) ClusterListener(org.apache.catalina.ha.ClusterListener) Valve(org.apache.catalina.Valve) ClusterManager(org.apache.catalina.ha.ClusterManager)

Example 5 with LifecycleListener

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);
    }
}
Also used : Connector(org.apache.catalina.connector.Connector) UpgradeProtocol(org.apache.coyote.UpgradeProtocol) LifecycleListener(org.apache.catalina.LifecycleListener) SSLHostConfig(org.apache.tomcat.util.net.SSLHostConfig)

Aggregations

LifecycleListener (org.apache.catalina.LifecycleListener)22 Container (org.apache.catalina.Container)6 Valve (org.apache.catalina.Valve)6 File (java.io.File)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Lifecycle (org.apache.catalina.Lifecycle)5 JarFile (java.util.jar.JarFile)4 Context (org.apache.catalina.Context)4 StandardContext (org.apache.catalina.core.StandardContext)4 Realm (org.apache.catalina.Realm)3 ClusterValve (org.apache.catalina.ha.ClusterValve)3 FileInputStream (java.io.FileInputStream)2 Cluster (org.apache.catalina.Cluster)2 LifecycleException (org.apache.catalina.LifecycleException)2 Manager (org.apache.catalina.Manager)2 Connector (org.apache.catalina.connector.Connector)2 StandardHost (org.apache.catalina.core.StandardHost)2 NamingResourcesImpl (org.apache.catalina.deploy.NamingResourcesImpl)2 BufferedOutputStream (java.io.BufferedOutputStream)1