public void handleRequest(ImplicitObjects theObjects) throws ServletException {
WebImplicitObjects webImplicitObjects = (WebImplicitObjects) theObjects;
// If the Cactus user has forgotten to put a needed jar on the server
// classpath (i.e. in WEB-INF/lib), then the servlet engine Webapp
// class loader will throw a NoClassDefFoundError exception. As this
// method is the entry point of the webapp, we'll catch all
// NoClassDefFoundError exceptions and report a nice error message
// for the user so that he knows he has forgotten to put a jar in the
// classpath. If we don't do this, the error will be trapped by the
// container and may not result in an ... err ... understandable error
// message (like in Tomcat) ...
try
{
String serviceName =
getServiceName(webImplicitObjects.getHttpServletRequest());
AbstractWebTestCaller caller = getTestCaller(webImplicitObjects);
// TODO: will need a factory here real soon...
ServiceEnumeration service =
ServiceEnumeration.valueOf(serviceName);
// Is it the call test method service ?
if (service == ServiceEnumeration.CALL_TEST_SERVICE)
{
caller.doTest();
}
// Is it the get test results service ?
else if (service == ServiceEnumeration.GET_RESULTS_SERVICE)
{
caller.doGetResults();
}
// Is it the test connection service ?
// This service is only used to verify that connection between
// client and server is working fine
else if (service == ServiceEnumeration.RUN_TEST_SERVICE)
{
caller.doRunTest();
}
// Is it the service to create an HTTP session?
else if (service == ServiceEnumeration.CREATE_SESSION_SERVICE)
{
caller.doCreateSession();
}
else if (service == ServiceEnumeration.GET_VERSION_SERVICE)
{
caller.doGetVersion();
}
else
{
String message = "Unknown service [" + serviceName
+ "] in HTTP request.";
LOGGER.error(message);
throw new ServletException(message);
}
}
catch (NoClassDefFoundError e)
{
// try to display messages as descriptive as possible !
if (e.getMessage().startsWith("junit/framework"))
{
String message = "You must put the JUnit jar in "
+ "your server classpath (in WEB-INF/lib for example)";
LOGGER.error(message, e);
throw new ServletException(message, e);
}
else
{
String message = "You are missing a jar in your "
+ "classpath (class [" + e.getMessage()
+ "] could not " + "be found";
LOGGER.error(message, e);
throw new ServletException(message, e);
}
}
}
Handles the incoming request by extracting the requested service and
calling the correct method on a WebTestCaller. |