org.apache.catalina.Valve - java examples

Here are the examples of the java api org.apache.catalina.Valve taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

126 Examples 7

19 View Complete Implementation : ValveBase.java
Copyright Apache License 2.0
Author : apache
/**
 * Set the Valve that follows this one in the pipeline it is part of.
 *
 * @param valve The new next valve
 */
@Override
public void setNext(Valve valve) {
    this.next = valve;
}

19 View Complete Implementation : MongoLogBenchmark.java
Copyright Apache License 2.0
Author : chanjarster
@Override
protected void setUpValve(Tomcat tomcat) throws UnknownHostException {
    // remove AccessLogValve
    for (Valve vl : tomcat.getHost().getPipeline().getValves()) {
        if (vl.getClreplaced().equals(AccessLogValve.clreplaced)) {
            tomcat.getHost().getPipeline().removeValve(vl);
        }
    }
    mongoClient = new MongoClient(new MongoClientURI(url));
    db = mongoClient.getDB(dbName);
    MongoAccessLogValve mavl = new MongoAccessLogValve();
    mavl.setUri(url);
    mavl.setDbName(dbName);
    mavl.setCollName(collName);
    mavl.setPattern(pattern);
    tomcat.getHost().getPipeline().addValve(mavl);
}

19 View Complete Implementation : ContainerMBean.java
Copyright Apache License 2.0
Author : apache
/**
 * Adds a valve to this Container instance.
 *
 * @param valveType ClreplacedName 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;
    }
}

19 View Complete Implementation : ContextSelectionHostValve.java
Copyright Apache License 2.0
Author : ops4j
public clreplaced ContextSelectionHostValve extends ValveBase {

    Valve standardHostValve;

    Mapper mapper;

    public ContextSelectionHostValve(Valve standardHostValve, Mapper mapper) {
        super(true);
        this.standardHostValve = standardHostValve;
        this.mapper = mapper;
    }

    @Override
    public void invoke(Request request, Response response) throws IOException, ServletException {
        /*
		 * The OSGi HTTP service (and the whiteboard extender) will create one
		 * Context with an empty context path per HttpContext. Tomcat will
		 * interpret this as different context versions.
		 * 
		 * At this point all these Contexts will be in the contexts array in the
		 * mappingData attribute of the request. The context and the wrapper
		 * element in the mappingData are set to the last element of the
		 * contexts array (which is the last version for Tomcat).
		 * 
		 * This code will select the first context element that has a wrapper
		 * for the request URI and set the context and wrapper elements in the
		 * mapping data accordingly. Afterwards the standard host valve is
		 * executed with the modified request.
		 */
        MappingData md = request.getMappingData();
        if (md.contexts != null && md.contexts.length > 1 && md.wrapper == null) {
            for (int i = 0; md.wrapper == null && i < md.contexts.length; i++) {
                md.context = md.contexts[i];
                mapper.map(md.context, request.getDecodedRequestURIMB(), md);
            }
        }
        standardHostValve.invoke(request, response);
    }

    @Override
    public void setContainer(Container container) {
        super.setContainer(container);
        if (standardHostValve instanceof Contained) {
            ((Contained) standardHostValve).setContainer(container);
        }
    }

    @Override
    protected void startInternal() throws LifecycleException {
        super.startInternal();
        if (standardHostValve instanceof Lifecycle) {
            ((Lifecycle) standardHostValve).start();
        }
    }

    @Override
    protected void stopInternal() throws LifecycleException {
        super.stopInternal();
        if (standardHostValve instanceof Lifecycle) {
            ((Lifecycle) standardHostValve).stop();
        }
    }
}

19 View Complete Implementation : StandardPipeline.java
Copyright Apache License 2.0
Author : how2j
/**
 * 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);
}

19 View Complete Implementation : StandardPipeline.java
Copyright Apache License 2.0
Author : apache
@Override
public void findNonAsyncValves(Set<String> result) {
    Valve valve = (first != null) ? first : basic;
    while (valve != null) {
        if (!valve.isAsyncSupported()) {
            result.add(valve.getClreplaced().getName());
        }
        valve = valve.getNext();
    }
}

19 View Complete Implementation : LazyValve.java
Copyright Apache License 2.0
Author : apache
@Override
public void setNext(final Valve valve) {
    this.next = valve;
    if (delegate != null) {
        delegate.setNext(next);
    }
}

19 View Complete Implementation : StandardPipeline.java
Copyright Apache License 2.0
Author : apache
// --------------------------------------------------------- Public Methods
@Override
public boolean isAsyncSupported() {
    Valve valve = (first != null) ? first : basic;
    boolean supported = true;
    while (supported && valve != null) {
        supported = supported & valve.isAsyncSupported();
        valve = valve.getNext();
    }
    return supported;
}

19 View Complete Implementation : ContainerBase.java
Copyright Apache License 2.0
Author : how2j
// ------------------------------------------------------- Pipeline Methods
/**
 * Convenience method, intended for use by the digester to simplify the
 * process of adding Valves to containers. See
 * {@link Pipeline#addValve(Valve)} for full details. Components other than
 * the digester should use {@link #getPipeline()}.{@link #addValve(Valve)}
 * in case a future implementation provides an alternative method for the
 * digester to use.
 *
 * @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 replacedociated with this
 *                Container
 * @exception IllegalStateException
 *                if the specified Valve is already replacedociated with a
 *                different Container
 */
public synchronized void addValve(Valve valve) {
    pipeline.addValve(valve);
}

19 View Complete Implementation : TestSSLValve.java
Copyright Apache License 2.0
Author : apache
public clreplaced TestSSLValve {

    public static clreplaced MockRequest extends Request {

        public MockRequest() {
            super(EasyMock.createMock(Connector.clreplaced));
            setCoyoteRequest(new org.apache.coyote.Request());
        }

        @Override
        public void setAttribute(String name, Object value) {
            getCoyoteRequest().getAttributes().put(name, value);
        }

        @Override
        public Object getAttribute(String name) {
            return getCoyoteRequest().getAttribute(name);
        }

        public void setHeader(String header, String value) {
            getCoyoteRequest().getMimeHeaders().setValue(header).setString(value);
        }

        public void addHeader(String header, String value) {
            getCoyoteRequest().getMimeHeaders().addValue(header).setString(value);
        }
    }

    private static final String[] CERTIFICATE_LINES = new String[] { "-----BEGIN CERTIFICATE-----", "MIIFXTCCA0WgAwIBAgIJANFf3YTJgYifMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV", "BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX", "aWRnaXRzIFB0eSBMdGQwHhcNMTcwNTI2MjEzNjM3WhcNMTgwNTI2MjEzNjM3WjBF", "MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50", "ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIIC", "CgKCAgEA2ykNBanZz4cVITNpZcWNVmErUzqgSNrK361mj9vEdB1UkHatwal9jVrR", "QvFgfiZ8Gl+/85t0ebJhJ+rIr1ww6JE7v2s2MThENj95K5EwZOmgvw+CBlBYsFIz", "8BtjlVYy+v7RaGPXfjrFkexQP9UIaiIIog2ClDZirRvb+QxS930/YW5Qo+X6EX6W", "/m/HvlorD25U4ni2FQ0y+EMO2e1jD88cAAMoP5f+Mf6NBK8I6yUeaSuMq7WqtHGV", "e4F1WOg5z9J5c/M69rB0iQr5NUQwZ1mPYf5Kr0P6+TLh8DJphbVvmHJyT3bgofeV", "JYl/kdjiXS5P/jwY9tfmhu04tsyzopWRUFCcj5zCiqZYaMn0wtDn08KaAh9oOlg8", "Z6mJ9i5EybkLm63W7z7LxuM+qnYzq4wKkKdx8hbpASwPqzJkJeXFL/LzhKdZuHiR", "clgPVYnm98URwhObh073dKguG/gkhcnpXcVBBVdVTJZYGBvTpQh0afXd9bcBwOzY", "t4MDpGiQB2fLzBOEZhQ37kUcWPmZw5bNPxhx4yE96Md0rx/Gu4ipAHuqLemb1SL5", "uWNesVmgY3OXaIamQIm9BCwkf8mMvoYdAT+lukTUZLtJ6s2w+Oxnl10tmb+6sTXy", "UB3WcBTp/o3YjAyJPnM1Wq6nVNQ4W2+NbV5purGAP09sumxeJj8CAwEAAaNQME4w", "HQYDVR0OBBYEFCGOYMvymUG2ZZT+lK4LvwEvx731MB8GA1UdIwQYMBaAFCGOYMvy", "mUG2ZZT+lK4LvwEvx731MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggIB", "AG6m4nDYCompUtRVude1qulwwAaYEMHyIIsfymI8uAE7d2o4bGjVpAUOdH/VWSOp", "Rzx0oK6K9cHyiBlKHw5zSZdqcRi++tDX3P9Iy5tXO//zkhMEnSpk6RF2+9JXtyhx", "Gma4yAET1yES+ybiFT21uZrGCC9r69rWG8JRZshc4RVWGwZsd0zrATVqfY0mZurm", "xLgU4UOvkTczjlrLiklwwU68M1DLcILJ5FZGTWeTJ/q1wpIn9isK2siAW/VOcbuG", "xdbGladnIFv+iQfuZG0yjreplacedsBFsQiXi6ONM8GM+dr+61V63/1s73jYcOToEsTMM", "3bHeVffoSkhZvOGTRCI6QhK9wqnIKhAYqu+NbV4OphfE3gOaK+T1cASXUtSQPXoa", "sEoIVmbQsWRBhWvYShVqvINsH/hAT3Cf/+SslprtQUqiyt2ljdgrRFZdoyB3S7ky", "KWoZRvHRj2cKU65LVYwx6U1A8SGmViz4aHMSai0wwKzOVv9MGHeRaVhlMmMsbdfu", "wKoKJv0xYoVwEh1rB8TH8PjbL+6eFLeZXYVZnH71d5JHCghZ8W0a11ZuYkscSQWk", "yoTBqEpJloWksrypqp3iL4PAL5+KkB2zp66+MVAg8LcEDFJggBBJCtv4SCWV7ZOB", "WLu8gep+XCwSn0Wb6D3eFs4DoIiMvQ6g2rS/pk7o5eWj", "-----END CERTIFICATE-----" };

    private SSLValve valve = new SSLValve();

    private MockRequest mockRequest = new MockRequest();

    private Valve mockNext = EasyMock.createMock(Valve.clreplaced);

    @Before
    public void setUp() throws Exception {
        valve.setNext(mockNext);
        mockNext.invoke(mockRequest, null);
        EasyMock.replay(mockNext);
    }

    @Test
    public void testSslHeader() {
        final String headerName = "myheader";
        final String headerValue = "BASE64_HEADER_VALUE";
        mockRequest.setHeader(headerName, headerValue);
        replacedert.replacedertEquals(headerValue, valve.mygetHeader(mockRequest, headerName));
    }

    @Test
    public void testSslHeaderNull() {
        final String headerName = "myheader";
        mockRequest.setHeader(headerName, null);
        replacedert.replacedertNull(valve.mygetHeader(mockRequest, headerName));
    }

    @Test
    public void testSslHeaderNullModHeader() {
        final String headerName = "myheader";
        final String nullModHeaderValue = "(null)";
        mockRequest.setHeader(headerName, nullModHeaderValue);
        replacedert.replacedertNull(valve.mygetHeader(mockRequest, nullModHeaderValue));
    }

    @Test
    public void testSslHeaderNullName() throws Exception {
        replacedert.replacedertNull(valve.mygetHeader(mockRequest, null));
    }

    @Test
    public void testSslHeaderMultiples() throws Exception {
        final String headerName = "myheader";
        final String headerValue = "BASE64_HEADER_VALUE";
        mockRequest.addHeader(headerName, headerValue);
        mockRequest.addHeader(headerName, "anyway won't be found");
        replacedert.replacedertEquals(headerValue, valve.mygetHeader(mockRequest, headerName));
    }

    @Test
    public void testSslClientCertHeaderSingleSpace() throws Exception {
        String singleSpaced = certificateSingleLine(" ");
        mockRequest.setHeader(valve.getSslClientCertHeader(), singleSpaced);
        valve.invoke(mockRequest, null);
        replacedertCertificateParsed();
    }

    @Test
    public void testSslClientCertHeaderMultiSpace() throws Exception {
        String singleSpaced = certificateSingleLine("    ");
        mockRequest.setHeader(valve.getSslClientCertHeader(), singleSpaced);
        valve.invoke(mockRequest, null);
        replacedertCertificateParsed();
    }

    @Test
    public void testSslClientCertHeaderTab() throws Exception {
        String singleSpaced = certificateSingleLine("\t");
        mockRequest.setHeader(valve.getSslClientCertHeader(), singleSpaced);
        valve.invoke(mockRequest, null);
        replacedertCertificateParsed();
    }

    @Test
    public void testSslClientCertNull() throws Exception {
        TesterLogValidationFilter f = TesterLogValidationFilter.add(null, "", null, "org.apache.catalina.valves.SSLValve");
        valve.invoke(mockRequest, null);
        EasyMock.verify(mockNext);
        replacedert.replacedertNull(mockRequest.getAttribute(Globals.CERTIFICATES_ATTR));
        replacedert.replacedertEquals(0, f.getMessageCount());
    }

    @Test
    public void testSslClientCertShorter() throws Exception {
        mockRequest.setHeader(valve.getSslClientCertHeader(), "shorter than hell");
        TesterLogValidationFilter f = TesterLogValidationFilter.add(null, "", null, "org.apache.catalina.valves.SSLValve");
        valve.invoke(mockRequest, null);
        EasyMock.verify(mockNext);
        replacedert.replacedertNull(mockRequest.getAttribute(Globals.CERTIFICATES_ATTR));
        replacedert.replacedertEquals(0, f.getMessageCount());
    }

    @Test
    public void testSslClientCertIgnoredBegin() throws Exception {
        String[] linesBegin = Arrays.copyOf(CERTIFICATE_LINES, CERTIFICATE_LINES.length);
        linesBegin[0] = "3fisjcme3kdsakasdfsadkafsd3";
        String begin = certificateSingleLine(linesBegin, " ");
        mockRequest.setHeader(valve.getSslClientCertHeader(), begin);
        valve.invoke(mockRequest, null);
        replacedertCertificateParsed();
    }

    @Test
    public void testSslClientCertBadFormat() throws Exception {
        String[] linesDeleted = Arrays.copyOf(CERTIFICATE_LINES, CERTIFICATE_LINES.length / 2);
        String deleted = certificateSingleLine(linesDeleted, " ");
        mockRequest.setHeader(valve.getSslClientCertHeader(), deleted);
        TesterLogValidationFilter f = TesterLogValidationFilter.add(Level.WARNING, null, "java.security.cert.CertificateException", "org.apache.catalina.valves.SSLValve");
        valve.invoke(mockRequest, null);
        EasyMock.verify(mockNext);
        replacedert.replacedertNull(mockRequest.getAttribute(Globals.CERTIFICATES_ATTR));
        replacedert.replacedertEquals(1, f.getMessageCount());
    }

    @Test
    public void testClientCertProviderNotFound() throws Exception {
        EasyMock.expect(mockRequest.getConnector().getProperty("clientCertProvider")).andStubReturn("wontBeFound");
        EasyMock.replay(mockRequest.getConnector());
        mockRequest.setHeader(valve.getSslClientCertHeader(), certificateSingleLine(" "));
        TesterLogValidationFilter f = TesterLogValidationFilter.add(Level.SEVERE, null, "java.security.NoSuchProviderException", "org.apache.catalina.valves.SSLValve");
        valve.invoke(mockRequest, null);
        replacedert.replacedertNull(mockRequest.getAttribute(Globals.CERTIFICATES_ATTR));
        replacedert.replacedertEquals(1, f.getMessageCount());
    }

    @Test
    public void testSslCipherHeaderPresent() throws Exception {
        String cipher = "ciphered-with";
        mockRequest.setHeader(valve.getSslCipherHeader(), cipher);
        valve.invoke(mockRequest, null);
        replacedert.replacedertEquals(cipher, mockRequest.getAttribute(Globals.CIPHER_SUITE_ATTR));
    }

    @Test
    public void testSslSessionIdHeaderPresent() throws Exception {
        String session = "ssl-session";
        mockRequest.setHeader(valve.getSslSessionIdHeader(), session);
        valve.invoke(mockRequest, null);
        replacedert.replacedertEquals(session, mockRequest.getAttribute(Globals.SSL_SESSION_ID_ATTR));
    }

    @Test
    public void testSslCipherUserKeySizeHeaderPresent() throws Exception {
        Integer keySize = Integer.valueOf(452);
        mockRequest.setHeader(valve.getSslCipherUserKeySizeHeader(), String.valueOf(keySize));
        valve.invoke(mockRequest, null);
        replacedert.replacedertEquals(keySize, mockRequest.getAttribute(Globals.KEY_SIZE_ATTR));
    }

    @Test(expected = NumberFormatException.clreplaced)
    public void testSslCipherUserKeySizeHeaderBadFormat() throws Exception {
        mockRequest.setHeader(valve.getSslCipherUserKeySizeHeader(), "not-an-integer");
        try {
            valve.invoke(mockRequest, null);
        } catch (NumberFormatException e) {
            replacedert.replacedertNull(mockRequest.getAttribute(Globals.KEY_SIZE_ATTR));
            throw e;
        }
    }

    private static String certificateSingleLine(String[] lines, String separator) {
        StringBuilder singleSpaced = new StringBuilder();
        for (String current : lines) {
            singleSpaced.append(current).append(separator);
        }
        singleSpaced.deleteCharAt(singleSpaced.length() - 1);
        return singleSpaced.toString();
    }

    private static String certificateSingleLine(String separator) {
        return certificateSingleLine(CERTIFICATE_LINES, separator);
    }

    private void replacedertCertificateParsed() throws Exception {
        TesterLogValidationFilter f = TesterLogValidationFilter.add(null, "", null, "org.apache.catalina.valves.SSLValve");
        EasyMock.verify(mockNext);
        X509Certificate[] certificates = (X509Certificate[]) mockRequest.getAttribute(Globals.CERTIFICATES_ATTR);
        replacedert.replacedertNotNull(certificates);
        replacedert.replacedertEquals(1, certificates.length);
        replacedert.replacedertNotNull(certificates[0]);
        replacedert.replacedertEquals(0, f.getMessageCount());
    }
}

19 View Complete Implementation : RedisSessionManager.java
Copyright MIT License
Author : jcoleman
/**
 * 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 {
    super.startInternal();
    setState(LifecycleState.STARTING);
    Boolean attachedToValve = false;
    for (Valve valve : getContainer().getPipeline().getValves()) {
        if (valve instanceof RedisSessionHandlerValve) {
            this.handlerValve = (RedisSessionHandlerValve) valve;
            this.handlerValve.setRedisSessionManager(this);
            log.info("Attached to RedisSessionHandlerValve");
            attachedToValve = true;
            break;
        }
    }
    if (!attachedToValve) {
        String error = "Unable to attach to session handling valve; sessions cannot be saved after the request without the valve starting properly.";
        log.fatal(error);
        throw new LifecycleException(error);
    }
    try {
        initializeSerializer();
    } catch (ClreplacedNotFoundException | InstantiationException | IllegalAccessException e) {
        log.fatal("Unable to load serializer", e);
        throw new LifecycleException(e);
    }
    log.info("Will expire sessions after " + getMaxInactiveInterval() + " seconds");
    initializeDatabaseConnection();
    setDistributable(true);
}

19 View Complete Implementation : StandardPipeline.java
Copyright Apache License 2.0
Author : how2j
public ObjectName[] getValveObjectNames() {
    ArrayList<ObjectName> valveList = new ArrayList<ObjectName>();
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        if (current instanceof ValveBase) {
            valveList.add(((ValveBase) current).getObjectName());
        }
        current = current.getNext();
    }
    return valveList.toArray(new ObjectName[0]);
}

19 View Complete Implementation : ContainerMBean.java
Copyright Apache License 2.0
Author : apache
/**
 * 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 {
    Container container = null;
    try {
        container = (Container) 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++) {
            if (valves[i] instanceof JmxEnabled) {
                ObjectName voname = ((JmxEnabled) valves[i]).getObjectName();
                if (voname.equals(oname)) {
                    container.getPipeline().removeValve(valves[i]);
                }
            }
        }
    }
}

19 View Complete Implementation : StandardHost.java
Copyright Apache License 2.0
Author : tryandcatch
// -------------------- JMX  --------------------
/**
 * Return the MBean Names of the Valves replacedociated 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] == null)
            continue;
        if (((ValveBase) valves[i]).getObjectName() == null)
            continue;
        mbeanNames[i] = ((ValveBase) valves[i]).getObjectName().toString();
    }
    return mbeanNames;
}

19 View Complete Implementation : StandardPipeline.java
Copyright Apache License 2.0
Author : apache
/**
 * Return the set of Valves in the pipeline replacedociated with this
 * Container, including the basic Valve (if any).  If there are no
 * such Valves, a zero-length array is returned.
 */
@Override
public Valve[] getValves() {
    List<Valve> valveList = new ArrayList<>();
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        valveList.add(current);
        current = current.getNext();
    }
    return valveList.toArray(new Valve[0]);
}

