Line | Hits | Source |
---|---|---|
1 | /* | |
2 | Chrysalis Web Framework [http://chrysalis.sourceforge.net] | |
3 | Copyright (c) 2002, 2003, 2004, Paul Strack | |
4 | ||
5 | All rights reserved. | |
6 | ||
7 | Redistribution and use in source and binary forms, with or without | |
8 | modification, are permitted provided that the following conditions are met: | |
9 | ||
10 | 1. Redistributions of source code must retain the above copyright notice, this | |
11 | list of conditions and the following disclaimer. | |
12 | ||
13 | 2. Redistributions in binary form must reproduce the above copyright notice, | |
14 | this list of conditions and the following disclaimer in the documentation | |
15 | and/or other materials provided with the distribution. | |
16 | ||
17 | 3. Neither the name of the copyright holder nor the names of its contributors | |
18 | may be used to endorse or promote products derived from this software without | |
19 | specific prior written permission. | |
20 | ||
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
22 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | |
25 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |
28 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
31 | */ | |
32 | ||
33 | package org.chwf.servlet.filter; | |
34 | ||
35 | import java.io.IOException; | |
36 | ||
37 | import javax.servlet.Filter; | |
38 | import javax.servlet.ServletConfig; | |
39 | import javax.servlet.ServletContext; | |
40 | import javax.servlet.ServletException; | |
41 | import javax.servlet.http.HttpServlet; | |
42 | import javax.servlet.http.HttpServletRequest; | |
43 | import javax.servlet.http.HttpServletResponse; | |
44 | ||
45 | /** | |
46 | * A component that intercepts requests and invokes components. It acts as | |
47 | * a "micro-container" to add Servlet 2.3 filter support to a Servlet 2.2 | |
48 | * compliant server. | |
49 | * | |
50 | * @author <a href="mailto:pfstrack@users.sourceforge.net">Paul Strack</a> | |
51 | */ | |
52 | 6 | public class FilterServlet extends HttpServlet { |
53 | ||
54 | /** Set of filters. */ | |
55 | private FilterSet filterSet; | |
56 | ||
57 | /** | |
58 | * Initialize the filters for the Chrysalis micro-container. | |
59 | * | |
60 | * @param config The servlet config. | |
61 | * @throws ServletException If the filters cannot be initialized. | |
62 | */ | |
63 | public void init(ServletConfig config) throws ServletException { | |
64 | 7 | super.init(config); |
65 | 7 | ServletContext context = config.getServletContext(); |
66 | try { | |
67 | 7 | this.filterSet = |
68 | new FilterSet(AllFilterConfig.getConfig(context)); | |
69 | 7 | ResourceMapper.init(context); |
70 | 7 | } catch (ServletException ex) { |
71 | 0 | throw ex; |
72 | } catch (Exception ex) { | |
73 | 0 | context.log("The filters could not be initialized", ex); |
74 | 0 | throw new ServletException(ex); |
75 | } | |
76 | 7 | } |
77 | ||
78 | /** | |
79 | * Runs filters. | |
80 | * | |
81 | * @param request The request. | |
82 | * @param response The response. | |
83 | * @throws ServletException For servlet exceptions. | |
84 | * @throws IOException For IO exceptions. | |
85 | */ | |
86 | public void doGet(HttpServletRequest request, HttpServletResponse response) | |
87 | throws ServletException, IOException { | |
88 | ||
89 | 1 | Filter terminator = ResourceMapper.getFilter(request); |
90 | 1 | this.filterSet.doChain(request, response, terminator); |
91 | 1 | } |
92 | ||
93 | /** | |
94 | * Runs filters. | |
95 | * | |
96 | * @param request The request. | |
97 | * @param response The response. | |
98 | * @throws ServletException For servlet exceptions. | |
99 | * @throws IOException For IO exceptions. | |
100 | */ | |
101 | public void doPost(HttpServletRequest request, HttpServletResponse response) | |
102 | throws ServletException, IOException { | |
103 | ||
104 | 1 | Filter terminator = ResourceMapper.getFilter(request); |
105 | 1 | this.filterSet.doChain(request, response, terminator); |
106 | 1 | } |
107 | ||
108 | /** Destroy all filters. */ | |
109 | public void destroy() { | |
110 | 1 | this.filterSet.destroy(); |
111 | 1 | } |
112 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |