001    package org.apache.turbine.pipeline;
002    
003    
004    /*
005     * Licensed to the Apache Software Foundation (ASF) under one
006     * or more contributor license agreements.  See the NOTICE file
007     * distributed with this work for additional information
008     * regarding copyright ownership.  The ASF licenses this file
009     * to you under the Apache License, Version 2.0 (the
010     * "License"); you may not use this file except in compliance
011     * with the License.  You may obtain a copy of the License at
012     *
013     *   http://www.apache.org/licenses/LICENSE-2.0
014     *
015     * Unless required by applicable law or agreed to in writing,
016     * software distributed under the License is distributed on an
017     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018     * KIND, either express or implied.  See the License for the
019     * specific language governing permissions and limitations
020     * under the License.
021     */
022    
023    
024    import java.io.IOException;
025    
026    import org.apache.turbine.util.TurbineException;
027    
028    /**
029     * <p>A <b>Valve</b> is a request processing component.  A series of
030     * Valves are generally associated with each other into a Pipeline.
031     * The detailed contract for a Valve is included in the description of
032     * the <code>invoke()</code> method below.</p>
033     *
034     * <b>HISTORICAL NOTE</b>:  The "Valve" name was assigned to this concept
035     * because a valve is what you use in a real world pipeline to control and/or
036     * modify flows through it.
037     *
038     * @author Craig R. McClanahan
039     * @author Gunnar Rjnning
040     * @author Peter Donald
041     * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
042     *
043     * @see #invoke(RunData, ValveContext)
044     */
045    public interface Valve
046    {
047        /**
048         * <p>Perform request processing as required by this Valve.</p>
049         *
050         * <p>An individual Valve <b>MAY</b> perform the following actions, in
051         * the specified order:</p>
052         * <ul>
053         * <li>Examine and/or modify the properties of the specified Request and
054         *     Response.
055         * <li>Examine the properties of the specified Request, completely generate
056         *     the corresponding Response, and return control to the caller.
057         * <li>Examine the properties of the specified Request and Response, wrap
058         *     either or both of these objects to supplement their functionality,
059         *     and pass them on.
060         * <li>If the corresponding Response was not generated (and control was not
061         *     returned, call the next Valve in the pipeline (if there is one) by
062         *     executing <code>context.invokeNext()</code>.
063         * <li>Examine, but not modify, the properties of the resulting Response
064         *     (which was created by a subsequently invoked Valve via a
065         *     call to <code>context.invokeNext()</code>).
066         * </ul>
067         *
068         * <p>A Valve <b>MUST NOT</b> do any of the following things:</p>
069         * <ul>
070         * <li>Change request properties that have already been used to direct
071         *     the flow of processing control for this request.
072         * <li>Create a completed Response <strong>AND</strong> pass this
073         *     Request and Response on to the next Valve in the pipeline.
074         * <li>Consume bytes from the input stream associated with the Request,
075         *     unless it is completely generating the response, or wrapping the
076         *     request before passing it on.
077         * <li>Modify the HTTP headers included with the Response after the
078         *     <code>invokeNext()</code> method has returned.
079         * <li>Perform any actions on the output stream associated with the
080         *     specified Response after the <code>invokeNext()</code> method has
081         *     returned.
082         * </ul>
083         *
084         * @param data The run-time information, including the servlet
085         * request and response we are processing.
086         * @param context The valve context used to invoke the next valve
087         *  in the current processing pipeline
088         *
089         * @exception IOException Thrown by a subsequent Valve.
090         * @exception TurbineException Thrown by a subsequent Valve.
091         */
092        public void invoke(PipelineData data, ValveContext context)
093            throws IOException, TurbineException;
094    
095        /**
096         * Initialize the valve before using in a pipeline.
097         */
098        public void initialize()
099            throws Exception;
100    }