KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > server > FilterTestRedirector


1 /*
2  * ========================================================================
3  *
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.cactus.server;
21
22 import java.io.IOException JavaDoc;
23
24 import javax.servlet.Filter JavaDoc;
25 import javax.servlet.FilterChain JavaDoc;
26 import javax.servlet.FilterConfig JavaDoc;
27 import javax.servlet.ServletException JavaDoc;
28 import javax.servlet.ServletRequest JavaDoc;
29 import javax.servlet.ServletResponse JavaDoc;
30 import javax.servlet.http.HttpServletRequest JavaDoc;
31 import javax.servlet.http.HttpServletResponse JavaDoc;
32
33 import org.apache.cactus.internal.configuration.ConfigurationInitializer;
34 import org.apache.cactus.internal.server.FilterImplicitObjects;
35 import org.apache.cactus.internal.server.FilterTestController;
36 import org.apache.commons.logging.Log;
37 import org.apache.commons.logging.LogFactory;
38
39 /**
40  * Generic Filter redirector that calls a test method on the server side.
41  *
42  * @version $Id: FilterTestRedirector.java,v 1.1 2004/05/22 11:34:47 vmassol Exp $
43  * @see org.apache.cactus.internal.server.FilterTestCaller
44  */

45 public class FilterTestRedirector implements Filter JavaDoc
46 {
47     /**
48      * As this class is the first one loaded on the server side, we ensure
49      * that the Cactus configuration has been initialized. A better
50      * implementation might be to perform this initialization in the
51      * init() method. However, that requires removing the static LOGGER
52      * object.
53      */

54     static
55     {
56         ConfigurationInitializer.initialize();
57     }
58
59     /**
60      * The logger
61      */

62     private static final Log LOGGER =
63         LogFactory.getLog(FilterTestRedirector.class);
64
65     /**
66      * The filter configuration object passed by the container when it calls
67      * <code>init(FilterConfig)</code>
68      */

69     private FilterConfig JavaDoc config;
70
71     /**
72      * Handle the request. Extract from the HTTP request paramete the
73      * Service to perform : call test method or return tests results.
74      *
75      * @param theRequest the incoming HTTP request which contains all needed
76      * information on the test case and method to call
77      * @param theResponse the response to send back to the client side
78      * @param theFilterChain contains the chain of filters.
79      * @exception IOException if an error occurred during test on server side
80      * @exception ServletException if an error occurred during test on server
81      * side
82      */

83     public void doFilter(ServletRequest JavaDoc theRequest,
84         ServletResponse JavaDoc theResponse, FilterChain JavaDoc theFilterChain)
85         throws IOException JavaDoc, ServletException JavaDoc
86     {
87         // Mark beginning of test on server side
88
LOGGER.debug("------------- Start Filter service");
89
90         // Create implicit object holder
91
FilterImplicitObjects objects = new FilterImplicitObjects();
92
93         objects.setHttpServletRequest((HttpServletRequest JavaDoc) theRequest);
94         objects.setHttpServletResponse((HttpServletResponse JavaDoc) theResponse);
95         objects.setFilterConfig(this.config);
96         objects.setServletContext(this.config.getServletContext());
97         objects.setFilterChain(theFilterChain);
98
99         FilterTestController controller = new FilterTestController();
100
101         controller.handleRequest(objects);
102     }
103
104     /**
105      * Initialise this filter redirector. Called by the container.
106      *
107      * @param theConfig the filter config containing initialisation
108      * parameters from web.xml
109      */

110     public void init(FilterConfig JavaDoc theConfig)
111     {
112         // Save the config to pass it to the test case later on
113
this.config = theConfig;
114     }
115
116     /**
117      * Provided so that it works with containers that do not support the
118      * latest Filter spec yet (ex: Orion 1.5.2)
119      *
120      * @param theConfig the Filter Config
121      */

122     public void setFilterConfig(FilterConfig JavaDoc theConfig)
123     {
124         this.config = theConfig;
125     }
126
127     /**
128      * Provided so that it works with containers that do not support the
129      * latest Filter spec yet (ex: Orion 1.5.2)
130      *
131      * @return the Filter Config
132      */

133     public FilterConfig JavaDoc getFilterConfig()
134     {
135         return this.config;
136     }
137
138     /**
139      * Destroy the filter. Called by the container.
140      */

141     public void destroy()
142     {
143     }
144 }
145
Popular Tags