19 View Complete Implementation : TestSSLValve.java
Copyright Apache License 2.0
Author : apache
public clreplaced TestSSLValve {

    public static clreplaced MockRequest extends Request {

        public MockRequest() {
            setConnector(EasyMock.createMock(Connector.clreplaced));
            setCoyoteRequest(new org.apache.coyote.Request());
        }

        @Override
        public void setAttribute(String name, Object value) {
            getCoyoteRequest().getAttributes().put(name, value);
        }

        @Override
        public Object getAttribute(String name) {
            return getCoyoteRequest().getAttribute(name);
        }

        public void setHeader(String header, String value) {
            getCoyoteRequest().getMimeHeaders().setValue(header).setString(value);
        }

        public void addHeader(String header, String value) {
            getCoyoteRequest().getMimeHeaders().addValue(header).setString(value);
        }
    }

    private static final String[] CERTIFICATE_LINES = new String[] { "-----BEGIN CERTIFICATE-----", "MIIFXTCCA0WgAwIBAgIJANFf3YTJgYifMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV", "BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX", "aWRnaXRzIFB0eSBMdGQwHhcNMTcwNTI2MjEzNjM3WhcNMTgwNTI2MjEzNjM3WjBF", "MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50", "ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIIC", "CgKCAgEA2ykNBanZz4cVITNpZcWNVmErUzqgSNrK361mj9vEdB1UkHatwal9jVrR", "QvFgfiZ8Gl+/85t0ebJhJ+rIr1ww6JE7v2s2MThENj95K5EwZOmgvw+CBlBYsFIz", "8BtjlVYy+v7RaGPXfjrFkexQP9UIaiIIog2ClDZirRvb+QxS930/YW5Qo+X6EX6W", "/m/HvlorD25U4ni2FQ0y+EMO2e1jD88cAAMoP5f+Mf6NBK8I6yUeaSuMq7WqtHGV", "e4F1WOg5z9J5c/M69rB0iQr5NUQwZ1mPYf5Kr0P6+TLh8DJphbVvmHJyT3bgofeV", "JYl/kdjiXS5P/jwY9tfmhu04tsyzopWRUFCcj5zCiqZYaMn0wtDn08KaAh9oOlg8", "Z6mJ9i5EybkLm63W7z7LxuM+qnYzq4wKkKdx8hbpASwPqzJkJeXFL/LzhKdZuHiR", "clgPVYnm98URwhObh073dKguG/gkhcnpXcVBBVdVTJZYGBvTpQh0afXd9bcBwOzY", "t4MDpGiQB2fLzBOEZhQ37kUcWPmZw5bNPxhx4yE96Md0rx/Gu4ipAHuqLemb1SL5", "uWNesVmgY3OXaIamQIm9BCwkf8mMvoYdAT+lukTUZLtJ6s2w+Oxnl10tmb+6sTXy", "UB3WcBTp/o3YjAyJPnM1Wq6nVNQ4W2+NbV5purGAP09sumxeJj8CAwEAAaNQME4w", "HQYDVR0OBBYEFCGOYMvymUG2ZZT+lK4LvwEvx731MB8GA1UdIwQYMBaAFCGOYMvy", "mUG2ZZT+lK4LvwEvx731MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggIB", "AG6m4nDYCompUtRVude1qulwwAaYEMHyIIsfymI8uAE7d2o4bGjVpAUOdH/VWSOp", "Rzx0oK6K9cHyiBlKHw5zSZdqcRi++tDX3P9Iy5tXO//zkhMEnSpk6RF2+9JXtyhx", "Gma4yAET1yES+ybiFT21uZrGCC9r69rWG8JRZshc4RVWGwZsd0zrATVqfY0mZurm", "xLgU4UOvkTczjlrLiklwwU68M1DLcILJ5FZGTWeTJ/q1wpIn9isK2siAW/VOcbuG", "xdbGladnIFv+iQfuZG0yjreplacedsBFsQiXi6ONM8GM+dr+61V63/1s73jYcOToEsTMM", "3bHeVffoSkhZvOGTRCI6QhK9wqnIKhAYqu+NbV4OphfE3gOaK+T1cASXUtSQPXoa", "sEoIVmbQsWRBhWvYShVqvINsH/hAT3Cf/+SslprtQUqiyt2ljdgrRFZdoyB3S7ky", "KWoZRvHRj2cKU65LVYwx6U1A8SGmViz4aHMSai0wwKzOVv9MGHeRaVhlMmMsbdfu", "wKoKJv0xYoVwEh1rB8TH8PjbL+6eFLeZXYVZnH71d5JHCghZ8W0a11ZuYkscSQWk", "yoTBqEpJloWksrypqp3iL4PAL5+KkB2zp66+MVAg8LcEDFJggBBJCtv4SCWV7ZOB", "WLu8gep+XCwSn0Wb6D3eFs4DoIiMvQ6g2rS/pk7o5eWj", "-----END CERTIFICATE-----" };

    private SSLValve valve = new SSLValve();

    private MockRequest mockRequest = new MockRequest();

    private Valve mockNext = EasyMock.createMock(Valve.clreplaced);

    @Before
    public void setUp() throws Exception {
        valve.setNext(mockNext);
        mockNext.invoke(mockRequest, null);
        EasyMock.replay(mockNext);
    }

    @Test
    public void testSslHeader() {
        final String headerName = "myheader";
        final String headerValue = "BASE64_HEADER_VALUE";
        mockRequest.setHeader(headerName, headerValue);
        replacedert.replacedertEquals(headerValue, valve.mygetHeader(mockRequest, headerName));
    }

    @Test
    public void testSslHeaderNull() {
        final String headerName = "myheader";
        mockRequest.setHeader(headerName, null);
        replacedert.replacedertNull(valve.mygetHeader(mockRequest, headerName));
    }

    @Test
    public void testSslHeaderNullModHeader() {
        final String headerName = "myheader";
        final String nullModHeaderValue = "(null)";
        mockRequest.setHeader(headerName, nullModHeaderValue);
        replacedert.replacedertNull(valve.mygetHeader(mockRequest, nullModHeaderValue));
    }

    @Test
    public void testSslHeaderNullName() throws Exception {
        replacedert.replacedertNull(valve.mygetHeader(mockRequest, null));
    }

    @Test
    public void testSslHeaderMultiples() throws Exception {
        final String headerName = "myheader";
        final String headerValue = "BASE64_HEADER_VALUE";
        mockRequest.addHeader(headerName, headerValue);
        mockRequest.addHeader(headerName, "anyway won't be found");
        replacedert.replacedertEquals(headerValue, valve.mygetHeader(mockRequest, headerName));
    }

    @Test
    public void testSslClientCertHeaderSingleSpace() throws Exception {
        String singleSpaced = certificateSingleLine(" ");
        mockRequest.setHeader(valve.getSslClientCertHeader(), singleSpaced);
        valve.invoke(mockRequest, null);
        replacedertCertificateParsed();
    }

    @Test
    public void testSslClientCertHeaderMultiSpace() throws Exception {
        String singleSpaced = certificateSingleLine("    ");
        mockRequest.setHeader(valve.getSslClientCertHeader(), singleSpaced);
        valve.invoke(mockRequest, null);
        replacedertCertificateParsed();
    }

    @Test
    public void testSslClientCertHeaderTab() throws Exception {
        String singleSpaced = certificateSingleLine("\t");
        mockRequest.setHeader(valve.getSslClientCertHeader(), singleSpaced);
        valve.invoke(mockRequest, null);
        replacedertCertificateParsed();
    }

    @Test
    public void testSslClientCertNull() throws Exception {
        TesterLogValidationFilter f = TesterLogValidationFilter.add(null, "", null, "org.apache.catalina.valves.SSLValve");
        valve.invoke(mockRequest, null);
        EasyMock.verify(mockNext);
        replacedert.replacedertNull(mockRequest.getAttribute(Globals.CERTIFICATES_ATTR));
        replacedert.replacedertEquals(0, f.getMessageCount());
    }

    @Test
    public void testSslClientCertShorter() throws Exception {
        mockRequest.setHeader(valve.getSslClientCertHeader(), "shorter than hell");
        TesterLogValidationFilter f = TesterLogValidationFilter.add(null, "", null, "org.apache.catalina.valves.SSLValve");
        valve.invoke(mockRequest, null);
        EasyMock.verify(mockNext);
        replacedert.replacedertNull(mockRequest.getAttribute(Globals.CERTIFICATES_ATTR));
        replacedert.replacedertEquals(0, f.getMessageCount());
    }

    @Test
    public void testSslClientCertIgnoredBegin() throws Exception {
        String[] linesBegin = Arrays.copyOf(CERTIFICATE_LINES, CERTIFICATE_LINES.length);
        linesBegin[0] = "3fisjcme3kdsakasdfsadkafsd3";
        String begin = certificateSingleLine(linesBegin, " ");
        mockRequest.setHeader(valve.getSslClientCertHeader(), begin);
        valve.invoke(mockRequest, null);
        replacedertCertificateParsed();
    }

    @Test
    public void testSslClientCertBadFormat() throws Exception {
        String[] linesDeleted = Arrays.copyOf(CERTIFICATE_LINES, CERTIFICATE_LINES.length / 2);
        String deleted = certificateSingleLine(linesDeleted, " ");
        mockRequest.setHeader(valve.getSslClientCertHeader(), deleted);
        TesterLogValidationFilter f = TesterLogValidationFilter.add(Level.WARNING, null, "java.security.cert.CertificateException", "org.apache.catalina.valves.SSLValve");
        valve.invoke(mockRequest, null);
        EasyMock.verify(mockNext);
        replacedert.replacedertNull(mockRequest.getAttribute(Globals.CERTIFICATES_ATTR));
        replacedert.replacedertEquals(1, f.getMessageCount());
    }

    @Test
    public void testClientCertProviderNotFound() throws Exception {
        EasyMock.expect(mockRequest.getConnector().getProperty("clientCertProvider")).andStubReturn("wontBeFound");
        EasyMock.replay(mockRequest.getConnector());
        mockRequest.setHeader(valve.getSslClientCertHeader(), certificateSingleLine(" "));
        TesterLogValidationFilter f = TesterLogValidationFilter.add(Level.SEVERE, null, "java.security.NoSuchProviderException", "org.apache.catalina.valves.SSLValve");
        valve.invoke(mockRequest, null);
        replacedert.replacedertNull(mockRequest.getAttribute(Globals.CERTIFICATES_ATTR));
        replacedert.replacedertEquals(1, f.getMessageCount());
    }

    @Test
    public void testSslCipherHeaderPresent() throws Exception {
        String cipher = "ciphered-with";
        mockRequest.setHeader(valve.getSslCipherHeader(), cipher);
        valve.invoke(mockRequest, null);
        replacedert.replacedertEquals(cipher, mockRequest.getAttribute(Globals.CIPHER_SUITE_ATTR));
    }

    @Test
    public void testSslSessionIdHeaderPresent() throws Exception {
        String session = "ssl-session";
        mockRequest.setHeader(valve.getSslSessionIdHeader(), session);
        valve.invoke(mockRequest, null);
        replacedert.replacedertEquals(session, mockRequest.getAttribute(Globals.SSL_SESSION_ID_ATTR));
    }

    @Test
    public void testSslCipherUserKeySizeHeaderPresent() throws Exception {
        Integer keySize = Integer.valueOf(452);
        mockRequest.setHeader(valve.getSslCipherUserKeySizeHeader(), String.valueOf(keySize));
        valve.invoke(mockRequest, null);
        replacedert.replacedertEquals(keySize, mockRequest.getAttribute(Globals.KEY_SIZE_ATTR));
    }

    @Test(expected = NumberFormatException.clreplaced)
    public void testSslCipherUserKeySizeHeaderBadFormat() throws Exception {
        mockRequest.setHeader(valve.getSslCipherUserKeySizeHeader(), "not-an-integer");
        try {
            valve.invoke(mockRequest, null);
        } catch (NumberFormatException e) {
            replacedert.replacedertNull(mockRequest.getAttribute(Globals.KEY_SIZE_ATTR));
            throw e;
        }
    }

    private static String certificateSingleLine(String[] lines, String separator) {
        StringBuilder singleSpaced = new StringBuilder();
        for (String current : lines) {
            singleSpaced.append(current).append(separator);
        }
        singleSpaced.deleteCharAt(singleSpaced.length() - 1);
        return singleSpaced.toString();
    }

    private static String certificateSingleLine(String separator) {
        return certificateSingleLine(CERTIFICATE_LINES, separator);
    }

    private void replacedertCertificateParsed() throws Exception {
        TesterLogValidationFilter f = TesterLogValidationFilter.add(null, "", null, "org.apache.catalina.valves.SSLValve");
        EasyMock.verify(mockNext);
        X509Certificate[] certificates = (X509Certificate[]) mockRequest.getAttribute(Globals.CERTIFICATES_ATTR);
        replacedert.replacedertNotNull(certificates);
        replacedert.replacedertEquals(1, certificates.length);
        replacedert.replacedertNotNull(certificates[0]);
        replacedert.replacedertEquals(0, f.getMessageCount());
    }
}

19 View Complete Implementation : StandardPipeline.java
Copyright Apache License 2.0
Author : apache
@Override
protected void destroyInternal() {
    Valve[] valves = getValves();
    for (Valve valve : valves) {
        removeValve(valve);
    }
}

