+
+ /**
+ * Gets the result of the HTTP method as an XHTML document.
+ *
+ * @param aMethod
+ * Method to invoke.
+ * @return XHTML as a byte array.
+ * @throws IOException
+ * In case of problems obtaining the XHTML.
+ */
+ private byte[] getXhtml(HttpMethod aMethod) throws IOException {
+ // Transform the HTML into wellformed XML.
+ Tidy tidy = new Tidy();
+ tidy.setXHTML(true);
+ tidy.setQuiet(true);
+ tidy.setShowWarnings(false);
+
+ // We write the jtidy output to XML since the DOM tree it produces is
+ // not namespace aware and namespace awareness is required by XSLT.
+ // An alternative is to configure namespace awareness of the XML parser
+ // in a system wide way.
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ Document w3cDoc = tidy.parseDOM(aMethod.getResponseBodyAsStream(), os);
+ DomUtils.removeDuplicateAttributes(w3cDoc);
+ LOG.debug("Content of response is \n" + os.toString());
+
+ ByteArrayOutputStream xhtml = new ByteArrayOutputStream();
+ XMLSerializer serializer = new XMLSerializer(xhtml, new OutputFormat());
+ serializer.serialize(w3cDoc);
+ xhtml.flush();
+
+ return xhtml.toByteArray();
+ }
+
+ /**
+ * Sleeps for a random time but no more than the maximum delay.
+ *
+ */
+ private void delay() {