Search in sources :

Example 11 with Valve

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

the class StandardHostSF method storeChildren.

/**
     * Store the specified Host properties and children
     * (Listener,Alias,Realm,Valve,Cluster, Context)
     *
     * @param aWriter
     *            PrintWriter to which we are storing
     * @param indent
     *            Number of spaces to indent this element
     * @param aHost
     *            Host whose properties are being stored
     *
     * @exception Exception
     *                if an exception occurs while storing
     */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aHost, StoreDescription parentDesc) throws Exception {
    if (aHost instanceof StandardHost) {
        StandardHost host = (StandardHost) aHost;
        // Store nested <Listener> elements
        LifecycleListener[] listeners = ((Lifecycle) host).findLifecycleListeners();
        storeElementArray(aWriter, indent, listeners);
        // Store nested <Alias> elements
        String[] aliases = host.findAliases();
        getStoreAppender().printTagArray(aWriter, "Alias", indent + 2, aliases);
        // Store nested <Realm> element
        Realm realm = host.getRealm();
        if (realm != null) {
            Realm parentRealm = null;
            if (host.getParent() != null) {
                parentRealm = host.getParent().getRealm();
            }
            if (realm != parentRealm) {
                storeElement(aWriter, indent, realm);
            }
        }
        // Store nested <Valve> elements
        Valve[] valves = host.getPipeline().getValves();
        if (valves != null && valves.length > 0) {
            List<Valve> hostValves = new ArrayList<>();
            for (int i = 0; i < valves.length; i++) {
                if (!(valves[i] instanceof ClusterValve))
                    hostValves.add(valves[i]);
            }
            storeElementArray(aWriter, indent, hostValves.toArray());
        }
        // store all <Cluster> elements
        Cluster cluster = host.getCluster();
        if (cluster != null) {
            Cluster parentCluster = null;
            if (host.getParent() != null) {
                parentCluster = host.getParent().getCluster();
            }
            if (cluster != parentCluster) {
                storeElement(aWriter, indent, cluster);
            }
        }
        // store all <Context> elements
        Container[] children = host.findChildren();
        storeElementArray(aWriter, indent, children);
    }
}
Also used : Lifecycle(org.apache.catalina.Lifecycle) ArrayList(java.util.ArrayList) Cluster(org.apache.catalina.Cluster) LifecycleListener(org.apache.catalina.LifecycleListener) ClusterValve(org.apache.catalina.ha.ClusterValve) Container(org.apache.catalina.Container) StandardHost(org.apache.catalina.core.StandardHost) ClusterValve(org.apache.catalina.ha.ClusterValve) Valve(org.apache.catalina.Valve) Realm(org.apache.catalina.Realm)

Example 12 with Valve

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

the class ContainerBase method getAccessLog.

@Override
public AccessLog getAccessLog() {
    if (accessLogScanComplete) {
        return accessLog;
    }
    AccessLogAdapter adapter = null;
    Valve[] valves = getPipeline().getValves();
    for (Valve valve : valves) {
        if (valve instanceof AccessLog) {
            if (adapter == null) {
                adapter = new AccessLogAdapter((AccessLog) valve);
            } else {
                adapter.add((AccessLog) valve);
            }
        }
    }
    if (adapter != null) {
        accessLog = adapter;
    }
    accessLogScanComplete = true;
    return accessLog;
}
Also used : AccessLog(org.apache.catalina.AccessLog) Valve(org.apache.catalina.Valve)

Example 13 with Valve

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

the class ContainerBase method backgroundProcess.

/**
     * Execute a periodic task, such as reloading, etc. This method will be
     * invoked inside the classloading context of this container. Unexpected
     * throwables will be caught and logged.
     */
@Override
public void backgroundProcess() {
    if (!getState().isAvailable())
        return;
    Cluster cluster = getClusterInternal();
    if (cluster != null) {
        try {
            cluster.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("containerBase.backgroundProcess.cluster", cluster), e);
        }
    }
    Realm realm = getRealmInternal();
    if (realm != null) {
        try {
            realm.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("containerBase.backgroundProcess.realm", realm), e);
        }
    }
    Valve current = pipeline.getFirst();
    while (current != null) {
        try {
            current.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("containerBase.backgroundProcess.valve", current), e);
        }
        current = current.getNext();
    }
    fireLifecycleEvent(Lifecycle.PERIODIC_EVENT, null);
}
Also used : Cluster(org.apache.catalina.Cluster) Valve(org.apache.catalina.Valve) Realm(org.apache.catalina.Realm) LifecycleException(org.apache.catalina.LifecycleException)

Example 14 with Valve

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

the class ContainerMBean method addValve.

/**
     * Adds a valve to this Container instance.
     *
     * @param valveType ClassName of the valve to be added
     * @return the MBean name of the new valve
     * @throws MBeanException if adding the valve failed
     */
public String addValve(String valveType) throws MBeanException {
    Valve valve = (Valve) newInstance(valveType);
    Container container = doGetManagedResource();
    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) JmxEnabled(org.apache.catalina.JmxEnabled)

Example 15 with Valve

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

the class SimpleTcpCluster method unregisterClusterValve.

/**
     * unregister all cluster valve to host or engine
     */
protected void unregisterClusterValve() {
    for (Iterator<Valve> iter = valves.iterator(); iter.hasNext(); ) {
        ClusterValve valve = (ClusterValve) iter.next();
        if (log.isDebugEnabled())
            log.debug("Invoking removeValve on " + getContainer() + " with class=" + valve.getClass().getName());
        if (valve != null) {
            container.getPipeline().removeValve(valve);
            valve.setCluster(null);
        }
    }
}
Also used : Valve(org.apache.catalina.Valve) JvmRouteBinderValve(org.apache.catalina.ha.session.JvmRouteBinderValve) ClusterValve(org.apache.catalina.ha.ClusterValve) ClusterValve(org.apache.catalina.ha.ClusterValve)

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