1 /*
2 * ========================================================================
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * ========================================================================
20 */
21 package org.apache.cactus.server;
22
23 import javax.servlet.ServletException;
24 import javax.servlet.http.HttpServlet;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
27
28 import org.apache.cactus.internal.configuration.ConfigurationInitializer;
29 import org.apache.cactus.internal.server.ServletImplicitObjects;
30 import org.apache.cactus.internal.server.ServletTestController;
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33
34 /**
35 * Generic Servlet redirector that calls a test method on the server side.
36 *
37 * @version $Id: ServletTestRedirector.java 238991 2004-05-22 11:34:50Z vmassol $
38 * @see org.apache.cactus.internal.server.ServletTestCaller
39 */
40 public class ServletTestRedirector extends HttpServlet
41 {
42 /**
43 * As this class is the first one loaded on the server side, we ensure
44 * that the Cactus configuration has been initialized. A better
45 * implementation might be to perform this initialization in the
46 * init() method. However, that requires removing the static LOGGER
47 * object.
48 */
49 static
50 {
51 ConfigurationInitializer.initialize();
52 }
53
54 /**
55 * The logger.
56 */
57 private static final Log LOGGER =
58 LogFactory.getLog(ServletTestRedirector.class);
59
60 /**
61 * Handle GET requests.
62 *
63 * @param theRequest the incoming HTTP client request
64 * @param theResponse the outgoing HTTP client request to send back.
65 *
66 * @exception ServletException if an error occurs when servicing the
67 * request
68 */
69 public void doGet(HttpServletRequest theRequest,
70 HttpServletResponse theResponse) throws ServletException
71 {
72 // Same handling than for a POST
73 doPost(theRequest, theResponse);
74 }
75
76 /**
77 * Handle POST request. Extract from the HTTP request parameter, the
78 * Service to perform : call test method or return tests results.
79 *
80 * @param theRequest the incoming HTTP request.
81 * @param theResponse the outgoing HTTP response.
82 *
83 * @exception ServletException if an error occurs when servicing the
84 * request
85 */
86 public void doPost(HttpServletRequest theRequest,
87 HttpServletResponse theResponse) throws ServletException
88 {
89 // Mark beginning of test on server side
90 LOGGER.debug("------------- Start Servlet service");
91
92 // Create implicit object holder
93 ServletImplicitObjects objects = new ServletImplicitObjects();
94
95 objects.setHttpServletRequest(theRequest);
96 objects.setHttpServletResponse(theResponse);
97 objects.setServletContext(getServletContext());
98 objects.setServletConfig(getServletConfig());
99
100 ServletTestController controller = new ServletTestController();
101
102 controller.handleRequest(objects);
103 }
104 }