Re: HeadMethodWebRequest problems
<[email protected]> Thu, 20 Aug 2009 13:43:13 -0500
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <047619DE22807D4192B0B9EB64E45CC12485A15689@MSGCMSV21024.ent.wfb.bank.corp> |
Sorry, a correction: my first point still stands but my second (about the listeners)
was wrong, it turns out that reset() was not clearing out the listeners, I suggest
we apply this patch (attached patch.txt):
===================================================================
--- src/com/meterware/httpunit/parsing/HTMLParserFactory.java (revision 1048)
+++ src/com/meterware/httpunit/parsing/HTMLParserFactory.java (working copy)
@@ -49,6 +49,7 @@
* Resets all settings to their default values. This includes the parser selection.
*/
public static void reset() {
+ _listeners.clear();
_preserveTagCase = false;
_returnHTMLDocument = true;
_parserWarningsEnabled = false;
Thanks,
Dan
From: [email protected] [mailto:[email protected]]
Sent: Thursday, August 20, 2009 11:33 AM
To: [email protected]; [email protected]
Subject: Re: [Httpunit-develop] HeadMethodWebRequest problems
I have another test case regarding this.
It seems that on a HEAD request you should not be calling the HTML parsers
at all. In the case below we fail because the parser is called (even though
it is called with the empty string). Also the HTMLParserListener I implemented
is outputting a ton of stuff, it looks like something somewhere is not getting
the empty string back from the HEAD request (I am not sure what at this point).
(the listener should probably have "fail" calls as well, I just wanted to see all the output).
// has to be in this package since parses aren't public classes or you have to implement all parser methods
package com.meterware.httpunit.parsing;
...
public void testHeadMethodWebRequest2() throws Exception {
defineResource( "SimplePage.html",
"<html><head><title>A Sample Page</title></head>\n" +
"<body>Hello</body></html>\n" );
HttpUnitOptions.setExceptionsThrownOnErrorStatus(true);
try {
HTMLParserFactory.setParserWarningsEnabled(true);
HTMLParserFactory.setHTMLParser(new NekoHTMLParser() {
@Override
public void parse(URL pageURL, String pageText, DocumentAdapter adapter) {
System.err.println("Parsing URL=" + pageURL + "\n" + pageText);
fail("Should not be parsing a HEAD request");
}
});
HTMLParserFactory.addHTMLParserListener(new HTMLParserListener() {
public void error(URL url, String msg, int line, int column) {
System.err.println("ERROR @url=" + url + ": (" + line + ", " + column + "):" + msg);
}
public void warning(URL url, String msg, int line, int column) {
System.err.println("WARN @url=" + url + ": (" + line + ", " + column + "):" + msg);
}
});
WebConversation wc = new WebConversation();
// create a HeadMethodWebRequest
// see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html for definition
WebRequest request = new HeadMethodWebRequest( getHostPath() + "/SimplePage.html" );
WebResponse simplePage = wc.getResponse( request );
String text=simplePage.getText();
// no body should be returned
assertEquals("",text);
} finally {
HTMLParserFactory.reset();
}
}
Thanks,
Dan
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Httpunit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/httpunit-develop
patch.txt
(text/plain, 580 B)
Index: src/com/meterware/httpunit/parsing/HTMLParserFactory.java
===================================================================
--- src/com/meterware/httpunit/parsing/HTMLParserFactory.java (revision 1048)
+++ src/com/meterware/httpunit/parsing/HTMLParserFactory.java (working copy)
@@ -49,6 +49,7 @@
* Resets all settings to their default values. This includes the parser selection.
*/
public static void reset() {
+ _listeners.clear();
_preserveTagCase = false;
_returnHTMLDocument = true;
_parserWarningsEnabled = false;