19 View Complete Implementation : AccessLogBenchmark.java
Copyright Apache License 2.0
Author : chanjarster
@Override
public void setUpValve(Tomcat tomcat) {
    // clear AccessLogValve
    for (Valve vl : tomcat.getHost().getPipeline().getValves()) {
        if (vl.getClreplaced().equals(AccessLogValve.clreplaced)) {
            tomcat.getHost().getPipeline().removeValve(vl);
        }
    }
    if (accessLogDirectory == null) {
        accessLogDirectory = new File(getBuildDirectory(), "logs").toString();
    }
    AccessLogValve alv = new AccessLogValve();
    alv.setDirectory(accessLogDirectory);
    alv.setPattern("combined");
    tomcat.getHost().getPipeline().addValve(alv);
}

19 View Complete Implementation : StandardPipeline.java
Copyright Apache License 2.0
Author : apache
/**
 * 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);
}

19 View Complete Implementation : ContainerMBean.java
Copyright Apache License 2.0
Author : codefollower
/**
 * Adds a valve to this Container instance.
 *
 * @param valveType ClreplacedName of the valve to be added
 *
 * @exception MBeanException if a component cannot be removed
 */
public String addValve(String valveType) throws MBeanException {
    Valve valve = null;
    try {
        valve = (Valve) Clreplaced.forName(valveType).newInstance();
    } catch (InstantiationException e) {
        throw new MBeanException(e);
    } catch (IllegalAccessException e) {
        throw new MBeanException(e);
    } catch (ClreplacedNotFoundException e) {
        throw new MBeanException(e);
    }
    if (valve == null) {
        return null;
    }
    try {
        Container container = (Container) getManagedResource();
        container.getPipeline().addValve(valve);
    } catch (InstanceNotFoundException e) {
        throw new MBeanException(e);
    } catch (RuntimeOperationsException e) {
        throw new MBeanException(e);
    } catch (InvalidTargetObjectTypeException e) {
        throw new MBeanException(e);
    }
    if (valve instanceof JmxEnabled) {
        return ((JmxEnabled) valve).getObjectName().toString();
    } else {
        return null;
    }
}

19 View Complete Implementation : ContainerMBean.java
Copyright Apache License 2.0
Author : apache
/**
 * 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 {
    Container container = doGetManagedResource();
    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++) {
            if (valves[i] instanceof JmxEnabled) {
                ObjectName voname = ((JmxEnabled) valves[i]).getObjectName();
                if (voname.equals(oname)) {
                    container.getPipeline().removeValve(valves[i]);
                }
            }
        }
    }
}

19 View Complete Implementation : StandardHost.java
Copyright Apache License 2.0
Author : how2j
// -------------------- JMX --------------------
/**
 * Return the MBean Names of the Valves replacedociated 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] == null)
            continue;
        if (((ValveBase) valves[i]).getObjectName() == null)
            continue;
        mbeanNames[i] = ((ValveBase) valves[i]).getObjectName().toString();
    }
    return mbeanNames;
}

19 View Complete Implementation : ContainerBase.java
Copyright Apache License 2.0
Author : apache
// ------------------------------------------------------- Pipeline Methods
/**
 * Convenience method, intended for use by the digester to simplify the
 * process of adding Valves to containers. See
 * {@link Pipeline#addValve(Valve)} for full details. Components other than
 * the digester should use {@link #getPipeline()}.{@link #addValve(Valve)} in case a
 * future implementation provides an alternative method for the digester to
 * use.
 *
 * @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
 *  replacedociated with this Container
 * @exception IllegalStateException if the specified Valve is already
 *  replacedociated with a different Container
 */
public synchronized void addValve(Valve valve) {
    pipeline.addValve(valve);
}

19 View Complete Implementation : StandardPipeline.java
Copyright Apache License 2.0
Author : how2j
/**
 * Return the set of Valves in the pipeline replacedociated with this Container,
 * including the basic Valve (if any). If there are no such Valves, a
 * zero-length array is returned.
 */
@Override
public Valve[] getValves() {
    ArrayList<Valve> valveList = new ArrayList<Valve>();
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        valveList.add(current);
        current = current.getNext();
    }
    return valveList.toArray(new Valve[0]);
}

19 View Complete Implementation : StandardHost.java
Copyright Apache License 2.0
Author : apache
// -------------------- JMX  --------------------
/**
 * Return the MBean Names of the Valves replacedociated 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;
}

19 View Complete Implementation : ValveBase.java
Copyright Apache License 2.0
Author : how2j
/**
 * Set the Valve that follows this one in the pipeline it is part of.
 *
 * @param valve
 *            The new next valve
 */
@Override
public void setNext(Valve valve) {
    this.next = valve;
}

19 View Complete Implementation : StandardPipeline.java
Copyright Apache License 2.0
Author : how2j
@Override
public boolean isAsyncSupported() {
    Valve valve = (first != null) ? first : basic;
    boolean supported = true;
    while (supported && valve != null) {
        supported = supported & valve.isAsyncSupported();
        valve = valve.getNext();
    }
    return supported;
}

19 View Complete Implementation : StandardPipeline.java
Copyright Apache License 2.0
Author : apache
/**
 * Return the set of Valves in the pipeline replacedociated with this
 * Container, including the basic Valve (if any).  If there are no
 * such Valves, a zero-length array is returned.
 */
@Override
public Valve[] getValves() {
    ArrayList<Valve> valveList = new ArrayList<>();
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        valveList.add(current);
        current = current.getNext();
    }
    return valveList.toArray(new Valve[0]);
}

19 View Complete Implementation : AbstractSessionManager.java
Copyright MIT License
Author : liuxinglanyue
@Override
protected synchronized void startInternal() throws LifecycleException {
    super.startInternal();
    setState(LifecycleState.STARTING);
    boolean attachedToValve = false;
    for (Valve valve : getContainer().getPipeline().getValves()) {
        if (valve instanceof SessionHandlerValve) {
            this.handlerValve = (SessionHandlerValve) valve;
            this.handlerValve.setSessionManager(this);
            log.info("Attached to SessionHandlerValve");
            attachedToValve = true;
            break;
        }
    }
    if (!attachedToValve) {
        String error = "Unable to attach to session handling valve; sessions cannot be saved after the request without the valve starting properly.";
        log.fatal(error);
        throw new LifecycleException(error);
    }
    try {
        initializeSerializer();
    } catch (ClreplacedNotFoundException | InstantiationException | IllegalAccessException e) {
        log.fatal("Unable to load serializer", e);
        throw new LifecycleException(e);
    }
    log.info("Will expire sessions after " + getMaxInactiveInterval() + " seconds");
    initializeDatabaseConnection();
    setDistributable(true);
}

19 View Complete Implementation : StandardPipeline.java
Copyright Apache License 2.0
Author : apache
public ObjectName[] getValveObjectNames() {
    List<ObjectName> valveList = new ArrayList<>();
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        if (current instanceof JmxEnabled) {
            valveList.add(((JmxEnabled) current).getObjectName());
        }
        current = current.getNext();
    }
    return valveList.toArray(new ObjectName[0]);
}

19 View Complete Implementation : SessionManager.java
Copyright GNU General Public License v3.0
Author : ran-jit
/**
 * {@inheritDoc}
 */
@Override
protected synchronized void startInternal() throws LifecycleException {
    super.startInternal();
    super.setState(LifecycleState.STARTING);
    boolean initializedValve = false;
    Context context = getContextIns();
    for (Valve valve : context.getPipeline().getValves()) {
        if (valve instanceof SessionHandlerValve) {
            SessionHandlerValve handlerValve = (SessionHandlerValve) valve;
            handlerValve.setSessionManager(this);
            initializedValve = true;
            break;
        }
    }
    if (!initializedValve) {
        throw new LifecycleException("Session handling valve is not initialized..");
    }
    initialize();
    LOGGER.info("The sessions will expire after " + (getSessionTimeout(null)) + " seconds.");
    context.setDistributable(true);
}

19 View Complete Implementation : ContainerMBean.java
Copyright Apache License 2.0
Author : apache
/**
 * Adds a valve to this Container instance.
 *
 * @param valveType ClreplacedName 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 = null;
    try {
        valve = (Valve) Clreplaced.forName(valveType).getConstructor().newInstance();
    } catch (ReflectiveOperationException e) {
        throw new MBeanException(e);
    }
    if (valve == null) {
        return null;
    }
    try {
        Container container = (Container) getManagedResource();
        container.getPipeline().addValve(valve);
    } catch (InstanceNotFoundException e) {
        throw new MBeanException(e);
    } catch (RuntimeOperationsException e) {
        throw new MBeanException(e);
    } catch (InvalidTargetObjectTypeException e) {
        throw new MBeanException(e);
    }
    if (valve instanceof JmxEnabled) {
        return ((JmxEnabled) valve).getObjectName().toString();
    } else {
        return null;
    }
}

19 View Complete Implementation : StandardPipeline.java
Copyright Apache License 2.0
Author : tryandcatch
/**
 * Return the set of Valves in the pipeline replacedociated with this
 * Container, including the basic Valve (if any).  If there are no
 * such Valves, a zero-length array is returned.
 */
@Override
public Valve[] getValves() {
    ArrayList<Valve> valveList = new ArrayList<Valve>();
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        valveList.add(current);
        current = current.getNext();
    }
    return valveList.toArray(new Valve[0]);
}

19 View Complete Implementation : ContainerBase.java
Copyright Apache License 2.0
Author : apache
@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;
}

19 View Complete Implementation : StandardHost.java
Copyright Apache License 2.0
Author : apache
// -------------------- JMX  --------------------
/**
 * @return the MBean Names of the Valves replacedociated 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;
}

19 View Complete Implementation : StandardPipeline.java
Copyright Apache License 2.0
Author : apache
/**
 * 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();
    }
}

19 View Complete Implementation : StandardPipeline.java
Copyright Apache License 2.0
Author : apache
public ObjectName[] getValveObjectNames() {
    ArrayList<ObjectName> valveList = new ArrayList<>();
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        if (current instanceof JmxEnabled) {
            valveList.add(((JmxEnabled) current).getObjectName());
        }
        current = current.getNext();
    }
    return valveList.toArray(new ObjectName[0]);
}

19 View Complete Implementation : StandardPipeline.java
Copyright Apache License 2.0
Author : how2j
/**
 * 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();
    }
}

18 View Complete Implementation : TomcatValve.java
Copyright Apache License 2.0
Author : apache
public void invoke(Request request, Response response) throws IOException, ServletException {
    invokeServletRequest(request);
    Valve next = getNext();
    if (next != null)
        next.invoke(request, response);
}

18 View Complete Implementation : DeltaSessionManager.java
Copyright Apache License 2.0
Author : apache
public abstract clreplaced DeltaSessionManager extends ManagerBase implements Lifecycle, PropertyChangeListener, SessionManager {

    static final String catalinaBaseSystemProperty = "catalina.base";

    static final String javaTempDirSystemProperty = "java.io.tmpdir";

    static final String fileSeparatorSystemProperty = "file.separator";

    /**
     * The number of rejected sessions.
     */
    private AtomicInteger rejectedSessions;

    /**
     * The maximum number of active Sessions allowed, or -1 for no limit.
     */
    private int maxActiveSessions = -1;

    /**
     * Has this <code>Manager</code> been started?
     */
    protected AtomicBoolean started = new AtomicBoolean(false);

    /**
     * The name of this <code>Manager</code>
     */
    protected String name;

    private Valve jvmRouteBinderValve;

    private Valve commitSessionValve;

    private SessionCache sessionCache;

    private static final String DEFAULT_REGION_NAME = RegionHelper.NAME + "_sessions";

    private static final boolean DEFAULT_ENABLE_GATEWAY_REPLICATION = false;

    private static final boolean DEFAULT_ENABLE_DEBUG_LISTENER = false;

    private static final boolean DEFAULT_ENABLE_COMMIT_VALVE = true;

    private static final boolean DEFAULT_ENABLE_COMMIT_VALVE_FAILFAST = false;

    private static final boolean DEFAULT_PREFER_DESERIALIZED_FORM = true;

    /*
   * This *MUST* only be replacedigned during start/startInternal otherwise it will be replacedociated with
   * the incorrect context clreplaced loader.
   */
    private Log LOGGER;

    protected String regionName = DEFAULT_REGION_NAME;

    // the default is different for client-server and
    private String regionAttributesId;

    // peer-to-peer
    // the default is different for client-server and peer-to-peer
    private Boolean enableLocalCache;

    private boolean enableCommitValve = DEFAULT_ENABLE_COMMIT_VALVE;

    private boolean enableCommitValveFailfast = DEFAULT_ENABLE_COMMIT_VALVE_FAILFAST;

    private boolean enableGatewayReplication = DEFAULT_ENABLE_GATEWAY_REPLICATION;

    private boolean enableDebugListener = DEFAULT_ENABLE_DEBUG_LISTENER;

    private boolean preferDeserializedForm = DEFAULT_PREFER_DESERIALIZED_FORM;

    private Timer timer;

    private final Set<String> sessionsToTouch;

    private static final long TIMER_TASK_PERIOD = Long.getLong("gemfiremodules.sessionTimerTaskPeriod", 10000);

    private static final long TIMER_TASK_DELAY = Long.getLong("gemfiremodules.sessionTimerTaskDelay", 10000);

    public DeltaSessionManager() {
        this.rejectedSessions = new AtomicInteger(0);
        // Create the set to store sessions to be touched after get attribute requests
        this.sessionsToTouch = Collections.newSetFromMap(new ConcurrentHashMap<>());
    }

    @Override
    public String getRegionName() {
        return this.regionName;
    }

    public void setRegionName(String regionName) {
        this.regionName = regionName;
    }

    @Override
    public void setMaxInactiveInterval(final int interval) {
        super.setMaxInactiveInterval(interval);
    }

    @Override
    public String getRegionAttributesId() {
        // This property will be null if it hasn't been set in the context.xml file.
        // Since its default is dependent on the session cache, get the default from
        // the session cache.
        if (this.regionAttributesId == null) {
            this.regionAttributesId = getSessionCache().getDefaultRegionAttributesId();
        }
        return this.regionAttributesId;
    }

    @SuppressWarnings("unused")
    public void setRegionAttributesId(String regionType) {
        this.regionAttributesId = regionType;
    }

    @Override
    public boolean getEnableLocalCache() {
        // This property will be null if it hasn't been set in the context.xml file.
        // Since its default is dependent on the session cache, get the default from
        // the session cache.
        if (this.enableLocalCache == null) {
            this.enableLocalCache = getSessionCache().getDefaultEnableLocalCache();
        }
        return this.enableLocalCache;
    }

    @SuppressWarnings("unused")
    public void setEnableLocalCache(boolean enableLocalCache) {
        this.enableLocalCache = enableLocalCache;
    }

    @SuppressWarnings("unused")
    public int getMaxActiveSessions() {
        return this.maxActiveSessions;
    }

    @SuppressWarnings("unused")
    public void setMaxActiveSessions(int maxActiveSessions) {
        int oldMaxActiveSessions = this.maxActiveSessions;
        this.maxActiveSessions = maxActiveSessions;
        support.firePropertyChange("maxActiveSessions", new Integer(oldMaxActiveSessions), new Integer(this.maxActiveSessions));
    }

    @Override
    public boolean getEnableGatewayDeltaReplication() {
        // return this.enableGatewayDeltaReplication;
        // disabled
        return false;
    }

    @SuppressWarnings("unused")
    public void setEnableGatewayDeltaReplication(boolean enableGatewayDeltaReplication) {
    // this.enableGatewayDeltaReplication = enableGatewayDeltaReplication;
    // Disabled. Keeping the method for backward compatibility.
    }

    @Override
    public boolean getEnableGatewayReplication() {
        return this.enableGatewayReplication;
    }

    @SuppressWarnings("unused")
    public void setEnableGatewayReplication(boolean enableGatewayReplication) {
        this.enableGatewayReplication = enableGatewayReplication;
    }

    @Override
    public boolean getEnableDebugListener() {
        return this.enableDebugListener;
    }

    @SuppressWarnings("unused")
    public void setEnableDebugListener(boolean enableDebugListener) {
        this.enableDebugListener = enableDebugListener;
    }

    @Override
    public boolean isCommitValveEnabled() {
        return this.enableCommitValve;
    }

    public void setEnableCommitValve(boolean enable) {
        this.enableCommitValve = enable;
    }

    @Override
    public boolean isCommitValveFailfastEnabled() {
        return this.enableCommitValveFailfast;
    }

    @SuppressWarnings("unused")
    public void setEnableCommitValveFailfast(boolean enable) {
        this.enableCommitValveFailfast = enable;
    }

    @Override
    public boolean isBackingCacheAvailable() {
        return sessionCache.isBackingCacheAvailable();
    }

    @SuppressWarnings("unused")
    public void setPreferDeserializedForm(boolean enable) {
        this.preferDeserializedForm = enable;
    }

    @Override
    public boolean getPreferDeserializedForm() {
        return this.preferDeserializedForm;
    }

    @Override
    public String getStatisticsName() {
        return getContextName().replace("/", "");
    }

    @Override
    public Log getLogger() {
        if (LOGGER == null) {
            LOGGER = LogFactory.getLog(DeltaSessionManager.clreplaced);
        }
        return LOGGER;
    }

    public SessionCache getSessionCache() {
        return this.sessionCache;
    }

    public DeltaSessionStatistics getStatistics() {
        return getSessionCache().getStatistics();
    }

    boolean isPeerToPeer() {
        return getSessionCache().isPeerToPeer();
    }

    @SuppressWarnings("unused")
    public boolean isClientServer() {
        return getSessionCache().isClientServer();
    }

    /**
     * This method was taken from StandardManager to set the default maxInactiveInterval based on the
     * container (to 30 minutes).
     * <p>
     * Set the Container with which this Manager has been replacedociated. If it is a Context (the usual
     * case), listen for changes to the session timeout property.
     *
     * @param container The replacedociated Container
     */
    @Override
    public void setContainer(Container container) {
        // De-register from the old Container (if any)
        if ((this.container != null) && (this.container instanceof Context)) {
            this.container.removePropertyChangeListener(this);
        }
        // Default processing provided by our superclreplaced
        super.setContainer(container);
        // Register with the new Container (if any)
        if ((this.container != null) && (this.container instanceof Context)) {
            // Overwrite the max inactive interval with the context's session timeout.
            setMaxInactiveInterval(((Context) this.container).getSessionTimeout() * 60);
            this.container.addPropertyChangeListener(this);
        }
    }

    @Override
    public Session findSession(String id) throws IOException {
        if (id == null) {
            return null;
        }
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(this + ": Finding session " + id + " in " + getSessionCache().getOperatingRegionName());
        }
        DeltaSessionInterface session = (DeltaSessionInterface) getSessionCache().getSession(id);
        /*
     * Check that the context name for this session is the same as this manager's. This comes into
     * play when multiple versions of a webapp are deployed and active at the same time; the context
     * name will contain an embedded version number; something like /test###2.
     */
        if (session != null && !session.getContextName().isEmpty() && !getContextName().equals(session.getContextName())) {
            getLogger().info(this + ": Session " + id + " rejected as container name and context do not match: " + getContextName() + " != " + session.getContextName());
            session = null;
        }
        if (session == null) {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug(this + ": Did not find session " + id + " in " + getSessionCache().getOperatingRegionName());
            }
        } else {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug(this + ": Found session " + id + " in " + getSessionCache().getOperatingRegionName() + ": " + session);
            }
            // The session was previously stored. Set new to false.
            session.setNew(false);
            // Check the manager.
            // If the manager is null, the session was replicated and this is a
            // failover situation. Reset the manager and activate the session.
            if (session.getManager() == null) {
                session.setOwner(this);
                session.activate();
            }
        }
        return session;
    }

    protected void initializeSessionCache() {
        // Retrieve the cache
        GemFireCacheImpl cache = (GemFireCacheImpl) getAnyCacheInstance();
        if (cache == null) {
            throw new IllegalStateException("No cache exists. Please configure either a PeerToPeerCacheLifecycleListener or ClientServerCacheLifecycleListener in the server.xml file.");
        }
        // Create the appropriate session cache
        this.sessionCache = cache.isClient() ? new ClientServerSessionCache(this, cache) : new PeerToPeerSessionCache(this, cache);
        // Initialize the session cache
        initSessionCache();
    }

    void initSessionCache() {
        this.sessionCache.initialize();
    }

    Cache getAnyCacheInstance() {
        return CacheFactory.getAnyInstance();
    }

    @Override
    protected StandardSession getNewSession() {
        return new DeltaSession(this);
    }

    @Override
    public void remove(Session session) {
        remove(session, false);
    }

    public void remove(Session session, @SuppressWarnings("unused") boolean update) {
        // super.remove(session);
        // Remove the session from the region if necessary.
        // It will have already been removed if it expired implicitly.
        DeltaSessionInterface ds = (DeltaSessionInterface) session;
        if (ds.getExpired()) {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug(this + ": Expired session " + session.getId() + " from " + getSessionCache().getOperatingRegionName());
            }
        } else {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug(this + ": Destroying session " + session.getId() + " from " + getSessionCache().getOperatingRegionName());
            }
            getSessionCache().destroySession(session.getId());
            if (getLogger().isDebugEnabled()) {
                getLogger().debug(this + ": Destroyed session " + session.getId() + " from " + getSessionCache().getOperatingRegionName());
            }
        }
    }

    @Override
    public void add(Session session) {
        // super.add(session);
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(this + ": Storing session " + session.getId() + " into " + getSessionCache().getOperatingRegionName());
        }
        getSessionCache().putSession(session);
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(this + ": Stored session " + session.getId() + " into " + getSessionCache().getOperatingRegionName());
        }
        getSessionCache().getStatistics().incSessionsCreated();
    }

    @Override
    public int getRejectedSessions() {
        return this.rejectedSessions.get();
    }

    @Override
    public void setRejectedSessions(int rejectedSessions) {
        this.rejectedSessions.set(rejectedSessions);
    }

    /**
     * Returns the number of active sessions
     *
     * @return number of sessions active
     */
    @Override
    public int getActiveSessions() {
        return getSessionCache().size();
    }

    /**
     * For debugging: return a list of all session ids currently active
     */
    @Override
    public String listSessionIds() {
        StringBuilder builder = new StringBuilder();
        Iterator<String> sessionIds = getSessionCache().keySet().iterator();
        while (sessionIds.hasNext()) {
            builder.append(sessionIds.next());
            if (sessionIds.hasNext()) {
                builder.append(" ");
            }
        }
        return builder.toString();
    }

    /*
   * If local caching is enabled, add the session to the set of sessions to be touched. A timer task
   * will be periodically invoked to get the session in the session region to update its last
   * accessed time. This prevents the session from expiring in the case where the application is
   * only getting attributes from the session and never putting attributes into the session. If
   * local caching is disabled. the session's last accessed time would already have been updated
   * properly in the sessions region.
   *
   * Note: Due to issues in GemFire expiry, sessions are always asynchronously touched using a
   * function regardless whether or not local caching is enabled. This prevents premature
   * expiration.
   */
    void addSessionToTouch(String sessionId) {
        this.sessionsToTouch.add(sessionId);
    }

    protected Set<String> getSessionsToTouch() {
        return this.sessionsToTouch;
    }

    boolean removeTouchedSession(String sessionId) {
        return this.sessionsToTouch.remove(sessionId);
    }

    protected void scheduleTimerTasks() {
        // Create the timer
        this.timer = new Timer("Timer for " + toString(), true);
        // Schedule the task to handle sessions to be touched
        scheduleTouchSessionsTask();
        // Schedule the task to maintain the maxActive sessions
        scheduleDetermineMaxActiveSessionsTask();
    }

    private void scheduleTouchSessionsTask() {
        TimerTask task = new TimerTask() {

            @Override
            public void run() {
                // Get the sessionIds to touch and clear the set inside synchronization
                Set<String> sessionIds;
                sessionIds = new HashSet<>(getSessionsToTouch());
                getSessionsToTouch().clear();
                // Touch the sessions we currently have
                if (!sessionIds.isEmpty()) {
                    getSessionCache().touchSessions(sessionIds);
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug(DeltaSessionManager.this + ": Touched sessions: " + sessionIds);
                    }
                }
            }
        };
        this.timer.schedule(task, TIMER_TASK_DELAY, TIMER_TASK_PERIOD);
    }

    protected void cancelTimer() {
        if (timer != null) {
            this.timer.cancel();
        }
    }

    private void scheduleDetermineMaxActiveSessionsTask() {
        TimerTask task = new TimerTask() {

            @Override
            public void run() {
                int currentActiveSessions = getSessionCache().size();
                if (currentActiveSessions > getMaxActive()) {
                    setMaxActive(currentActiveSessions);
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug(DeltaSessionManager.this + ": Set max active sessions: " + currentActiveSessions);
                    }
                }
            }
        };
        this.timer.schedule(task, TIMER_TASK_DELAY, TIMER_TASK_PERIOD);
    }

    @Override
    public void load() throws ClreplacedNotFoundException, IOException {
        doLoad();
        ContextMapper.addContext(getContextName(), this);
    }

    @Override
    public void unload() throws IOException {
        doUnload();
        ContextMapper.removeContext(getContextName());
    }

    protected void registerJvmRouteBinderValve() {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(this + ": Registering JVM route binder valve");
        }
        jvmRouteBinderValve = new JvmRouteBinderValve();
        getPipeline().addValve(jvmRouteBinderValve);
    }

    Pipeline getPipeline() {
        return getContainer().getPipeline();
    }

    protected void unregisterJvmRouteBinderValve() {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(this + ": Unregistering JVM route binder valve");
        }
        if (jvmRouteBinderValve != null) {
            getPipeline().removeValve(jvmRouteBinderValve);
        }
    }

    protected void registerCommitSessionValve() {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(this + ": Registering CommitSessionValve");
        }
        commitSessionValve = new CommitSessionValve();
        getPipeline().addValve(commitSessionValve);
    }

    protected void unregisterCommitSessionValve() {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(this + ": Unregistering CommitSessionValve");
        }
        if (commitSessionValve != null) {
            getPipeline().removeValve(commitSessionValve);
        }
    }

    // ------------------------------ Lifecycle Methods
    /**
     * Process property change events from our replacedociated Context.
     * <p>
     * Part of this method implementation was taken from StandardManager. The sessionTimeout can be
     * changed in the web.xml which is processed after the context.xml. The context (and the default
     * session timeout) would already have been set in this Manager. This is the way to get the new
     * session timeout value specified in the web.xml.
     * <p>
     * The precedence order for setting the session timeout value is:
     * <p>
     * <ol>
     * <li>the max inactive interval is set based on the Manager defined in the context.xml
     * <li>the max inactive interval is then overwritten by the value of the Context's session timeout
     * when setContainer is called
     * <li>the max inactive interval is then overwritten by the value of the session-timeout specified
     * in the web.xml (if any)
     * </ol>
     *
     * @param event The property change event that has occurred
     */
    @Override
    public void propertyChange(PropertyChangeEvent event) {
        // Validate the source of this event
        if (!(event.getSource() instanceof Context)) {
            return;
        }
        // Process a relevant property change
        if (event.getPropertyName().equals("sessionTimeout")) {
            try {
                int interval = (Integer) event.getNewValue();
                if (interval < RegionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL) {
                    getLogger().warn("The configured session timeout of " + interval + " minutes is invalid. Using the original value of " + event.getOldValue() + " minutes.");
                    interval = (Integer) event.getOldValue();
                }
                // StandardContext.setSessionTimeout preplacedes -1 if the configured timeout
                // is 0; otherwise it preplacedes the value set in web.xml. If the interval
                // parameter equals the default, set the max inactive interval to the
                // default (no expiration); otherwise set it in seconds.
                setMaxInactiveInterval(interval == RegionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL ? RegionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL : interval * 60);
            } catch (NumberFormatException e) {
                getLogger().error(sm.getString("standardManager.sessionTimeout", event.getNewValue().toString()));
            }
        }
    }

    /**
     * Save any currently active sessions in the appropriate persistence mechanism, if any. If
     * persistence is not supported, this method returns without doing anything.
     *
     * @throws IOException if an input/output error occurs
     */
    private void doUnload() throws IOException {
        QueryService querySvc = getSessionCache().getCache().getQueryService();
        Context context = getTheContext();
        if (context == null) {
            return;
        }
        String regionName;
        if (getRegionName().startsWith("/")) {
            regionName = getRegionName();
        } else {
            regionName = "/" + getRegionName();
        }
        Query query = querySvc.newQuery("select s.id from " + regionName + " as s where s.contextName = '" + context.getPath() + "'");
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Query: " + query.getQueryString());
        }
        SelectResults results;
        try {
            results = (SelectResults) query.execute();
        } catch (Exception ex) {
            getLogger().error("Unable to perform query during doUnload", ex);
            return;
        }
        if (results.isEmpty()) {
            getLogger().debug("No sessions to unload for context " + context.getPath());
            // nothing to do
            return;
        }
        // Open an output stream to the specified pathname, if any
        File store = sessionStore(context.getPath());
        if (store == null) {
            return;
        }
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Unloading sessions to " + store.getAbsolutePath());
        }
        FileOutputStream fos = null;
        BufferedOutputStream bos = null;
        ObjectOutputStream oos = null;
        boolean error = false;
        try {
            fos = getFileOutputStream(store);
            bos = getBufferedOutputStream(fos);
            oos = getObjectOutputStream(bos);
        } catch (IOException e) {
            error = true;
            getLogger().error("Exception unloading sessions", e);
            throw e;
        } finally {
            if (error) {
                if (oos != null) {
                    try {
                        oos.close();
                    } catch (IOException ioe) {
                    // Ignore
                    }
                }
                if (bos != null) {
                    try {
                        bos.close();
                    } catch (IOException ioe) {
                    // Ignore
                    }
                }
                if (fos != null) {
                    try {
                        fos.close();
                    } catch (IOException ioe) {
                    // Ignore
                    }
                }
            }
        }
        ArrayList<DeltaSessionInterface> list = new ArrayList<>();
        @SuppressWarnings("unchecked")
        Iterator<String> elements = (Iterator<String>) results.iterator();
        while (elements.hasNext()) {
            String id = elements.next();
            DeltaSessionInterface session = (DeltaSessionInterface) findSession(id);
            if (session != null) {
                list.add(session);
            }
        }
        // Write the number of active sessions, followed by the details
        if (getLogger().isDebugEnabled())
            getLogger().debug("Unloading " + list.size() + " sessions");
        try {
            writeToObjectOutputStream(oos, list);
            for (DeltaSessionInterface session : list) {
                if (session instanceof StandardSession) {
                    StandardSession standardSession = (StandardSession) session;
                    standardSession.preplacedivate();
                    standardSession.writeObjectData(oos);
                } else {
                    // All DeltaSessionInterfaces as of Geode 1.0 should be based on StandardSession
                    throw new IOException("Session should be of type StandardSession");
                }
            }
        } catch (IOException e) {
            getLogger().error("Exception unloading sessions", e);
            try {
                oos.close();
            } catch (IOException f) {
            // Ignore
            }
            throw e;
        }
        // Flush and close the output stream
        try {
            oos.flush();
        } finally {
            try {
                oos.close();
            } catch (IOException f) {
            // Ignore
            }
        }
        // Locally destroy the sessions we just wrote
        if (getSessionCache().isClientServer()) {
            for (DeltaSessionInterface session : list) {
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("Locally destroying session " + session.getId());
                }
                try {
                    getSessionCache().getOperatingRegion().localDestroy(session.getId());
                } catch (EntryNotFoundException ex) {
                // This can be thrown if an entry is evicted during or immediately after a session is
                // written
                // to disk. This isn't a problem, but the resulting exception messages can be confusing in
                // testing
                }
            }
        }
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Unloading complete");
        }
    }

    /**
     * Load any currently active sessions that were previously unloaded to the appropriate persistence
     * mechanism, if any. If persistence is not supported, this method returns without doing anything.
     *
     * @throws ClreplacedNotFoundException if a serialized clreplaced cannot be found during the reload
     * @throws IOException if an input/output error occurs
     */
    private void doLoad() throws ClreplacedNotFoundException, IOException {
        Context context = getTheContext();
        if (context == null) {
            return;
        }
        // Open an input stream to the specified pathname, if any
        File store = sessionStore(context.getPath());
        if (store == null) {
            getLogger().debug("No session store file found");
            return;
        }
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Loading sessions from " + store.getAbsolutePath());
        }
        FileInputStream fis = null;
        BufferedInputStream bis = null;
        ObjectInputStream ois;
        Loader loader = null;
        ClreplacedLoader clreplacedLoader = null;
        try {
            fis = getFileInputStream(store);
            bis = getBufferedInputStream(fis);
            if (getTheContext() != null) {
                loader = getTheContext().getLoader();
            }
            if (loader != null) {
                clreplacedLoader = loader.getClreplacedLoader();
            }
            if (clreplacedLoader != null) {
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("Creating custom object input stream for clreplaced loader");
                }
                ois = new CustomObjectInputStream(bis, clreplacedLoader);
            } else {
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("Creating standard object input stream");
                }
                ois = getObjectInputStream(bis);
            }
        } catch (FileNotFoundException e) {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("No persisted data file found");
            }
            return;
        } catch (IOException e) {
            getLogger().error("Exception loading sessions", e);
            try {
                fis.close();
            } catch (IOException f) {
            // Ignore
            }
            try {
                bis.close();
            } catch (IOException f) {
            // Ignore
            }
            throw e;
        }
        // Load the previously unloaded active sessions
        try {
            int n = getSessionCountFromObjectInputStream(ois);
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Loading " + n + " persisted sessions");
            }
            for (int i = 0; i < n; i++) {
                StandardSession session = getNewSession();
                session.readObjectData(ois);
                session.setManager(this);
                Region region = getSessionCache().getOperatingRegion();
                DeltaSessionInterface existingSession = (DeltaSessionInterface) region.get(session.getId());
                // Check whether the existing session is newer
                if (existingSession != null && existingSession.getLastAccessedTime() > session.getLastAccessedTime()) {
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug("Loaded session " + session.getId() + " is older than cached copy");
                    }
                    continue;
                }
                // Check whether the new session has already expired
                if (!session.isValid()) {
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug("Loaded session " + session.getId() + " is invalid");
                    }
                    continue;
                }
                getLogger().debug("Loading session " + session.getId());
                session.activate();
                add(session);
            }
        } catch (ClreplacedNotFoundException | IOException e) {
            getLogger().error(e);
            try {
                ois.close();
            } catch (IOException f) {
            // Ignore
            }
            throw e;
        } finally {
            // Close the input stream
            try {
                ois.close();
            } catch (IOException f) {
            // ignored
            }
            // Delete the persistent storage file
            if (store.exists()) {
                if (!store.delete()) {
                    getLogger().warn("Couldn't delete persistent storage file " + store.getAbsolutePath());
                }
            }
        }
    }

    /**
     * Return a File object representing the pathname to our persistence file, if any.
     */
    private File sessionStore(String ctxPath) {
        String storeDir = getSystemPropertyValue(catalinaBaseSystemProperty);
        if (storeDir == null || storeDir.isEmpty()) {
            storeDir = getSystemPropertyValue(javaTempDirSystemProperty);
        } else {
            storeDir += getSystemPropertyValue(fileSeparatorSystemProperty) + "temp";
        }
        return getFileAtPath(storeDir, ctxPath);
    }

    String getSystemPropertyValue(String propertyKey) {
        return System.getProperty(propertyKey);
    }

    File getFileAtPath(String storeDir, String ctxPath) {
        return (new File(storeDir, ctxPath.replaceAll("/", "_") + ".sessions.ser"));
    }

    FileInputStream getFileInputStream(File file) throws FileNotFoundException {
        return new FileInputStream(file.getAbsolutePath());
    }

    BufferedInputStream getBufferedInputStream(FileInputStream fis) {
        return new BufferedInputStream(fis);
    }

    ObjectInputStream getObjectInputStream(BufferedInputStream bis) throws IOException {
        return new ObjectInputStream(bis);
    }

    FileOutputStream getFileOutputStream(File file) throws FileNotFoundException {
        return new FileOutputStream(file.getAbsolutePath());
    }

    BufferedOutputStream getBufferedOutputStream(FileOutputStream fos) {
        return new BufferedOutputStream(fos);
    }

    ObjectOutputStream getObjectOutputStream(BufferedOutputStream bos) throws IOException {
        return new ObjectOutputStream(bos);
    }

    void writeToObjectOutputStream(ObjectOutputStream oos, List listToWrite) throws IOException {
        oos.writeObject(listToWrite.size());
    }

    int getSessionCountFromObjectInputStream(ObjectInputStream ois) throws IOException, ClreplacedNotFoundException {
        return (Integer) ois.readObject();
    }

    @Override
    public String toString() {
        return getClreplaced().getSimpleName() + "[" + "container=" + getTheContext() + "; regionName=" + this.regionName + "; regionAttributesId=" + this.regionAttributesId + "]";
    }

    String getContextName() {
        return getTheContext().getName();
    }

    public Context getTheContext() {
        if (getContainer() instanceof Context) {
            return (Context) getContainer();
        } else {
            getLogger().error("Unable to unload sessions - container is of type " + getContainer().getClreplaced().getName() + " instead of StandardContext");
            return null;
        }
    }
}

