001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.catalina;
019:
020: import java.io.IOException;
021: import javax.servlet.ServletException;
022:
023: import org.apache.catalina.connector.Request;
024: import org.apache.catalina.connector.Response;
025:
026: /**
027: * <p>A <b>Valve</b> is a request processing component associated with a
028: * particular Container. A series of Valves are generally associated with
029: * each other into a Pipeline. The detailed contract for a Valve is included
030: * in the description of the <code>invoke()</code> method below.</p>
031: *
032: * <b>HISTORICAL NOTE</b>: The "Valve" name was assigned to this concept
033: * because a valve is what you use in a real world pipeline to control and/or
034: * modify flows through it.
035: *
036: * @author Craig R. McClanahan
037: * @author Gunnar Rjnning
038: * @author Peter Donald
039: * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
040: */
041:
042: public interface Valve {
043:
044: //-------------------------------------------------------------- Properties
045:
046: /**
047: * Return descriptive information about this Valve implementation.
048: */
049: public String getInfo();
050:
051: /**
052: * Return the next Valve in the pipeline containing this Valve, if any.
053: */
054: public Valve getNext();
055:
056: /**
057: * Set the next Valve in the pipeline containing this Valve.
058: *
059: * @param valve The new next valve, or <code>null</code> if none
060: */
061: public void setNext(Valve valve);
062:
063: //---------------------------------------------------------- Public Methods
064:
065: /**
066: * Execute a periodic task, such as reloading, etc. This method will be
067: * invoked inside the classloading context of this container. Unexpected
068: * throwables will be caught and logged.
069: */
070: public void backgroundProcess();
071:
072: /**
073: * <p>Perform request processing as required by this Valve.</p>
074: *
075: * <p>An individual Valve <b>MAY</b> perform the following actions, in
076: * the specified order:</p>
077: * <ul>
078: * <li>Examine and/or modify the properties of the specified Request and
079: * Response.
080: * <li>Examine the properties of the specified Request, completely generate
081: * the corresponding Response, and return control to the caller.
082: * <li>Examine the properties of the specified Request and Response, wrap
083: * either or both of these objects to supplement their functionality,
084: * and pass them on.
085: * <li>If the corresponding Response was not generated (and control was not
086: * returned, call the next Valve in the pipeline (if there is one) by
087: * executing <code>context.invokeNext()</code>.
088: * <li>Examine, but not modify, the properties of the resulting Response
089: * (which was created by a subsequently invoked Valve or Container).
090: * </ul>
091: *
092: * <p>A Valve <b>MUST NOT</b> do any of the following things:</p>
093: * <ul>
094: * <li>Change request properties that have already been used to direct
095: * the flow of processing control for this request (for instance,
096: * trying to change the virtual host to which a Request should be
097: * sent from a pipeline attached to a Host or Context in the
098: * standard implementation).
099: * <li>Create a completed Response <strong>AND</strong> pass this
100: * Request and Response on to the next Valve in the pipeline.
101: * <li>Consume bytes from the input stream associated with the Request,
102: * unless it is completely generating the response, or wrapping the
103: * request before passing it on.
104: * <li>Modify the HTTP headers included with the Response after the
105: * <code>invokeNext()</code> method has returned.
106: * <li>Perform any actions on the output stream associated with the
107: * specified Response after the <code>invokeNext()</code> method has
108: * returned.
109: * </ul>
110: *
111: * @param request The servlet request to be processed
112: * @param response The servlet response to be created
113: *
114: * @exception IOException if an input/output error occurs, or is thrown
115: * by a subsequently invoked Valve, Filter, or Servlet
116: * @exception ServletException if a servlet error occurs, or is thrown
117: * by a subsequently invoked Valve, Filter, or Servlet
118: */
119: public void invoke(Request request, Response response)
120: throws IOException, ServletException;
121:
122: /**
123: * Process a Comet event.
124: *
125: * @param request The servlet request to be processed
126: * @param response The servlet response to be created
127: *
128: * @exception IOException if an input/output error occurs, or is thrown
129: * by a subsequently invoked Valve, Filter, or Servlet
130: * @exception ServletException if a servlet error occurs, or is thrown
131: * by a subsequently invoked Valve, Filter, or Servlet
132: */
133: public void event(Request request, Response response,
134: CometEvent event) throws IOException, ServletException;
135:
136: }
|