Save This Page
Home » glassfish-v2ur2-b04-src » javax » servlet » [javadoc | source]
    1   
    2   
    3   /*
    4    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    5    * 
    6    * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    7    * 
    8    * Portions Copyright Apache Software Foundation.
    9    * 
   10    * The contents of this file are subject to the terms of either the GNU
   11    * General Public License Version 2 only ("GPL") or the Common Development
   12    * and Distribution License("CDDL") (collectively, the "License").  You
   13    * may not use this file except in compliance with the License. You can obtain
   14    * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
   15    * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
   16    * language governing permissions and limitations under the License.
   17    * 
   18    * When distributing the software, include this License Header Notice in each
   19    * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
   20    * Sun designates this particular file as subject to the "Classpath" exception
   21    * as provided by Sun in the GPL Version 2 section of the License file that
   22    * accompanied this code.  If applicable, add the following below the License
   23    * Header, with the fields enclosed by brackets [] replaced by your own
   24    * identifying information: "Portions Copyrighted [year]
   25    * [name of copyright owner]"
   26    * 
   27    * Contributor(s):
   28    * 
   29    * If you wish your version of this file to be governed by only the CDDL or
   30    * only the GPL Version 2, indicate your decision by adding "[Contributor]
   31    * elects to include this software in this distribution under the [CDDL or GPL
   32    * Version 2] license."  If you don't indicate a single choice of license, a
   33    * recipient has the option to distribute your version of this file under
   34    * either the CDDL, the GPL Version 2 or to extend the choice of license to
   35    * its licensees as provided above.  However, if you add GPL Version 2 code
   36    * and therefore, elected the GPL Version 2 license, then the option applies
   37    * only if the new code is made subject to such option by the copyright
   38    * holder.
   39    */
   40   
   41   package javax.servlet;
   42   
   43   import java.io.IOException;
   44   
   45   	/** 
   46   	* A filter is an object that performs filtering tasks on either the request to a resource (a servlet or static content), or on the response from a resource, or both.
   47           * <br><br>
   48   	* Filters perform filtering in the <code>doFilter</code> method. Every Filter has access to 
   49   	** a FilterConfig object from which it can obtain its initialization parameters, a
   50   	** reference to the ServletContext which it can use, for example, to load resources
   51   	** needed for filtering tasks.
   52   	** <p>
   53   	** Filters are configured in the deployment descriptor of a web application
   54   	** <p>
   55   	** Examples that have been identified for this design are<br>
   56   	** 1) Authentication Filters <br>
   57   	** 2) Logging and Auditing Filters <br>
   58   	** 3) Image conversion Filters <br>
   59       	** 4) Data compression Filters <br>
   60   	** 5) Encryption Filters <br>
   61   	** 6) Tokenizing Filters <br>
   62   	** 7) Filters that trigger resource access events <br>
   63   	** 8) XSL/T filters <br>
   64   	** 9) Mime-type chain Filter <br>
   65   	 * @since	Servlet 2.3
   66   	*/
   67   
   68   public interface Filter {
   69   
   70   	/** 
   71   	* Called by the web container to indicate to a filter that it is being placed into
   72   	* service. The servlet container calls the init method exactly once after instantiating the
   73   	* filter. The init method must complete successfully before the filter is asked to do any
   74   	* filtering work. <br><br>
   75   
   76        	* The web container cannot place the filter into service if the init method either<br>
   77           * 1.Throws a ServletException <br>
   78           * 2.Does not return within a time period defined by the web container 
   79   	*/
   80   	public void init(FilterConfig filterConfig) throws ServletException;
   81   	
   82   	
   83   	/**
   84   	* The <code>doFilter</code> method of the Filter is called by the container
   85   	* each time a request/response pair is passed through the chain due
   86   	* to a client request for a resource at the end of the chain. The FilterChain passed in to this
   87   	* method allows the Filter to pass on the request and response to the next entity in the
   88   	* chain.<p>
   89   	* A typical implementation of this method would follow the following pattern:- <br>
   90   	* 1. Examine the request<br>
   91   	* 2. Optionally wrap the request object with a custom implementation to
   92   	* filter content or headers for input filtering <br>
   93   	* 3. Optionally wrap the response object with a custom implementation to
   94   	* filter content or headers for output filtering <br>
   95   	* 4. a) <strong>Either</strong> invoke the next entity in the chain using the FilterChain object (<code>chain.doFilter()</code>), <br>   
   96   	** 4. b) <strong>or</strong> not pass on the request/response pair to the next entity in the filter chain to block the request processing<br>
   97   	** 5. Directly set headers on the response after invocation of the next entity in the filter chain.
   98   	**/
   99       public void doFilter ( ServletRequest request, ServletResponse response, FilterChain chain ) throws IOException, ServletException;
  100   
  101   	/**
  102   	* Called by the web container to indicate to a filter that it is being taken out of service. This 
  103   	* method is only called once all threads within the filter's doFilter method have exited or after
  104   	* a timeout period has passed. After the web container calls this method, it will not call the
  105   	* doFilter method again on this instance of the filter. <br><br>
  106   	* 
  107        	* This method gives the filter an opportunity to clean up any resources that are being held (for
  108   	* example, memory, file handles, threads) and make sure that any persistent state is synchronized
  109   	* with the filter's current state in memory.
  110   	*/
  111   
  112   	public void destroy();
  113   
  114   
  115   }
  116   

Save This Page
Home » glassfish-v2ur2-b04-src » javax » servlet » [javadoc | source]