18 View Complete Implementation : StandardPipeline.java
Copyright Apache License 2.0
Author : apache
/**
 * Standard implementation of a processing <b>Pipeline</b> that will invoke
 * a series of Valves that have been configured to be called in order.  This
 * implementation can be used for any type of Container.
 *
 * <b>IMPLEMENTATION WARNING</b> - This implementation replacedumes that no
 * calls to <code>addValve()</code> or <code>removeValve</code> are allowed
 * while a request is currently being processed.  Otherwise, the mechanism
 * by which per-thread state is maintained will need to be modified.
 *
 * @author Craig R. McClanahan
 */
public clreplaced StandardPipeline extends LifecycleBase implements Pipeline {

    private static final Log log = LogFactory.getLog(StandardPipeline.clreplaced);

    private static final StringManager sm = StringManager.getManager(Constants.Package);

    // ----------------------------------------------------------- Constructors
    /**
     * Construct a new StandardPipeline instance with no replacedociated Container.
     */
    public StandardPipeline() {
        this(null);
    }

    /**
     * Construct a new StandardPipeline instance that is replacedociated with the
     * specified Container.
     *
     * @param container The container we should be replacedociated with
     */
    public StandardPipeline(Container container) {
        super();
        setContainer(container);
    }

    // ----------------------------------------------------- Instance Variables
    /**
     * The basic Valve (if any) replacedociated with this Pipeline.
     */
    protected Valve basic = null;

    /**
     * The Container with which this Pipeline is replacedociated.
     */
    protected Container container = null;

    /**
     * The first valve replacedociated with this Pipeline.
     */
    protected Valve first = null;

    // --------------------------------------------------------- Public Methods
    @Override
    public boolean isAsyncSupported() {
        Valve valve = (first != null) ? first : basic;
        boolean supported = true;
        while (supported && valve != null) {
            supported = supported & valve.isAsyncSupported();
            valve = valve.getNext();
        }
        return supported;
    }

    @Override
    public void findNonAsyncValves(Set<String> result) {
        Valve valve = (first != null) ? first : basic;
        while (valve != null) {
            if (!valve.isAsyncSupported()) {
                result.add(valve.getClreplaced().getName());
            }
            valve = valve.getNext();
        }
    }

    // ------------------------------------------------------ Contained Methods
    /**
     * Return the Container with which this Pipeline is replacedociated.
     */
    @Override
    public Container getContainer() {
        return this.container;
    }

    /**
     * Set the Container with which this Pipeline is replacedociated.
     *
     * @param container The new replacedociated container
     */
    @Override
    public void setContainer(Container container) {
        this.container = container;
    }

    @Override
    protected void initInternal() {
    // NOOP
    }

    /**
     * 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);
    }

    /**
     * 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();
        }
    }

    @Override
    protected void destroyInternal() {
        Valve[] valves = getValves();
        for (Valve valve : valves) {
            removeValve(valve);
        }
    }

    /**
     * Return a String representation of this component.
     */
    @Override
    public String toString() {
        return ToStringUtil.toString(this);
    }

    // ------------------------------------------------------- Pipeline Methods
    /**
     * <p>Return the Valve instance that has been distinguished as the basic
     * Valve for this Pipeline (if any).
     */
    @Override
    public Valve getBasic() {
        return this.basic;
    }

    /**
     * <p>Set the Valve instance that has been distinguished as the basic
     * Valve for this Pipeline (if any).  Prior to setting the basic Valve,
     * the Valve's <code>setContainer()</code> 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 replacedociated with this Container, or
     * <code>IllegalStateException</code> if it is already replacedociated with
     * a different Container.</p>
     *
     * @param valve Valve to be distinguished as the basic Valve
     */
    @Override
    public void setBasic(Valve valve) {
        // Change components if necessary
        Valve oldBasic = this.basic;
        if (oldBasic == valve)
            return;
        // Stop the old component if necessary
        if (oldBasic != null) {
            if (getState().isAvailable() && (oldBasic instanceof Lifecycle)) {
                try {
                    ((Lifecycle) oldBasic).stop();
                } catch (LifecycleException e) {
                    log.error(sm.getString("standardPipeline.basic.stop"), e);
                }
            }
            if (oldBasic instanceof Contained) {
                try {
                    ((Contained) oldBasic).setContainer(null);
                } catch (Throwable t) {
                    ExceptionUtils.handleThrowable(t);
                }
            }
        }
        // Start the new component if necessary
        if (valve == null)
            return;
        if (valve instanceof Contained) {
            ((Contained) valve).setContainer(this.container);
        }
        if (getState().isAvailable() && valve instanceof Lifecycle) {
            try {
                ((Lifecycle) valve).start();
            } catch (LifecycleException e) {
                log.error(sm.getString("standardPipeline.basic.start"), e);
                return;
            }
        }
        // Update the pipeline
        Valve current = first;
        while (current != null) {
            if (current.getNext() == oldBasic) {
                current.setNext(valve);
                break;
            }
            current = current.getNext();
        }
        this.basic = valve;
    }

    /**
     * <p>Add a new Valve to the end of the pipeline replacedociated 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 replacedociated with this Container, or <code>IllegalStateException</code>
     * if it is already replacedociated 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
     *  replacedociated with this Container
     * @exception IllegalStateException if the specified Valve is already
     *  replacedociated 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(sm.getString("standardPipeline.valve.start"), e);
                }
            }
        }
        // Add this Valve to the set replacedociated 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);
    }

    /**
     * Return the set of Valves in the pipeline replacedociated with this
     * Container, including the basic Valve (if any).  If there are no
     * such Valves, a zero-length array is returned.
     */
    @Override
    public Valve[] getValves() {
        List<Valve> valveList = new ArrayList<>();
        Valve current = first;
        if (current == null) {
            current = basic;
        }
        while (current != null) {
            valveList.add(current);
            current = current.getNext();
        }
        return valveList.toArray(new Valve[0]);
    }

    public ObjectName[] getValveObjectNames() {
        List<ObjectName> valveList = new ArrayList<>();
        Valve current = first;
        if (current == null) {
            current = basic;
        }
        while (current != null) {
            if (current instanceof JmxEnabled) {
                valveList.add(((JmxEnabled) current).getObjectName());
            }
            current = current.getNext();
        }
        return valveList.toArray(new ObjectName[0]);
    }

    /**
     * Remove the specified Valve from the pipeline replacedociated 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(sm.getString("standardPipeline.valve.stop"), e);
                }
            }
            try {
                ((Lifecycle) valve).destroy();
            } catch (LifecycleException e) {
                log.error(sm.getString("standardPipeline.valve.destroy"), e);
            }
        }
        container.fireContainerEvent(Container.REMOVE_VALVE_EVENT, valve);
    }

    @Override
    public Valve getFirst() {
        if (first != null) {
            return first;
        }
        return basic;
    }
}

18 View Complete Implementation : ClusterManagerBase.java
Copyright Apache License 2.0
Author : apache
/**
 * Register cross context session at replication valve thread local
 * @param session cross context session
 */
protected void registerSessionAtReplicationValve(DeltaSession session) {
    if (replicationValve == null) {
        CatalinaCluster cluster = getCluster();
        if (cluster != null) {
            Valve[] valves = cluster.getValves();
            if (valves != null && valves.length > 0) {
                for (int i = 0; replicationValve == null && i < valves.length; i++) {
                    if (valves[i] instanceof ReplicationValve)
                        replicationValve = (ReplicationValve) valves[i];
                }
                // for
                if (replicationValve == null && log.isDebugEnabled()) {
                    log.debug("no ReplicationValve found for CrossContext Support");
                }
            // endif
            }
        // end if
        }
    // endif
    }
    // end if
    if (replicationValve != null) {
        replicationValve.registerReplicationSession(session);
    }
}

18 View Complete Implementation : SimpleTcpCluster.java
Copyright Apache License 2.0
Author : apache
/**
 * Add cluster valve
 * Cluster Valves are only add to container when cluster is started!
 * @param valve The new cluster Valve.
 */
@Override
public void addValve(Valve valve) {
    if (valve instanceof ClusterValve && (!valves.contains(valve)))
        valves.add(valve);
}

18 View Complete Implementation : SimpleTcpCluster.java
Copyright Apache License 2.0
Author : apache
/**
 * unregister all cluster valve to host or engine
 */
protected void unregisterClusterValve() {
    for (Valve v : valves) {
        ClusterValve valve = (ClusterValve) v;
        if (log.isDebugEnabled())
            log.debug("Invoking removeValve on " + getContainer() + " with clreplaced=" + valve.getClreplaced().getName());
        if (valve != null) {
            container.getPipeline().removeValve(valve);
            valve.setCluster(null);
        }
    }
}

18 View Complete Implementation : SimpleTcpCluster.java
Copyright Apache License 2.0
Author : apache
/**
 * register all cluster valve to host or engine
 */
protected void registerClusterValve() {
    if (container != null) {
        for (Valve v : valves) {
            ClusterValve valve = (ClusterValve) v;
            if (log.isDebugEnabled())
                log.debug("Invoking addValve on " + getContainer() + " with clreplaced=" + valve.getClreplaced().getName());
            if (valve != null) {
                container.getPipeline().addValve(valve);
                valve.setCluster(this);
            }
        }
    }
}

18 View Complete Implementation : FailedContext.java
Copyright Apache License 2.0
Author : apache
@SuppressWarnings("unused")
public synchronized void addValve(Valve valve) {
/* NO-OP */
}

18 View Complete Implementation : StandardContextSF.java
Copyright Apache License 2.0
Author : apache
/**
 * 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();
        List<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);
    }
}

18 View Complete Implementation : ValveBase.java
Copyright Apache License 2.0
Author : apache
/**
 * Convenience base clreplaced for implementations of the <b>Valve</b> interface.
 * A subclreplaced <strong>MUST</strong> implement an <code>invoke()</code>
 * method to provide the required functionality, and <strong>MAY</strong>
 * implement the <code>Lifecycle</code> interface to provide configuration
 * management and lifecycle support.
 *
 * @author Craig R. McClanahan
 */
public abstract clreplaced ValveBase extends LifecycleMBeanBase implements Contained, Valve {

    protected static final StringManager sm = StringManager.getManager(ValveBase.clreplaced);

    // ------------------------------------------------------ Constructor
    public ValveBase() {
        this(false);
    }

    public ValveBase(boolean asyncSupported) {
        this.asyncSupported = asyncSupported;
    }

    // ------------------------------------------------------ Instance Variables
    /**
     * Does this valve support Servlet 3+ async requests?
     */
    protected boolean asyncSupported;

    /**
     * The Container whose pipeline this Valve is a component of.
     */
    protected Container container = null;

    /**
     * Container log
     */
    protected Log containerLog = null;

    /**
     * The next Valve in the pipeline this Valve is a component of.
     */
    protected Valve next = null;

    // -------------------------------------------------------------- Properties
    /**
     * Return the Container with which this Valve is replacedociated, if any.
     */
    @Override
    public Container getContainer() {
        return container;
    }

    /**
     * Set the Container with which this Valve is replacedociated, if any.
     *
     * @param container The new replacedociated container
     */
    @Override
    public void setContainer(Container container) {
        this.container = container;
    }

    @Override
    public boolean isAsyncSupported() {
        return asyncSupported;
    }

    public void setAsyncSupported(boolean asyncSupported) {
        this.asyncSupported = asyncSupported;
    }

    /**
     * Return the next Valve in this pipeline, or <code>null</code> if this
     * is the last Valve in the pipeline.
     */
    @Override
    public Valve getNext() {
        return next;
    }

    /**
     * Set the Valve that follows this one in the pipeline it is part of.
     *
     * @param valve The new next valve
     */
    @Override
    public void setNext(Valve valve) {
        this.next = valve;
    }

    // ---------------------------------------------------------- Public Methods
    /**
     * Execute a periodic task, such as reloading, etc. This method will be
     * invoked inside the clreplacedloading context of this container. Unexpected
     * throwables will be caught and logged.
     */
    @Override
    public void backgroundProcess() {
    // NOOP by default
    }

    @Override
    protected void initInternal() throws LifecycleException {
        super.initInternal();
        containerLog = getContainer().getLogger();
    }

    /**
     * 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 {
        setState(LifecycleState.STARTING);
    }

    /**
     * Stop this component and implement the requirements
     * of {@link org.apache.catalina.util.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);
    }

    /**
     * Return a String rendering of this object.
     */
    @Override
    public String toString() {
        return ToStringUtil.toString(this);
    }

    // -------------------- JMX and Registration  --------------------
    @Override
    public String getObjectNameKeyProperties() {
        StringBuilder name = new StringBuilder("type=Valve");
        Container container = getContainer();
        name.append(container.getMBeanKeyProperties());
        int seq = 0;
        // Pipeline may not be present in unit testing
        Pipeline p = container.getPipeline();
        if (p != null) {
            for (Valve valve : p.getValves()) {
                // Skip null valves
                if (valve == null) {
                    continue;
                }
                // Only compare valves in pipeline until we find this valve
                if (valve == this) {
                    break;
                }
                if (valve.getClreplaced() == this.getClreplaced()) {
                    // Duplicate valve earlier in pipeline
                    // increment sequence number
                    seq++;
                }
            }
        }
        if (seq > 0) {
            name.append(",seq=");
            name.append(seq);
        }
        String clreplacedName = this.getClreplaced().getName();
        int period = clreplacedName.lastIndexOf('.');
        if (period >= 0) {
            clreplacedName = clreplacedName.substring(period + 1);
        }
        name.append(",name=");
        name.append(clreplacedName);
        return name.toString();
    }

    @Override
    public String getDomainInternal() {
        Container c = getContainer();
        if (c == null) {
            return null;
        } else {
            return c.getDomain();
        }
    }
}

18 View Complete Implementation : StandardHost.java
Copyright Apache License 2.0
Author : apache
/**
 * 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 {
    // Set error report valve
    String errorValve = getErrorReportValveClreplaced();
    if ((errorValve != null) && (!errorValve.equals(""))) {
        try {
            boolean found = false;
            Valve[] valves = getPipeline().getValves();
            for (Valve valve : valves) {
                if (errorValve.equals(valve.getClreplaced().getName())) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                Valve valve = (Valve) Clreplaced.forName(errorValve).getDeclaredConstructor().newInstance();
                getPipeline().addValve(valve);
            }
        } catch (Throwable t) {
            ExceptionUtils.handleThrowable(t);
            log.error(sm.getString("standardHost.invalidErrorReportValveClreplaced", errorValve), t);
        }
    }
    super.startInternal();
}

18 View Complete Implementation : StandardPipeline.java
Copyright Apache License 2.0
Author : apache
/**
 * Standard implementation of a processing <b>Pipeline</b> that will invoke
 * a series of Valves that have been configured to be called in order.  This
 * implementation can be used for any type of Container.
 *
 * <b>IMPLEMENTATION WARNING</b> - This implementation replacedumes that no
 * calls to <code>addValve()</code> or <code>removeValve</code> are allowed
 * while a request is currently being processed.  Otherwise, the mechanism
 * by which per-thread state is maintained will need to be modified.
 *
 * @author Craig R. McClanahan
 */
public clreplaced StandardPipeline extends LifecycleBase implements Pipeline, Contained {

    private static final Log log = LogFactory.getLog(StandardPipeline.clreplaced);

    // ----------------------------------------------------------- Constructors
    /**
     * Construct a new StandardPipeline instance with no replacedociated Container.
     */
    public StandardPipeline() {
        this(null);
    }

    /**
     * Construct a new StandardPipeline instance that is replacedociated with the
     * specified Container.
     *
     * @param container The container we should be replacedociated with
     */
    public StandardPipeline(Container container) {
        super();
        setContainer(container);
    }

    // ----------------------------------------------------- Instance Variables
    /**
     * The basic Valve (if any) replacedociated with this Pipeline.
     */
    protected Valve basic = null;

    /**
     * The Container with which this Pipeline is replacedociated.
     */
    protected Container container = null;

    /**
     * The first valve replacedociated with this Pipeline.
     */
    protected Valve first = null;

    // --------------------------------------------------------- Public Methods
    @Override
    public boolean isAsyncSupported() {
        Valve valve = (first != null) ? first : basic;
        boolean supported = true;
        while (supported && valve != null) {
            supported = supported & valve.isAsyncSupported();
            valve = valve.getNext();
        }
        return supported;
    }

    // ------------------------------------------------------ Contained Methods
    /**
     * Return the Container with which this Pipeline is replacedociated.
     */
    @Override
    public Container getContainer() {
        return (this.container);
    }

    /**
     * Set the Container with which this Pipeline is replacedociated.
     *
     * @param container The new replacedociated container
     */
    @Override
    public void setContainer(Container container) {
        this.container = container;
    }

    @Override
    protected void initInternal() {
    // NOOP
    }

    /**
     * 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);
    }

    /**
     * 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();
        }
    }

    @Override
    protected void destroyInternal() {
        Valve[] valves = getValves();
        for (Valve valve : valves) {
            removeValve(valve);
        }
    }

    /**
     * Return a String representation of this component.
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("Pipeline[");
        sb.append(container);
        sb.append(']');
        return sb.toString();
    }

    // ------------------------------------------------------- Pipeline Methods
    /**
     * <p>Return the Valve instance that has been distinguished as the basic
     * Valve for this Pipeline (if any).
     */
    @Override
    public Valve getBasic() {
        return (this.basic);
    }

    /**
     * <p>Set the Valve instance that has been distinguished as the basic
     * Valve for this Pipeline (if any).  Prior to setting the basic Valve,
     * the Valve's <code>setContainer()</code> 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 replacedociated with this Container, or
     * <code>IllegalStateException</code> if it is already replacedociated with
     * a different Container.</p>
     *
     * @param valve Valve to be distinguished as the basic Valve
     */
    @Override
    public void setBasic(Valve valve) {
        // Change components if necessary
        Valve oldBasic = this.basic;
        if (oldBasic == valve)
            return;
        // Stop the old component if necessary
        if (oldBasic != null) {
            if (getState().isAvailable() && (oldBasic instanceof Lifecycle)) {
                try {
                    ((Lifecycle) oldBasic).stop();
                } catch (LifecycleException e) {
                    log.error("StandardPipeline.setBasic: stop", e);
                }
            }
            if (oldBasic instanceof Contained) {
                try {
                    ((Contained) oldBasic).setContainer(null);
                } catch (Throwable t) {
                    ExceptionUtils.handleThrowable(t);
                }
            }
        }
        // Start the new component if necessary
        if (valve == null)
            return;
        if (valve instanceof Contained) {
            ((Contained) valve).setContainer(this.container);
        }
        if (getState().isAvailable() && valve instanceof Lifecycle) {
            try {
                ((Lifecycle) valve).start();
            } catch (LifecycleException e) {
                log.error("StandardPipeline.setBasic: start", e);
                return;
            }
        }
        // Update the pipeline
        Valve current = first;
        while (current != null) {
            if (current.getNext() == oldBasic) {
                current.setNext(valve);
                break;
            }
            current = current.getNext();
        }
        this.basic = valve;
    }

    /**
     * <p>Add a new Valve to the end of the pipeline replacedociated 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 replacedociated with this Container, or <code>IllegalStateException</code>
     * if it is already replacedociated 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
     *  replacedociated with this Container
     * @exception IllegalStateException if the specified Valve is already
     *  replacedociated 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 replacedociated 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);
    }

    /**
     * Return the set of Valves in the pipeline replacedociated with this
     * Container, including the basic Valve (if any).  If there are no
     * such Valves, a zero-length array is returned.
     */
    @Override
    public Valve[] getValves() {
        ArrayList<Valve> valveList = new ArrayList<>();
        Valve current = first;
        if (current == null) {
            current = basic;
        }
        while (current != null) {
            valveList.add(current);
            current = current.getNext();
        }
        return valveList.toArray(new Valve[0]);
    }

    public ObjectName[] getValveObjectNames() {
        ArrayList<ObjectName> valveList = new ArrayList<>();
        Valve current = first;
        if (current == null) {
            current = basic;
        }
        while (current != null) {
            if (current instanceof JmxEnabled) {
                valveList.add(((JmxEnabled) current).getObjectName());
            }
            current = current.getNext();
        }
        return valveList.toArray(new ObjectName[0]);
    }

    /**
     * Remove the specified Valve from the pipeline replacedociated 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);
    }

    @Override
    public Valve getFirst() {
        if (first != null) {
            return first;
        }
        return basic;
    }
}