Search in sources :

Example 46 with Valve

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

the class AuthenticatorBase method startInternal.

/**
 * Start this component and implement the requirements
 * of {@link org.apache.catalina.util.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 {
    // Look up the SingleSignOn implementation in our request processing
    // path, if there is one
    Container parent = context.getParent();
    while ((sso == null) && (parent != null)) {
        Valve[] valves = parent.getPipeline().getValves();
        for (int i = 0; i < valves.length; i++) {
            if (valves[i] instanceof SingleSignOn) {
                sso = (SingleSignOn) valves[i];
                break;
            }
        }
        if (sso == null)
            parent = parent.getParent();
    }
    if (log.isDebugEnabled()) {
        if (sso != null)
            log.debug("Found SingleSignOn Valve at " + sso);
        else
            log.debug("No SingleSignOn Valve is present");
    }
    sessionIdGenerator = new StandardSessionIdGenerator();
    sessionIdGenerator.setSecureRandomAlgorithm(getSecureRandomAlgorithm());
    sessionIdGenerator.setSecureRandomClass(getSecureRandomClass());
    sessionIdGenerator.setSecureRandomProvider(getSecureRandomProvider());
    super.startInternal();
}
Also used : Container(org.apache.catalina.Container) StandardSessionIdGenerator(org.apache.catalina.util.StandardSessionIdGenerator) Valve(org.apache.catalina.Valve) SecurityConstraint(org.apache.catalina.deploy.SecurityConstraint)

Example 47 with Valve

use of org.apache.catalina.Valve in project tomcat70 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<AsyncListenerWrapper>();
        listenersCopy.addAll(listeners);
        for (AsyncListenerWrapper listener : listenersCopy) {
            try {
                listener.fireOnError(errorEvent);
            } catch (Throwable t2) {
                ExceptionUtils.handleThrowable(t2);
                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()) {
        // No listener called dispatch() or complete(). This is an error.
        // SRV.2.3.3.3 (search for "error dispatch")
        // Take a local copy to avoid threading issues if another thread
        // clears this (can happen during error handling with non-container
        // threads)
        ServletResponse servletResponse = this.servletResponse;
        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) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) ArrayList(java.util.ArrayList) HttpServletResponse(javax.servlet.http.HttpServletResponse) Valve(org.apache.catalina.Valve) Host(org.apache.catalina.Host) AsyncEvent(javax.servlet.AsyncEvent)

Example 48 with Valve

use of org.apache.catalina.Valve in project tomcat70 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 LifecycleMBeanBase}.
 */
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 LifecycleMBeanBase) {
        return ((LifecycleMBeanBase) valve).getObjectName().toString();
    } else {
        return null;
    }
}
Also used : Container(org.apache.catalina.Container) LifecycleMBeanBase(org.apache.catalina.util.LifecycleMBeanBase) Valve(org.apache.catalina.Valve) AccessLogValve(org.apache.catalina.valves.AccessLogValve) RemoteHostValve(org.apache.catalina.valves.RemoteHostValve) RemoteAddrValve(org.apache.catalina.valves.RemoteAddrValve) ObjectName(javax.management.ObjectName)

Example 49 with Valve

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

the class ContainerMBean method removeValve.

/**
 * Remove an existing Valve.
 *
 * @param valveName MBean Name of the Valve to remove
 *
 * @exception MBeanException if a component cannot be removed
 */
public void removeValve(String valveName) throws MBeanException {
    ContainerBase container = null;
    try {
        container = (ContainerBase) getManagedResource();
    } catch (InstanceNotFoundException e) {
        throw new MBeanException(e);
    } catch (RuntimeOperationsException e) {
        throw new MBeanException(e);
    } catch (InvalidTargetObjectTypeException e) {
        throw new MBeanException(e);
    }
    ObjectName oname;
    try {
        oname = new ObjectName(valveName);
    } catch (MalformedObjectNameException e) {
        throw new MBeanException(e);
    } catch (NullPointerException e) {
        throw new MBeanException(e);
    }
    if (container != null) {
        Valve[] valves = container.getPipeline().getValves();
        for (int i = 0; i < valves.length; i++) {
            ObjectName voname = ((ValveBase) valves[i]).getObjectName();
            if (voname.equals(oname)) {
                container.getPipeline().removeValve(valves[i]);
            }
        }
    }
}
Also used : ContainerBase(org.apache.catalina.core.ContainerBase) MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) Valve(org.apache.catalina.Valve) ValveBase(org.apache.catalina.valves.ValveBase) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) RuntimeOperationsException(javax.management.RuntimeOperationsException) ObjectName(javax.management.ObjectName)

Example 50 with Valve

use of org.apache.catalina.Valve in project tomcat70 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)72 ArrayList (java.util.ArrayList)15 Lifecycle (org.apache.catalina.Lifecycle)14 Container (org.apache.catalina.Container)13 LifecycleException (org.apache.catalina.LifecycleException)13 Pipeline (org.apache.catalina.Pipeline)11 ObjectName (javax.management.ObjectName)9 Realm (org.apache.catalina.Realm)8 AccessLogValve (org.apache.catalina.valves.AccessLogValve)8 Contained (org.apache.catalina.Contained)7 LifecycleListener (org.apache.catalina.LifecycleListener)7 Request (org.apache.catalina.connector.Request)7 ClusterValve (org.apache.catalina.ha.ClusterValve)7 RemoteIpValve (org.apache.catalina.valves.RemoteIpValve)7 Test (org.junit.Test)7 Context (org.apache.catalina.Context)6 JmxEnabled (org.apache.catalina.JmxEnabled)6 Response (org.apache.catalina.connector.Response)6 IOException (java.io.IOException)5 ContainerBase (org.apache.catalina.core.ContainerBase)5