// context scope as the HTTP request will not block in some containers.
// However this will not happen because on the client side, once the
// first request is done to execute the test, all the result is read
// by the AutoReadHttpURLConnection class, thus ensuring that the
// request is fully finished and the result has been committed ...
WebTestResult result = (WebTestResult) (this.webImplicitObjects
.getServletContext().getAttribute(TEST_RESULTS));
// It can happen that the result has not been written in the Servlet
// context. This could happen for example when using a load-balancer
// which would direct the second Cactus HTTP connection to another
// instance. In that case, we throw an error.
if (result == null)
{
String message = "Error getting test result. This could happen "
+ "for example if you're using a load-balancer. Please disable "
+ "it before running Cactus tests.";
LOGGER.error(message);
throw new ServletException(message);
}
LOGGER.debug("Test Result = [" + result + "]");
// Write back the results to the outgoing stream as an XML string.
// Use UTF-8 to transfer the result back
webImplicitObjects.getHttpServletResponse().setContentType(
"text/xml; charset=UTF-8");
try
{
Writer writer = getResponseWriter();
writer.write(result.toXml());
writer.close();
}
catch (IOException e)
{
String message = "Error writing WebTestResult instance to output "