Search in sources :

Example 26 with Valve

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

the class StandardHost method getValveNames.

// -------------------- JMX  --------------------
/**
      * @return the MBean Names of the Valves associated with this Host
      *
      * @exception Exception if an MBean cannot be created or registered
      */
public String[] getValveNames() throws Exception {
    Valve[] valves = this.getPipeline().getValves();
    String[] mbeanNames = new String[valves.length];
    for (int i = 0; i < valves.length; i++) {
        if (valves[i] instanceof JmxEnabled) {
            ObjectName oname = ((JmxEnabled) valves[i]).getObjectName();
            if (oname != null) {
                mbeanNames[i] = oname.toString();
            }
        }
    }
    return mbeanNames;
}
Also used : Valve(org.apache.catalina.Valve) JmxEnabled(org.apache.catalina.JmxEnabled) ObjectName(javax.management.ObjectName)

Example 27 with Valve

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

the class AsyncContextImpl method setErrorState.

public void setErrorState(Throwable t, boolean fireOnError) {
    if (t != null)
        request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
    request.getCoyoteRequest().action(ActionCode.ASYNC_ERROR, null);
    if (fireOnError) {
        AsyncEvent errorEvent = new AsyncEvent(event.getAsyncContext(), event.getSuppliedRequest(), event.getSuppliedResponse(), t);
        List<AsyncListenerWrapper> listenersCopy = new ArrayList<>();
        listenersCopy.addAll(listeners);
        for (AsyncListenerWrapper listener : listenersCopy) {
            try {
                listener.fireOnError(errorEvent);
            } catch (Throwable t2) {
                ExceptionUtils.handleThrowable(t);
                log.warn("onError() failed for listener of type [" + listener.getClass().getName() + "]", t2);
            }
        }
    }
    AtomicBoolean result = new AtomicBoolean();
    request.getCoyoteRequest().action(ActionCode.ASYNC_IS_ERROR, result);
    if (result.get()) {
        // SRV.2.3.3.3 (search for "error dispatch")
        if (servletResponse instanceof HttpServletResponse) {
            ((HttpServletResponse) servletResponse).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
        Host host = (Host) context.getParent();
        Valve stdHostValve = host.getPipeline().getBasic();
        if (stdHostValve instanceof StandardHostValve) {
            ((StandardHostValve) stdHostValve).throwable(request, request.getResponse(), t);
        }
        request.getCoyoteRequest().action(ActionCode.ASYNC_IS_ERROR, result);
        if (result.get()) {
            // Still in the error state. The error page did not call
            // complete() or dispatch(). Complete the async processing.
            complete();
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) HttpServletResponse(javax.servlet.http.HttpServletResponse) Valve(org.apache.catalina.Valve) Host(org.apache.catalina.Host) AsyncEvent(javax.servlet.AsyncEvent)

Example 28 with Valve

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

the class StandardPipeline method removeValve.

/**
     * Remove the specified Valve from the pipeline associated with this
     * Container, if it is found; otherwise, do nothing.  If the Valve is
     * found and removed, the Valve's <code>setContainer(null)</code> method
     * will be called if it implements <code>Contained</code>.
     *
     * @param valve Valve to be removed
     */
@Override
public void removeValve(Valve valve) {
    Valve current;
    if (first == valve) {
        first = first.getNext();
        current = null;
    } else {
        current = first;
    }
    while (current != null) {
        if (current.getNext() == valve) {
            current.setNext(valve.getNext());
            break;
        }
        current = current.getNext();
    }
    if (first == basic)
        first = null;
    if (valve instanceof Contained)
        ((Contained) valve).setContainer(null);
    if (valve instanceof Lifecycle) {
        // Stop this valve if necessary
        if (getState().isAvailable()) {
            try {
                ((Lifecycle) valve).stop();
            } catch (LifecycleException e) {
                log.error("StandardPipeline.removeValve: stop: ", e);
            }
        }
        try {
            ((Lifecycle) valve).destroy();
        } catch (LifecycleException e) {
            log.error("StandardPipeline.removeValve: destroy: ", e);
        }
    }
    container.fireContainerEvent(Container.REMOVE_VALVE_EVENT, valve);
}
Also used : Contained(org.apache.catalina.Contained) LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) Valve(org.apache.catalina.Valve)

Example 29 with Valve

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

the class StandardPipeline method stopInternal.

/**
     * Stop {@link Valve}s) in this pipeline and implement the requirements
     * of {@link LifecycleBase#stopInternal()}.
     *
     * @exception LifecycleException if this component detects a fatal error
     *  that prevents this component from being used
     */
@Override
protected synchronized void stopInternal() throws LifecycleException {
    setState(LifecycleState.STOPPING);
    // Stop 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).stop();
        current = current.getNext();
    }
}
Also used : Lifecycle(org.apache.catalina.Lifecycle) Valve(org.apache.catalina.Valve)

Example 30 with Valve

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

the class StandardPipeline method addValve.

/**
     * <p>Add a new Valve to the end of the pipeline associated with this
     * Container.  Prior to adding the Valve, the Valve's
     * <code>setContainer()</code> method will be called, if it implements
     * <code>Contained</code>, with the owning Container as an argument.
     * The method may throw an
     * <code>IllegalArgumentException</code> if this Valve chooses not to
     * be associated with this Container, or <code>IllegalStateException</code>
     * if it is already associated with a different Container.</p>
     *
     * @param valve Valve to be added
     *
     * @exception IllegalArgumentException if this Container refused to
     *  accept the specified Valve
     * @exception IllegalArgumentException if the specified Valve refuses to be
     *  associated with this Container
     * @exception IllegalStateException if the specified Valve is already
     *  associated with a different Container
     */
@Override
public void addValve(Valve valve) {
    // Validate that we can add this Valve
    if (valve instanceof Contained)
        ((Contained) valve).setContainer(this.container);
    // Start the new component if necessary
    if (getState().isAvailable()) {
        if (valve instanceof Lifecycle) {
            try {
                ((Lifecycle) valve).start();
            } catch (LifecycleException e) {
                log.error("StandardPipeline.addValve: start: ", e);
            }
        }
    }
    // Add this Valve to the set associated with this Pipeline
    if (first == null) {
        first = valve;
        valve.setNext(basic);
    } else {
        Valve current = first;
        while (current != null) {
            if (current.getNext() == basic) {
                current.setNext(valve);
                valve.setNext(basic);
                break;
            }
            current = current.getNext();
        }
    }
    container.fireContainerEvent(Container.ADD_VALVE_EVENT, valve);
}
Also used : Contained(org.apache.catalina.Contained) LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) Valve(org.apache.catalina.Valve)

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