KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.servlet.ServletException JavaDoc;
23 import javax.servlet.http.HttpServlet JavaDoc;
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26
27 import org.apache.cactus.internal.configuration.ConfigurationInitializer;
28 import org.apache.cactus.internal.server.ServletImplicitObjects;
29 import org.apache.cactus.internal.server.ServletTestController;
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32
33 /**
34  * Generic Servlet redirector that calls a test method on the server side.
35  *
36  * @version $Id: ServletTestRedirector.java,v 1.1 2004/05/22 11:34:48 vmassol Exp $
37  * @see org.apache.cactus.internal.server.ServletTestCaller
38  */

39 public class ServletTestRedirector extends HttpServlet JavaDoc
40 {
41     /**
42      * As this class is the first one loaded on the server side, we ensure
43      * that the Cactus configuration has been initialized. A better
44      * implementation might be to perform this initialization in the
45      * init() method. However, that requires removing the static LOGGER
46      * object.
47      */

48     static
49     {
50         ConfigurationInitializer.initialize();
51     }
52     
53     /**
54      * The logger
55      */

56     private static final Log LOGGER =
57         LogFactory.getLog(ServletTestRedirector.class);
58
59     /**
60      * Handle GET requests.
61      *
62      * @param theRequest the incoming HTTP client request
63      * @param theResponse the outgoing HTTP client request to send back.
64      *
65      * @exception ServletException if an error occurs when servicing the
66      * request
67      */

68     public void doGet(HttpServletRequest JavaDoc theRequest,
69         HttpServletResponse JavaDoc theResponse) throws ServletException JavaDoc
70     {
71         // Same handling than for a POST
72
doPost(theRequest, theResponse);
73     }
74
75     /**
76      * Handle POST request. Extract from the HTTP request parameter, the
77      * Service to perform : call test method or return tests results.
78      *
79      * @param theRequest the incoming HTTP request.
80      * @param theResponse the outgoing HTTP response.
81      *
82      * @exception ServletException if an error occurs when servicing the
83      * request
84      */

85     public void doPost(HttpServletRequest JavaDoc theRequest,
86         HttpServletResponse JavaDoc theResponse) throws ServletException JavaDoc
87     {
88         // Mark beginning of test on server side
89
LOGGER.debug("------------- Start Servlet service");
90
91         // Create implicit object holder
92
ServletImplicitObjects objects = new ServletImplicitObjects();
93
94         objects.setHttpServletRequest(theRequest);
95         objects.setHttpServletResponse(theResponse);
96         objects.setServletContext(getServletContext());
97         objects.setServletConfig(getServletConfig());
98
99         ServletTestController controller = new ServletTestController();
100
101         controller.handleRequest(objects);
102     }
103 }
104
Popular Tags