public void doGet(HttpServletRequest theRequest,
HttpServletResponse theResponse) throws IOException, ServletException {
// Verify if a suite parameter exists
String suiteClassName = theRequest.getParameter(HTTP_SUITE_PARAM);
// Set up default Cactus System properties so that there is no need
// to have a cactus.properties file in WEB-INF/classes
setSystemProperties(theRequest);
if (suiteClassName == null)
{
throw new ServletException("Missing HTTP parameter ["
+ HTTP_SUITE_PARAM + "] in request");
}
// Get the XSL stylesheet parameter if any
String xslParam = theRequest.getParameter(HTTP_XSL_PARAM);
// Get the transform parameter if any
String transformParam = theRequest.getParameter(HTTP_TRANSFORM_PARAM);
// Get the enconding parameter, if any
String encoding = theRequest.getParameter(ENCODING_PARAM);
// Run the tests
String xml = run(suiteClassName, xslParam, encoding);
// Check if we should do the transformation server side
if ((transformParam != null) && (transformer != null))
{
// Transform server side
try
{
Method getContentTypeMethod =
transformer.getClass().getMethod(
"getContentType", new Class[0]);
theResponse.setContentType((String)
getContentTypeMethod.invoke(transformer, new Object[0]));
PrintWriter out = theResponse.getWriter();
Method transformMethod =
transformer.getClass().getMethod(
"transform", new Class[] {Reader.class, Writer.class});
transformMethod.invoke(transformer,
new Object[] {new StringReader(xml), out});
}
catch (Exception e)
{
throw new ServletException(
"Problem applying the XSLT transformation", e);
}
}
else
{
// Transform client side (or not at all)
theResponse.setContentType("text/xml");
PrintWriter pw = theResponse.getWriter();
pw.println(xml);
}
}
Starts the test suite passed as a HTTP parameter. |