1
|
|
/* Generated by AspectJ version 1.0.5 */
|
2
|
|
package org.apache.cactus.server;
|
3
|
|
import javax.servlet.ServletException;
|
4
|
|
import javax.servlet.http.HttpServletRequest;
|
5
|
|
import org.apache.cactus.HttpServiceDefinition;
|
6
|
|
import org.apache.cactus.ServiceEnumeration;
|
7
|
|
import org.apache.commons.logging.Log;
|
8
|
|
import org.apache.commons.logging.LogFactory;
|
9
|
|
|
10
|
|
/**
|
11
|
|
* Controller that extracts the requested service from the HTTP request and
|
12
|
|
* executes the request by calling a <code>WebTestCaller</code>. There
|
13
|
|
* are 2 services available : one for executing the test and one for returning
|
14
|
|
* the test result.
|
15
|
|
*
|
16
|
|
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
17
|
|
*
|
18
|
|
* @version $Id: AbstractWebTestController.html,v 1.1 2003/04/14 12:27:31 sinisa Exp $
|
19
|
|
*/
|
20
|
|
public abstract class AbstractWebTestController implements TestController {
|
21
|
|
/**
|
22
|
|
* The logger
|
23
|
|
*/
|
24
|
|
private static Log LOGGER;
|
25
|
|
/**
|
26
|
|
* @param theObjects the implicit objects coming from the redirector
|
27
|
|
* @return the test caller that will be used to execute the test
|
28
|
|
*/
|
29
|
|
protected abstract AbstractWebTestCaller getTestCaller(WebImplicitObjects theObjects);
|
30
|
|
|
31
|
|
/**
|
32
|
|
* Handles the incoming request by extracting the requested service and
|
33
|
|
* calling the correct method on a <code>WebTestCaller</code>.
|
34
|
|
*
|
35
|
|
* @param theObjects the implicit objects (they are different for the
|
36
|
|
* different redirectors)
|
37
|
|
* @exception ServletException if an error occurs when servicing the
|
38
|
|
* request
|
39
|
|
*/
|
40
|
675
|
public void handleRequest(ImplicitObjects theObjects) throws ServletException {
|
41
|
675
|
WebImplicitObjects webImplicitObjects = (WebImplicitObjects)theObjects;
|
42
|
675
|
try {
|
43
|
675
|
String serviceName = this.getServiceName(webImplicitObjects.getHttpServletRequest());
|
44
|
675
|
AbstractWebTestCaller caller = this.getTestCaller(webImplicitObjects);
|
45
|
675
|
if (ServiceEnumeration.CALL_TEST_SERVICE.equals(serviceName)) {
|
46
|
330
|
caller.doTest();
|
47
|
345
|
} else if (ServiceEnumeration.GET_RESULTS_SERVICE.equals(serviceName)) {
|
48
|
330
|
caller.doGetResults();
|
49
|
15
|
} else if (ServiceEnumeration.RUN_TEST_SERVICE.equals(serviceName)) {
|
50
|
15
|
caller.doRunTest();
|
51
|
|
} else {
|
52
|
0
|
String message = "Unknown service [" + serviceName + "] in HTTP request.";
|
53
|
0
|
AbstractWebTestController.LOGGER.error(message);
|
54
|
0
|
throw new ServletException(message);
|
55
|
|
}
|
56
|
|
} catch (NoClassDefFoundError e) {
|
57
|
0
|
if (e.getMessage().startsWith("junit/framework")) {
|
58
|
0
|
String message =
|
59
|
|
"You must put the JUnit jar in your server classpath (in WEB-INF/lib for example)";
|
60
|
0
|
AbstractWebTestController.LOGGER.error(message, e);
|
61
|
0
|
throw new ServletException(message, e);
|
62
|
|
} else {
|
63
|
0
|
String message = "You are missing a jar in your classpath (class [" + e.getMessage() +
|
64
|
|
"] could not " + "be found";
|
65
|
0
|
AbstractWebTestController.LOGGER.error(message, e);
|
66
|
0
|
throw new ServletException(message, e);
|
67
|
|
}
|
68
|
|
}
|
69
|
|
}
|
70
|
|
|
71
|
|
/**
|
72
|
|
* @param theRequest the HTTP request
|
73
|
|
* @return the service name of the service to call (there are 2 services
|
74
|
|
* "do test" and "get results"), extracted from the HTTP request
|
75
|
|
* @exception ServletException if the service to execute is missing from
|
76
|
|
* the HTTP request
|
77
|
|
*/
|
78
|
675
|
private String getServiceName(HttpServletRequest theRequest) throws ServletException {
|
79
|
675
|
String queryString = theRequest.getQueryString();
|
80
|
675
|
String serviceName = ServletUtil.getQueryStringParameter(queryString, "Cactus_Service");
|
81
|
675
|
if (serviceName == null) {
|
82
|
0
|
String message =
|
83
|
|
"Missing service name parameter [Cactus_Service] in HTTP request. Received query string is ["
|
84
|
|
+ queryString + "].";
|
85
|
0
|
AbstractWebTestController.LOGGER.debug(message);
|
86
|
0
|
throw new ServletException(message);
|
87
|
|
}
|
88
|
675
|
AbstractWebTestController.LOGGER.debug("Service to call = " + serviceName);
|
89
|
675
|
return serviceName;
|
90
|
|
}
|
91
|
|
|
92
|
|
/**
|
93
|
|
* Controller that extracts the requested service from the HTTP request and
|
94
|
|
* executes the request by calling a <code>WebTestCaller</code>. There
|
95
|
|
* are 2 services available : one for executing the test and one for returning
|
96
|
|
* the test result.
|
97
|
|
*
|
98
|
|
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
99
|
|
*
|
100
|
|
* @version $Id: AbstractWebTestController.html,v 1.1 2003/04/14 12:27:31 sinisa Exp $
|
101
|
|
*/
|
102
|
675
|
public AbstractWebTestController() {
|
103
|
675
|
super();
|
104
|
|
}
|
105
|
|
/**
|
106
|
|
* Controller that extracts the requested service from the HTTP request and
|
107
|
|
* executes the request by calling a <code>WebTestCaller</code>. There
|
108
|
|
* are 2 services available : one for executing the test and one for returning
|
109
|
|
* the test result.
|
110
|
|
*
|
111
|
|
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
112
|
|
*
|
113
|
|
* @version $Id: AbstractWebTestController.html,v 1.1 2003/04/14 12:27:31 sinisa Exp $
|
114
|
|
*/
|
115
|
|
static {
|
116
|
|
/**
|
117
|
|
* The logger
|
118
|
|
*/
|
119
|
5
|
AbstractWebTestController.LOGGER = LogFactory.getLog(AbstractWebTestController.class);
|
120
|
|
}
|
121
|
|
|
122
|
|
}
|