Search in sources :

Example 6 with Valve

use of org.apache.catalina.Valve in project tomcat by apache.

the class StandardPipeline method startInternal.

/**
     * Start {@link Valve}s) in this pipeline and implement the requirements
     * of {@link LifecycleBase#startInternal()}.
     *
     * @exception LifecycleException if this component detects a fatal error
     *  that prevents this component from being used
     */
@Override
protected synchronized void startInternal() throws LifecycleException {
    // Start the Valves in our pipeline (including the basic), if any
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        if (current instanceof Lifecycle)
            ((Lifecycle) current).start();
        current = current.getNext();
    }
    setState(LifecycleState.STARTING);
}
Also used : Lifecycle(org.apache.catalina.Lifecycle) Valve(org.apache.catalina.Valve)

Example 7 with Valve

use of org.apache.catalina.Valve in project tomcat by apache.

the class MBeanFactory method createValve.

/**
     * Create a new Valve and associate it with a {@link Container}.
     *
     * @param className The fully qualified class name of the {@link Valve} to
     *                  create
     * @param parent    The MBean name of the associated parent
     *                  {@link Container}.
     *
     * @return  The MBean name of the {@link Valve} that was created or
     *          <code>null</code> if the {@link Valve} does not implement
     *          {@link JmxEnabled}.
     * @exception Exception if an MBean cannot be created or registered
     */
public String createValve(String className, String parent) throws Exception {
    // Look for the parent
    ObjectName parentName = new ObjectName(parent);
    Container container = getParentContainerFromParent(parentName);
    if (container == null) {
        // TODO
        throw new IllegalArgumentException();
    }
    Valve valve = (Valve) Class.forName(className).newInstance();
    container.getPipeline().addValve(valve);
    if (valve instanceof JmxEnabled) {
        return ((JmxEnabled) valve).getObjectName().toString();
    } else {
        return null;
    }
}
Also used : Container(org.apache.catalina.Container) Valve(org.apache.catalina.Valve) ObjectName(javax.management.ObjectName) JmxEnabled(org.apache.catalina.JmxEnabled)

Example 8 with Valve

use of org.apache.catalina.Valve in project tomcat by apache.

the class MBeanFactory method removeValve.

/**
     * Remove an existing Valve.
     *
     * @param name MBean Name of the component to remove
     *
     * @exception Exception if a component cannot be removed
     */
public void removeValve(String name) throws Exception {
    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    Container container = getParentContainerFromChild(oname);
    Valve[] valves = container.getPipeline().getValves();
    for (int i = 0; i < valves.length; i++) {
        ObjectName voname = ((JmxEnabled) valves[i]).getObjectName();
        if (voname.equals(oname)) {
            container.getPipeline().removeValve(valves[i]);
        }
    }
}
Also used : Container(org.apache.catalina.Container) Valve(org.apache.catalina.Valve) ObjectName(javax.management.ObjectName) JmxEnabled(org.apache.catalina.JmxEnabled)

Example 9 with Valve

use of org.apache.catalina.Valve 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 10 with Valve

use of org.apache.catalina.Valve 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)

Aggregations

Valve (org.apache.catalina.Valve)34 Container (org.apache.catalina.Container)10 ArrayList (java.util.ArrayList)8 Lifecycle (org.apache.catalina.Lifecycle)8 JmxEnabled (org.apache.catalina.JmxEnabled)6 LifecycleException (org.apache.catalina.LifecycleException)6 LifecycleListener (org.apache.catalina.LifecycleListener)6 ObjectName (javax.management.ObjectName)5 Realm (org.apache.catalina.Realm)5 ClusterValve (org.apache.catalina.ha.ClusterValve)5 Contained (org.apache.catalina.Contained)4 Pipeline (org.apache.catalina.Pipeline)4 Cluster (org.apache.catalina.Cluster)3 StandardContext (org.apache.catalina.core.StandardContext)3 IOException (java.io.IOException)2 ServletContext (javax.servlet.ServletContext)2 JvmRouteBinderValve (org.apache.catalina.ha.session.JvmRouteBinderValve)2 AccessLogValve (org.apache.catalina.valves.AccessLogValve)2 RemoteIpValve (org.apache.catalina.valves.RemoteIpValve)2 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)2