httpunit-commit Mailing List for httpunit (Page 73)
Brought to you by:
russgold
You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(5) |
Sep
(31) |
Oct
(39) |
Nov
(18) |
Dec
(6) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(8) |
Feb
(5) |
Mar
(8) |
Apr
(25) |
May
(20) |
Jun
(23) |
Jul
(28) |
Aug
(10) |
Sep
(3) |
Oct
(32) |
Nov
(61) |
Dec
(24) |
2002 |
Jan
(50) |
Feb
(34) |
Mar
(35) |
Apr
(3) |
May
(25) |
Jun
(25) |
Jul
(30) |
Aug
(146) |
Sep
(49) |
Oct
(156) |
Nov
(121) |
Dec
(54) |
2003 |
Jan
(12) |
Feb
(79) |
Mar
(88) |
Apr
(26) |
May
(67) |
Jun
(29) |
Jul
(8) |
Aug
(16) |
Sep
(20) |
Oct
(17) |
Nov
|
Dec
(5) |
2004 |
Jan
|
Feb
(40) |
Mar
(30) |
Apr
(5) |
May
|
Jun
(83) |
Jul
(34) |
Aug
(20) |
Sep
(44) |
Oct
(46) |
Nov
|
Dec
(14) |
2005 |
Jan
(4) |
Feb
|
Mar
(5) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
(1) |
2006 |
Jan
|
Feb
|
Mar
(26) |
Apr
(8) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(5) |
Nov
|
Dec
|
2008 |
Jan
|
Feb
|
Mar
|
Apr
(36) |
May
(38) |
Jun
(1) |
Jul
(1) |
Aug
|
Sep
(4) |
Oct
|
Nov
(18) |
Dec
(4) |
2009 |
Jan
|
Feb
(2) |
Mar
(3) |
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
(35) |
Sep
(1) |
Oct
|
Nov
|
Dec
(1) |
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
(9) |
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(21) |
Oct
(18) |
Nov
(1) |
Dec
|
From: Russell G. <rus...@us...> - 2001-07-24 15:28:06
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv7957/doc Modified Files: faq.html Log Message: Updated FAQ to refer to parameters Index: faq.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/faq.html,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- faq.html 2001/06/18 20:21:30 1.8 +++ faq.html 2001/07/24 15:28:03 1.9 @@ -13,7 +13,7 @@ <LI><A HREF="#proxy">Can I use HttpUnit through a proxy server?</A></LI> <LI><A HREF="#charset">Why isn't HttpUnit handling my non-English pages?</A></LI> <LI><A HREF="#utf8">HttpUnit fails with an IllegalArgumentException: sun.io.CharToByteUTF-8, what do I do?</A></LI> -<LI><A HREF="#buttons">HttpUnit is not finding the buttons in my forms. What is wrong?</A></LI> +<LI><A HREF="#buttons">HttpUnit is not finding the buttons and parameters in my forms. What is wrong?</A></LI> <LI><A HREF="#reload">Why do I get java.lang.IllegalAccessError when calling getResponse()?</A></LI> </OL> @@ -72,12 +72,12 @@ encoding name in its JDK 1.1.x implementations, so this code fails under JDK 1.1. This has been corrected in HttpUnit 1.2.2. -<A NAME="buttons"><H2>HttpUnit is not finding the buttons in my forms. What is wrong?</H2></A> +<A NAME="buttons"><H2>HttpUnit is not finding the buttons and parameters in my forms. What is wrong?</H2></A> This often happens when your HTML is not valid. Most browsers are extremely forgiving of bad HTML; however, JTidy (the HTML parser used by HttpUnit) is not. It expects tags to be nested according to the HTML specification and will reject any that are not. JTidy can display error messages to tell you what is wrong. To see them, call <code>HttpUnitOptions.setParserWarningsEnabled( true )</code> before retrieving your HTML page. -Once you have corrected any errors, HttpUnit should see your form buttons. +Once you have corrected any errors, HttpUnit should see your form buttons and parameters. <A NAME="#reload"><H2>Why do I get java.lang.IllegalAccessError when calling getResponse()?</H2></A> This happens when you use HttpUnit and JTidy with one of the JUnit graphical test runners, which reloads |
From: Russell G. <rus...@us...> - 2001-07-23 03:05:33
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv15976/src/com/meterware/httpunit Modified Files: WebResponse.java Log Message: From David Karr: corrected handling of 3xx responses Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.40 retrieving revision 1.41 diff -u -r1.40 -r1.41 --- WebResponse.java 2001/07/20 21:04:21 1.40 +++ WebResponse.java 2001/07/23 03:05:30 1.41 @@ -220,6 +220,7 @@ * Returns a buffered input stream for reading the contents of this reply. **/ public InputStream getInputStream() throws IOException { + if (_inputStream == null) _inputStream = new ByteArrayInputStream( new byte[0] ); return _inputStream; } @@ -482,7 +483,7 @@ if (_responseText != null) throw new IllegalStateException( "May only invoke loadResponseText once" ); _responseText = ""; - InputStream inputStream = _inputStream; + InputStream inputStream = getInputStream(); try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[8 * 1024]; |
From: Russell G. <rus...@us...> - 2001-07-23 03:05:33
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv15976/test/com/meterware/httpunit Modified Files: PseudoServerTest.java Log Message: From David Karr: corrected handling of 3xx responses Index: PseudoServerTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServerTest.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- PseudoServerTest.java 2001/07/17 12:50:47 1.14 +++ PseudoServerTest.java 2001/07/23 03:05:30 1.15 @@ -76,7 +76,25 @@ } - public void notestInternalErrorException() throws Exception { + public void testNotModifiedResponse() throws Exception { + PseudoServer ps = new PseudoServer(); + ps.setErrorResource( "error.htm", 304, "Not Modified" ); + int port = ps.getConnectedPort(); + + try { + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + "/error.htm" ); + WebResponse response = wc.getResponse( request ); + assertEquals( "Response code", 304, response.getResponseCode() ); + response.getText(); + response.getInputStream().read(); + } finally { + ps.shutDown(); + } + } + + + public void testInternalErrorException() throws Exception { PseudoServer ps = new PseudoServer(); ps.setErrorResource( "error.htt", 501, "Internal error" ); int port = ps.getConnectedPort(); |
From: Russell G. <rus...@us...> - 2001-07-23 03:05:33
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv15976/doc Modified Files: release_notes.txt Log Message: From David Karr: corrected handling of 3xx responses Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.45 retrieving revision 1.46 diff -u -r1.45 -r1.46 --- release_notes.txt 2001/07/20 21:04:21 1.45 +++ release_notes.txt 2001/07/23 03:05:30 1.46 @@ -14,9 +14,13 @@ 20-Jul-2001 Acknowledgements: Thanks to Drew Varner for more sophisticated cookie handling, including Set-Cookie2 code + Thanks to David Karr for pointing out the problem with status code 3xx responses and + suggesting a fix for it. Problems corrected: 1. cookies with embedded commas and quotes are now handled + 2. Status code 3xx responses no longer result in a null pointer exception when + invoking getText or reading the input stream. Additions: 1. The Set_Cookie2 header is now handled |
From: Russell G. <rus...@us...> - 2001-07-20 21:04:23
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv25670/src/com/meterware/httpunit Modified Files: WebResponse.java Log Message: From Drew Varner: improved cookie handling Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- WebResponse.java 2001/07/19 17:43:50 1.39 +++ WebResponse.java 2001/07/20 21:04:21 1.40 @@ -4,12 +4,12 @@ * * Copyright (c) 2000-2001, Russell Gold * -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -* documentation files (the "Software"), to deal in the Software without restriction, including without limitation +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +* documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * -* The above copyright notice and this permission notice shall be included in all copies or substantial portions +* The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO @@ -25,6 +25,7 @@ import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.IOException; +import java.io.StreamTokenizer; import java.io.StringReader; import java.io.UnsupportedEncodingException; @@ -40,7 +41,6 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; -import java.util.StringTokenizer; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -50,11 +50,33 @@ import org.xml.sax.SAXException; /** - * A response from a web server to a web request. + * A response to a web request from a web server. + * + * @author <a href="mailto:rus...@ac...">Russell Gold</a> + * @author <a href="mailto:DRE...@or...">Drew Varner</a> **/ abstract public class WebResponse implements HTMLSegment { + /** + * A version flag indicating a cookie is based on the + * Internet Engineering Task Force's (IETF) + * <a href="http://www.ietf.org/rfc/rfc2109.txt">RFC 2109</a> + * + * <br /> + * These cookies come from the <code>Set-Cookie:</code> header + **/ + public static final int IETF_RFC2109 = 0; + + /** + * A version flag indicating a cookie is based on the + * Internet Engineering Task Force's (IETF) + * <a href="http://www.ietf.org/rfc/rfc2965.txt">RFC 2965</a> + * + * <br /> + * These cookies come from the <code>Set-Cookie2:</code> header + **/ + public static final int IETF_RFC2965 = 1; /** * Returns a web response built from a URL connection. Provided to allow @@ -108,8 +130,8 @@ /** - * Returns the delay before normally following the request to refresh this page, if any. - * This request will be defined by a <meta> tag in the header. If no tag exists, + * Returns the delay before normally following the request to refresh this page, if any. + * This request will be defined by a <meta> tag in the header. If no tag exists, * will return zero. **/ public int getRefreshDelay() { @@ -178,12 +200,12 @@ /** * Returns the value for the specified header field. If no such field is defined, will return null. - * No more than one header may be defined for each key. + * No more than one header may be defined for each key. **/ abstract public String getHeaderField( String fieldName ); - - + + /** * Returns the text of the response (excluding headers) as a string. Use this method in preference to 'toString' * which may be used to represent internal state of this object. @@ -192,7 +214,7 @@ if (_responseText == null) loadResponseText(); return _responseText; } - + /** * Returns a buffered input stream for reading the contents of this reply. @@ -201,7 +223,7 @@ return _inputStream; } - + /** * Returns the names of the frames found in the page in the order in which they appear. * @exception SAXException thrown if there is an error parsing this response @@ -307,8 +329,8 @@ public WebTable getTableStartingWith( String text ) throws SAXException { return getReceivedPage().getTableStartingWith( text ); } - - + + /** * Returns the first table in the response which has the specified text as a prefix of the text of * its first non-blank row and non-blank column. Will recurse into any nested tables, as needed. @@ -322,7 +344,7 @@ /** - * Returns the first table in the response which has the specified text as its summary attribute. + * Returns the first table in the response which has the specified text as its summary attribute. * Will recurse into any nested tables, as needed. * Case is ignored. * @exception SAXException thrown if there is an error parsing the response. @@ -334,7 +356,7 @@ /** - * Returns the first table in the response which has the specified text as its ID attribute. + * Returns the first table in the response which has the specified text as its ID attribute. * Will recurse into any nested tables, as needed. * Case is ignored. * @exception SAXException thrown if there is an error parsing the response. @@ -394,7 +416,7 @@ _contentHeader = value; } - + //------------------------------------------ package members ------------------------------------------------ @@ -473,7 +495,7 @@ byte[] bytes = outputStream.toByteArray(); readMetaTags( bytes ); _responseText = new String( bytes, getCharacterSet() ); - _inputStream = new ByteArrayInputStream( bytes ); + _inputStream = new ByteArrayInputStream( bytes ); } finally { inputStream.close(); } @@ -506,42 +528,167 @@ } } - - private Hashtable getNewCookies() { - if (_newCookies == null) { - _newCookies = new Hashtable(); - String cookieHeader = getHeaderField( "Set-Cookie" ); - if (cookieHeader != null) { - StringTokenizer st = new StringTokenizer( cookieHeader, "," ); - while (st.hasMoreTokens()) recognizeOneCookie( st.nextToken() ); - } - } - return _newCookies; - } + /** + * Parses cookies from the <code>Set-Cookie</code> and the + * <code>Set-Cookie2</code> header fields. + * <p> + * This class does not strictly follow the specifications, but + * attempts to imitate the behavior of popular browsers. Specifically, + * this method allows cookie values to contain commas, which the + * Netscape standard does not allow for. + * </p><p> + * This method does not parse path,domain,expires or secure information + * about the cookie.</p> + * + * @returns Hashtable a <code>Hashtable</code> of where the name of the + * cookie is the key and the value of the cookie is + * the value + */ + private Hashtable getNewCookies() { + if (_newCookies == null) { + _newCookies = new Hashtable(); + } + String cookieHeader = getHeaderField( "Set-Cookie" ); + if (cookieHeader != null) { + processCookieTokens( getCookieTokens(cookieHeader),IETF_RFC2109 ); + } + String cookieHeader2 = getHeaderField( "Set-Cookie2" ); + if (cookieHeader2 != null) { + processCookieTokens( getCookieTokens(cookieHeader2),IETF_RFC2965 ); + } + return _newCookies; + } + + + private void processCookieTokens(Vector tokens, + int version) { + // holds tokens that should be part of the value of + // the first token before it that contains an + // equals sign (=) + String tokensToAdd = ""; + int numTokens = tokens.size(); + for (int i=numTokens - 1; i >= 0; i--) { + String token = (String) tokens.get(i); + int equalsIndex = token.indexOf('='); + + // if this token has an equals sign (=) in it + if (equalsIndex != -1) { + String name = token.substring(0,equalsIndex).trim(); + // make sure we aren't using a cookie's attribute other + // than the name/value pair + if ( !isStringCookieAttribute(name,version) ) { + String value = token.substring(equalsIndex+1).trim(); + _newCookies.put(name,value+tokensToAdd); + } + tokensToAdd = ""; + } + + else { + // make sure we aren't counting a one word reserved + // cookie attribute value + if ( !isTokenReservedWord(token,version) ) { + tokensToAdd = token + tokensToAdd; + String preceedingToken = (String) tokens.get(i - 1); + char lastChar = preceedingToken.charAt(preceedingToken.length()-1); + if (lastChar != '=') { + tokensToAdd = ","+ tokensToAdd; + } + } + // the token is a secure or discard flag for the cookie + else { + // just to be safe we should clear the tokens + // to append to the value of the cookie + tokensToAdd = ""; + } + } + } + } + + + /** + * Tokenizes a cookie header and returns the tokens in a + * <code>Vector</code>. + **/ + private Vector getCookieTokens(String cookieHeader) { + StringReader sr = new StringReader(cookieHeader); + StreamTokenizer st = new StreamTokenizer(sr); + Vector tokens = new Vector(); + + // clear syntax tables of the StreamTokenizer + st.resetSyntax(); + + // set all characters as word characters + st.wordChars(0,Character.MAX_VALUE); + + // set up characters for quoting + st.quoteChar(34); //double quotes + st.quoteChar(39); //single quotes + + // set up characters to separate tokens + st.whitespaceChars(59,59); //semicolon + st.whitespaceChars(44,44); //comma + + try { + while (st.nextToken() != StreamTokenizer.TT_EOF) { + tokens.add( st.sval.trim() ); + } + } + catch (IOException ioe) { + // this will never happen with a StringReader + } + sr.close(); + return tokens; + } + + + private boolean isStringCookieAttribute(String string, + int version) { + String stringLowercase = string.toLowerCase(); + if (version == IETF_RFC2109) { + if ( stringLowercase.equals("path") || + stringLowercase.equals("domain") || + stringLowercase.equals("expires") || + stringLowercase.equals("comment") || + stringLowercase.equals("max-age") || + stringLowercase.equals("version") ) { + return true; + } + } + else if (version == IETF_RFC2965) { + if ( stringLowercase.equals("path") || + stringLowercase.equals("domain") || + stringLowercase.equals("comment") || + stringLowercase.equals("commenturl") || + stringLowercase.equals("max-age") || + stringLowercase.equals("version") || + stringLowercase.equals("$version") || + stringLowercase.equals("port") ) { + return true; + } + } + return false; + } + + + private boolean isTokenReservedWord(String token, + int version) { + String tokenLowercase = token.toLowerCase(); + if (version == IETF_RFC2109) { + if ( tokenLowercase.equals("secure") ) { + return true; + } + } + else if (version == IETF_RFC2965) { + if ( tokenLowercase.equals("discard") || + tokenLowercase.equals("secure") ) { + return true; + } + } + return false; + } - private void recognizeOneCookie( String cookieSpec ) { - StringTokenizer st = new StringTokenizer( cookieSpec, ";" ); - String token = st.nextToken().trim(); - int i = token.indexOf("="); - if (i > -1) { - String name = token.substring(0, i).trim(); - String value = stripQuote( token.substring( i+1, token.length() ).trim() ); - _newCookies.put( name, value ); - } - } - - - private String stripQuote( String value ) { - if (((value.startsWith("\"")) && (value.endsWith("\""))) || - ((value.startsWith("'") && (value.endsWith("'"))))) { - return value.substring(1,value.length()-1); - } - return value; - } - - private void readContentTypeHeader() { String contentHeader = (_contentHeader != null) ? _contentHeader : getHeaderField( "Content-type" ); @@ -756,8 +903,8 @@ return null; } } - - + + /** * Returns the text of the response (excluding headers) as a string. Use this method in preference to 'toString' * which may be used to represent internal state of this object. @@ -773,13 +920,13 @@ public InputStream getInputStream() { return new ByteArrayInputStream( _responseText.getBytes() ); } + - public String toString() { - return "DefaultWebResponse [" + _responseText + "]"; + return "DefaultWebResponse [" + _responseText + "]"; } - - + + private String _responseText; } |
From: Russell G. <rus...@us...> - 2001-07-20 21:04:23
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv25670/doc Modified Files: release_notes.txt Log Message: From Drew Varner: improved cookie handling Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.44 retrieving revision 1.45 diff -u -r1.44 -r1.45 --- release_notes.txt 2001/07/19 17:43:50 1.44 +++ release_notes.txt 2001/07/20 21:04:21 1.45 @@ -11,6 +11,16 @@ Revision History: +20-Jul-2001 +Acknowledgements: + Thanks to Drew Varner for more sophisticated cookie handling, including Set-Cookie2 code + +Problems corrected: + 1. cookies with embedded commas and quotes are now handled + +Additions: + 1. The Set_Cookie2 header is now handled + 19-Jul-2001 Additions: 1. Added getHeaderFieldNames to WebResponse |
From: Russell G. <rus...@us...> - 2001-07-19 17:43:53
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv26541/src/com/meterware/httpunit Modified Files: HttpWebResponse.java WebResponse.java Log Message: provide access to response header names Index: HttpWebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- HttpWebResponse.java 2001/07/17 12:50:47 1.13 +++ HttpWebResponse.java 2001/07/19 17:43:50 1.14 @@ -27,8 +27,10 @@ import java.net.URL; import java.net.URLConnection; +import java.util.Enumeration; import java.util.Hashtable; import java.util.StringTokenizer; +import java.util.Vector; /** @@ -62,6 +64,17 @@ **/ public int getResponseCode() { return _responseCode; + } + + + public String[] getHeaderFieldNames() { + Vector names = new Vector(); + for (Enumeration e = _headers.keys(); e.hasMoreElements();) { + names.addElement( e.nextElement() ); + } + String[] result = new String[ names.size() ]; + names.copyInto( result ); + return result; } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- WebResponse.java 2001/07/06 17:11:04 1.38 +++ WebResponse.java 2001/07/19 17:43:50 1.39 @@ -169,6 +169,12 @@ } + /** + * Returns the names of the header fields found in the response. + **/ + abstract + public String[] getHeaderFieldNames(); + /** * Returns the value for the specified header field. If no such field is defined, will return null. @@ -732,6 +738,11 @@ **/ public int getResponseCode() { return HttpURLConnection.HTTP_OK; + } + + + public String[] getHeaderFieldNames() { + return new String[] { "Content-type" }; } |
From: Russell G. <rus...@us...> - 2001-07-19 17:43:53
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv26541/src/com/meterware/servletunit Modified Files: ServletUnitHttpResponse.java ServletUnitWebResponse.java Log Message: provide access to response header names Index: ServletUnitHttpResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpResponse.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ServletUnitHttpResponse.java 2001/07/06 17:11:04 1.4 +++ ServletUnitHttpResponse.java 2001/07/19 17:43:50 1.5 @@ -411,6 +411,18 @@ } + public String[] getHeaderFieldNames() { + if (!_headersComplete) completeHeaders(); + Vector names = new Vector(); + for (Enumeration e = _headers.keys(); e.hasMoreElements();) { + names.addElement( e.nextElement() ); + } + String[] result = new String[ names.size() ]; + names.copyInto( result ); + return result; + } + + /** * Returns the headers defined for this response. **/ Index: ServletUnitWebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitWebResponse.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ServletUnitWebResponse.java 2001/07/06 17:11:04 1.5 +++ ServletUnitWebResponse.java 2001/07/19 17:43:50 1.6 @@ -67,6 +67,11 @@ } + public String[] getHeaderFieldNames() { + return _response.getHeaderFieldNames(); + } + + /** * Returns the value for the specified header field. If no such field is defined, will return null. **/ |
From: Russell G. <rus...@us...> - 2001-07-19 17:43:53
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv26541/doc Modified Files: release_notes.txt Log Message: provide access to response header names Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.43 retrieving revision 1.44 diff -u -r1.43 -r1.44 --- release_notes.txt 2001/07/17 12:50:47 1.43 +++ release_notes.txt 2001/07/19 17:43:50 1.44 @@ -11,6 +11,10 @@ Revision History: +19-Jul-2001 +Additions: + 1. Added getHeaderFieldNames to WebResponse + 16-Jul-2001 Acknowledgements: Thanks to Chris Stevenson for identifying a problem with forms lacking an action @@ -21,7 +25,7 @@ calling getResponse. This will prevent HttpUnit from throwing an exception in such cases. You can still check the status of the response by calling WebResponse.getStatusCode() - + Problems corrected: 1. Forms with no action now default to the originating page |
From: Russell G. <rus...@us...> - 2001-07-17 12:50:50
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv16845/test/com/meterware/httpunit Modified Files: FormSubmitTest.java HttpUnitTest.java PseudoServer.java PseudoServerTest.java WebResource.java Log Message: Allow access to pages with non-OK status Index: FormSubmitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormSubmitTest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- FormSubmitTest.java 2001/05/21 21:04:29 1.8 +++ FormSubmitTest.java 2001/07/17 12:50:47 1.9 @@ -303,6 +303,20 @@ } + public void testNoActionSupplied() throws Exception { + defineWebPage( "abc/form", "<form name=\"test\">" + + " <input type=\"text\" name=\"aTextField\">" + + " <input type=\"submit\" name=\"apply\" value=\"Apply\">" + + "</form>" ); + + WebResponse wr = _wc.getResponse( getHostPath() + "/abc/form.html" ); + WebForm form = wr.getForms()[0]; + WebRequest req = form.getRequest( "apply" ); + req.setParameter( "aTextField", "test" ); + assertEqualQueries( getHostPath() + "/abc/form.html?apply=Apply&aTextField=test", + req.getURL().toExternalForm() ); + } + //---------------------------------------------- private members ------------------------------------------------ Index: HttpUnitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitTest.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- HttpUnitTest.java 2001/07/02 13:05:56 1.13 +++ HttpUnitTest.java 2001/07/17 12:50:47 1.14 @@ -43,6 +43,7 @@ public void setUp() throws Exception { _server = new PseudoServer(); + HttpUnitOptions.reset(); _hostPath = "http://localhost:" + _server.getConnectedPort(); } Index: PseudoServer.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServer.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- PseudoServer.java 2001/06/11 21:21:09 1.14 +++ PseudoServer.java 2001/07/17 12:50:47 1.15 @@ -176,9 +176,10 @@ WebResource resource = getResource( request ); if (resource == null) { response.setResponse( HttpURLConnection.HTTP_NOT_FOUND, "unable to find " + request.getURI() ); - } else if (resource.getResponseCode() != HttpURLConnection.HTTP_OK) { - response.setResponse( resource.getResponseCode(), resource.getResponseText() ); } else { + if (resource.getResponseCode() != HttpURLConnection.HTTP_OK) { + response.setResponse( resource.getResponseCode(), "" ); + } response.addHeader( "Content-type: " + resource.getContentType() + resource.getCharacterSetParameter() ); String[] headers = resource.getHeaders(); for (int i = 0; i < headers.length; i++) { Index: PseudoServerTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServerTest.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- PseudoServerTest.java 2001/06/11 21:21:09 1.13 +++ PseudoServerTest.java 2001/07/17 12:50:47 1.14 @@ -32,7 +32,7 @@ /** * Tests the basic authentication. **/ -public class PseudoServerTest extends TestCase { +public class PseudoServerTest extends HttpUnitTest { public static void main(String args[]) { junit.textui.TestRunner.run( suite() ); @@ -76,7 +76,7 @@ } - public void testInternalError() throws Exception { + public void notestInternalErrorException() throws Exception { PseudoServer ps = new PseudoServer(); ps.setErrorResource( "error.htt", 501, "Internal error" ); int port = ps.getConnectedPort(); @@ -91,6 +91,20 @@ } finally { ps.shutDown(); } + } + + + public void testInternalErrorDisplay() throws Exception { + PseudoServer ps = new PseudoServer(); + ps.setErrorResource( "error.htm", 501, "Internal error" ); + int port = ps.getConnectedPort(); + + HttpUnitOptions.setExceptionsThrownOnErrorStatus( false ); + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + "/error.htm" ); + WebResponse response = wc.getResponse( request ); + assertEquals( "Response code", 501, response.getResponseCode() ); + assertEquals( "Message contents", "Internal error", response.getText().trim() ); } Index: WebResource.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebResource.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- WebResource.java 2001/06/11 21:21:09 1.4 +++ WebResource.java 2001/07/17 12:50:47 1.5 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000, Russell Gold +* Copyright (c) 2000-2001, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -46,9 +46,8 @@ } - WebResource( int responseCode, String responseText ) { - this( "", DEFAULT_CONTENT_TYPE, responseCode ); - _responseText = responseText; + WebResource( int responseCode, String contents ) { + this( contents, DEFAULT_CONTENT_TYPE, responseCode ); } @@ -125,10 +124,6 @@ return _responseCode; } - String getResponseText() { - return _responseText; - } - public String toString() { return "WebResource [code=" + _responseCode + "; type = " + _contentType @@ -149,8 +144,7 @@ private int _responseCode; private boolean _sendCharacterSet; - private String _responseText = ""; - private String _contentType; + private String _contentType = DEFAULT_CONTENT_TYPE; private String _characterSet = DEFAULT_CHARACTER_SET; private Vector _headers = new Vector(); } |
From: Russell G. <rus...@us...> - 2001-07-17 12:50:50
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv16845/src/com/meterware/httpunit Modified Files: HttpUnitOptions.java HttpWebResponse.java WebClient.java Log Message: Allow access to pages with non-OK status Index: HttpUnitOptions.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- HttpUnitOptions.java 2001/07/02 13:05:56 1.7 +++ HttpUnitOptions.java 2001/07/17 12:50:47 1.8 @@ -64,6 +64,23 @@ /** + * If true, WebClient.getResponse throws an exception when it receives an error status. + * Defaults to true. + **/ + public static void setExceptionsThrownOnErrorStatus( boolean enabled ) { + _exceptionsOnErrorStatus = enabled; + } + + + /** + * Returns true if WebClient.getResponse throws exceptions when detected an error status. + **/ + public static boolean getExceptionsThrownOnErrorStatus() { + return _exceptionsOnErrorStatus; + } + + + /** * If true, tells the parser to display warning messages. The default is false (warnings are not shown). **/ public static void setParserWarningsEnabled( boolean enabled ) { @@ -179,12 +196,30 @@ } +//------------------------------ package methods ---------------------------------------- + + + static void reset() { + _parserWarningsEnabled = false; + _exceptionsOnErrorStatus = true; + _parameterValuesValidated = true; + _imagesTreatedAsAltText = false; + _loggingHttpHeaders = false; + _matchesIgnoreCase = true; + _autoRefresh = false; + _redirectDelay = 0; + _characterSet = DEFAULT_CHARACTER_SET; + } + + //--------------------------------- private members -------------------------------------- private static String DEFAULT_CHARACTER_SET = "iso-8859-1"; private static boolean _parserWarningsEnabled; + + private static boolean _exceptionsOnErrorStatus = true; private static boolean _parameterValuesValidated = true; Index: HttpWebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- HttpWebResponse.java 2001/07/06 17:11:04 1.12 +++ HttpWebResponse.java 2001/07/17 12:50:47 1.13 @@ -50,7 +50,7 @@ readHeaders( connection ); /** make sure that any IO exception for HTML received page happens here, not later. **/ - if (_responseCode == HttpURLConnection.HTTP_OK) { + if (_responseCode == HttpURLConnection.HTTP_OK || !HttpUnitOptions.getExceptionsThrownOnErrorStatus()) { defineRawInputStream( new BufferedInputStream( connection.getInputStream() ) ); if (getContentType().startsWith( "text" )) loadResponseText(); } Index: WebClient.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- WebClient.java 2001/07/02 13:05:56 1.7 +++ WebClient.java 2001/07/17 12:50:47 1.8 @@ -254,6 +254,7 @@ private void validateHeaders( WebResponse response ) throws HttpException, IOException { if (response.getHeaderField( "WWW-Authenticate" ) != null) { throw new AuthorizationRequiredException( response.getHeaderField( "WWW-Authenticate" ) ); + } else if (!HttpUnitOptions.getExceptionsThrownOnErrorStatus()) { } else if (response.getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR) { throw new HttpInternalErrorException( response.getURL().toExternalForm() ); } else if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { |
From: Russell G. <rus...@us...> - 2001-07-17 12:50:50
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv16845/doc Modified Files: release_notes.txt todo.txt Log Message: Allow access to pages with non-OK status Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- release_notes.txt 2001/07/06 17:11:04 1.42 +++ release_notes.txt 2001/07/17 12:50:47 1.43 @@ -11,7 +11,21 @@ Revision History: - 6-Jul-2001 +16-Jul-2001 +Acknowledgements: + Thanks to Chris Stevenson for identifying a problem with forms lacking an action + +Additions: + 1. It is now possible to see the response accompanying an error status by + calling HttpUnitOptions.setExceptionsThrownOnErrorStatus( false ) before + calling getResponse. This will prevent HttpUnit from throwing an exception + in such cases. You can still check the status of the response by calling + WebResponse.getStatusCode() + +Problems corrected: + 1. Forms with no action now default to the originating page + + 6-Jul-2001 1.2.6 Acknowledgements: Thanks to Marcos Tarruella for adding a test case for the Base64 class Index: todo.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/todo.txt,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- todo.txt 2001/07/02 13:05:56 1.14 +++ todo.txt 2001/07/17 12:50:47 1.15 @@ -1,3 +1,9 @@ +High priority: +o Support selection of input stream for file upload. Will require file 'name' + and mime type as well as input stream +o Support image maps + +Medium priority: o Support optional tags which hide their contents (as in IFRAME, OBJECT, etc.) o Support IFRAME tag o Support reset button detection @@ -8,9 +14,9 @@ Possibles: o replace JTidy with a simpler custom parser o support JavaScript +o support in-container testing, probably through integration with Cactus Low priority: - o history on web conversation o Support digest HTTP Authentication |
From: Russell G. <rus...@us...> - 2001-07-17 12:50:15
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv16631/src/com/meterware/httpunit Modified Files: WebForm.java Log Message: Support forms with no explicit action Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- WebForm.java 2001/05/21 21:04:29 1.22 +++ WebForm.java 2001/07/17 12:50:12 1.23 @@ -238,6 +238,10 @@ NamedNodeMap nnm = _node.getAttributes(); String action = getValue( nnm.getNamedItem( "action" ) ); + if (action.trim().length() == 0) { + action = this._baseURL.getFile(); + } + WebRequest result; if (getValue( nnm.getNamedItem( "method" ) ).equalsIgnoreCase( "post" )) { |
From: Russell G. <rus...@us...> - 2001-07-06 17:11:07
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv3916/test/com/meterware/servletunit Modified Files: HttpServletResponseTest.java Log Message: Release to enable access from Cactus Index: HttpServletResponseTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/HttpServletResponseTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- HttpServletResponseTest.java 2000/11/21 20:44:59 1.1 +++ HttpServletResponseTest.java 2001/07/06 17:11:04 1.2 @@ -24,7 +24,7 @@ import java.util.Enumeration; import java.util.Vector; -import javax.servlet.ServletException; +import javax.servlet.*; import javax.servlet.http.*; import junit.framework.Test; @@ -71,6 +71,59 @@ assertEquals( "Status code", HttpServletResponse.SC_OK, response.getResponseCode() ); assertEquals( "Content type", "text/html", response.getContentType() ); assertEquals( "Title", "Sample Page", response.getTitle() ); + } + + + public void testEncoding() throws Exception { + String hebrewTitle = "\u05d0\u05d1\u05d2\u05d3"; + String page = "<html><head><title>" + hebrewTitle + "</title></head>\n" + + "<body>This has no data\n" + + "</body></html>\n"; + ServletUnitHttpResponse servletResponse = new ServletUnitHttpResponse(); + servletResponse.setContentType( "text/html; charset=iso-8859-8" ); + PrintWriter pw = servletResponse.getWriter(); + pw.print( page ); + pw.close(); + + WebResponse response = new ServletUnitWebResponse( "_self", null, servletResponse ); + assertEquals( "Character set", "iso-8859-8", response.getCharacterSet() ); + assertEquals( "Title", hebrewTitle, response.getTitle() ); + } + + + public void testStreamResponse() throws Exception { + ServletUnitHttpResponse servletResponse = new ServletUnitHttpResponse(); + servletResponse.setContentType( "text/html" ); + ServletOutputStream sos = servletResponse.getOutputStream(); + sos.println( "<html><head><title>Sample Page</title></head><body></body></html>" ); + + WebResponse response = new ServletUnitWebResponse( "_self", null, servletResponse ); + assertEquals( "Status code", HttpServletResponse.SC_OK, response.getResponseCode() ); + assertEquals( "Content type", "text/html", response.getContentType() ); + assertEquals( "Title", "Sample Page", response.getTitle() ); + } + + + public void testStreamWriterAfterOutputStream() throws Exception { + ServletUnitHttpResponse servletResponse = new ServletUnitHttpResponse(); + servletResponse.setContentType( "text/html" ); + ServletOutputStream sos = servletResponse.getOutputStream(); + try { + servletResponse.getWriter(); + fail( "Should have thrown IllegalStateException" ); + } catch (IllegalStateException e) { + } + } + + + public void testStreamOutputStreamAfterWriter() throws Exception { + ServletUnitHttpResponse servletResponse = new ServletUnitHttpResponse(); + servletResponse.getWriter(); + try { + servletResponse.getOutputStream(); + fail( "Should have thrown IllegalStateException" ); + } catch (IllegalStateException e) { + } } |
From: Russell G. <rus...@us...> - 2001-07-06 17:11:07
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv3916/src/com/meterware/servletunit Modified Files: ServletUnitHttpResponse.java ServletUnitWebResponse.java Log Message: Release to enable access from Cactus Index: ServletUnitHttpResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpResponse.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ServletUnitHttpResponse.java 2000/12/13 21:56:03 1.3 +++ ServletUnitHttpResponse.java 2001/07/06 17:11:04 1.4 @@ -30,6 +30,7 @@ import javax.servlet.*; import javax.servlet.http.*; +import com.meterware.httpunit.HttpUnitUtils; import com.meterware.httpunit.WebRequest; @@ -200,14 +201,9 @@ /** * Returns the name of the character set encoding used for * the MIME body sent by this response. - * - * <p>The character encoding is either the one specified in - * the content itself or another one the client understands. - * If no character encoding has been assigned, it is implicitly - * set to <i>text/plain</i>. **/ public String getCharacterEncoding() { - throw new RuntimeException( "getCharacterEncoding not implemented" ); + return _encoding; } @@ -221,7 +217,12 @@ * {@link ServletOutputStream} object to return a response. **/ public void setContentType( String type ) { - _contentType = type; + String[] typeAndEncoding = HttpUnitUtils.parseContentTypeHeader( type ); + + _contentType = typeAndEncoding[0]; + if (typeAndEncoding[1] != null) _encoding = typeAndEncoding[1]; + + setHeader( "Content-type", _contentType + "; charset=" + _encoding ); } @@ -233,7 +234,12 @@ * @exception IllegalStateException if you have already called the <code>getWriter</code> method **/ public ServletOutputStream getOutputStream() throws IOException { - throw new RuntimeException( "getOutputStream not implemented" ); + if (_writer != null) throw new IllegalStateException( "Tried to create output stream; writer already exists" ); + if (_servletStream == null) { + _outputStream = new ByteArrayOutputStream(); + _servletStream = new ServletUnitOutputStream( _outputStream ); + } + return _servletStream; } @@ -262,10 +268,11 @@ * use this method * **/ - public PrintWriter getWriter() throws IOException { + public PrintWriter getWriter() throws UnsupportedEncodingException { + if (_servletStream != null) throw new IllegalStateException( "Tried to create writer; output stream already exists" ); if (_writer == null) { - _stringWriter = new java.io.StringWriter(); - _writer = new PrintWriter( _stringWriter ); + _outputStream = new ByteArrayOutputStream(); + _writer = new PrintWriter( new OutputStreamWriter( _outputStream, getCharacterEncoding() ) ); } return _writer; } @@ -386,11 +393,12 @@ /** * Returns the contents of this response. **/ - String getContents() { - if (_stringWriter == null) { - return ""; + byte[] getContents() { + if (_outputStream == null) { + return new byte[0]; } else { - return _stringWriter.getBuffer().toString(); + if (_writer != null) _writer.flush(); + return _outputStream.toByteArray(); } } @@ -417,9 +425,13 @@ private String _contentType = "text/plain"; + private String _encoding = "us-ascii"; + private PrintWriter _writer; + + private ServletOutputStream _servletStream; - private StringWriter _stringWriter; + private ByteArrayOutputStream _outputStream; private int _status = SC_OK; @@ -432,7 +444,6 @@ private void completeHeaders() { if (_headersComplete) return; - setHeader( "Content-Type", _contentType + "; charset=us-ascii" ); addCookieHeader(); _headersComplete = true; } @@ -449,4 +460,20 @@ } setHeader( "Set-Cookie", sb.toString() ); } +} + + + +class ServletUnitOutputStream extends ServletOutputStream { + + ServletUnitOutputStream( ByteArrayOutputStream stream ) { + _stream = stream; + } + + + public void write( int aByte ) throws IOException { + _stream.write( aByte ); + } + + private ByteArrayOutputStream _stream; } Index: ServletUnitWebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitWebResponse.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ServletUnitWebResponse.java 2001/06/13 16:38:20 1.4 +++ ServletUnitWebResponse.java 2001/07/06 17:11:04 1.5 @@ -55,6 +55,7 @@ ServletUnitWebResponse( String target, URL url, HttpServletResponse response ) { super( target, url ); _response = (ServletUnitHttpResponse) response; + defineRawInputStream( new ByteArrayInputStream( _response.getContents() ) ); } @@ -73,23 +74,6 @@ return _response.getHeaderField( fieldName ); } - - /** - * Returns the text of the response (excluding headers) as a string. Use this method in preference to 'toString' - * which may be used to represent internal state of this object. - **/ - public String getText() { - return _response.getContents(); - } - - - /** - * Returns an input stream for reading the contents of this reply. - **/ - public InputStream getInputStream() throws IOException { - return new ByteArrayInputStream( getText().getBytes() ); - } - public String toString() { return "[ _response = " + _response + "]"; |
From: Russell G. <rus...@us...> - 2001-07-06 17:11:06
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv3916/src/com/meterware/httpunit Modified Files: HttpWebResponse.java WebResponse.java Added Files: HttpUnitUtils.java Log Message: Release to enable access from Cactus ***** Error reading new file[Errno 2] No such file or directory: 'HttpUnitUtils.java' Index: HttpWebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- HttpWebResponse.java 2001/07/02 13:05:56 1.11 +++ HttpWebResponse.java 2001/07/06 17:11:04 1.12 @@ -20,34 +20,39 @@ * *******************************************************************************************************************/ -import java.io.*; +import java.io.BufferedInputStream; +import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; -import java.util.Enumeration; import java.util.Hashtable; import java.util.StringTokenizer; /** * A response from a web server to an Http request. + * + * @author <a href="mailto:rus...@ac...">Russell Gold</a> **/ class HttpWebResponse extends WebResponse { /** * Constructs a response object from an input stream. + * @param target the target window or frame to which the request should be directed * @param url the url from which the response was received - * @param inputStream the input stream from which the response can be read + * @param connection the URL connection from which the response can be read **/ HttpWebResponse( String target, URL url, URLConnection connection ) throws IOException { super( target, url ); - _connection = connection; readHeaders( connection ); - if (_responseCode == HttpURLConnection.HTTP_OK && getContentType().startsWith( "text" )) { - loadResponseText( connection ); + + /** make sure that any IO exception for HTML received page happens here, not later. **/ + if (_responseCode == HttpURLConnection.HTTP_OK) { + defineRawInputStream( new BufferedInputStream( connection.getInputStream() ) ); + if (getContentType().startsWith( "text" )) loadResponseText(); } } @@ -68,75 +73,23 @@ } - /** - * Returns the text of the response (excluding headers) as a string. Use this method in preference to 'toString' - * which may be used to represent internal state of this object. - **/ - public String getText() throws IOException { - if (_responseText == null) loadResponseText( _connection ); - return _responseText; + public String toString() { + return "[headers=" + _headers + "]"; } - - /** - * Returns an input stream for reading the contents of this reply. - **/ - public InputStream getInputStream() throws IOException { - if (_responseText != null) { - return new ByteArrayInputStream( _responseText.getBytes() ); - } else { - return new BufferedInputStream( _connection.getInputStream() ); - } - } - - public String toString() { - return "[headers=" + _headers + "; ??]"; - } - -//-------------------------------------------- private members ------------------------------------------------ +//------------------------------------- private members ------------------------------------- final private static String END_OF_LINE = System.getProperty( "line.separator" ); final private static String FILE_ENCODING = System.getProperty( "file.encoding" ); - - private int _responseCode = HttpURLConnection.HTTP_OK; - private URLConnection _connection; + private int _responseCode = HttpURLConnection.HTTP_OK; - private String _responseText; - private Hashtable _headers = new Hashtable(); - private void loadResponseText( URLConnection connection ) throws IOException { - StringBuffer sb = new StringBuffer(); - try { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - BufferedInputStream inputStream = new BufferedInputStream( connection.getInputStream() ); - byte[] buffer = new byte[8 * 1024]; - int count = 0; - do { - outputStream.write( buffer, 0, count ); - count = inputStream.read( buffer, 0, buffer.length ); - } while (count != -1); - - inputStream.close(); - - readMetaTags( outputStream.toByteArray() ); - _responseText = new String( outputStream.toByteArray(), getCharacterSet() ); - } catch (FileNotFoundException e) { - if (connection instanceof HttpURLConnection) { - _responseCode = HttpURLConnection.HTTP_NOT_FOUND; - _responseText = ""; - } else { - e.fillInStackTrace(); - throw e; - } - } - } - - + private int getResponseCode( URLConnection connection, String statusHeader ) { if (statusHeader == null) throw new HttpNotFoundException( connection.getURL().toExternalForm() ); @@ -152,42 +105,14 @@ } - final - protected void readMetaTags( byte[] rawMessage ) throws UnsupportedEncodingException { - ByteTagParser parser = new ByteTagParser( rawMessage ); - ByteTag tag = parser.getNextTag(); - while (tag != null && !tag.getName().equalsIgnoreCase( "body" )) { - if (tag.getName().equalsIgnoreCase( "meta" )) processMetaTag( tag ); - tag = parser.getNextTag(); - } - } - - - private void processMetaTag( ByteTag tag ) { - if ("content-type".equalsIgnoreCase( tag.getAttribute( "http_equiv" ) )) { - inferContentType( tag.getAttribute( "content" ) ); - } else if ("refresh".equalsIgnoreCase( tag.getAttribute( "http_equiv" ) )) { - readRefreshRequest( tag.getAttribute( "content" ) ); - } - } - - - private void inferContentType( String contentTypeHeader ) { - String originalHeader = (String) _headers.get( "Content-type".toUpperCase() ); - if (originalHeader == null || originalHeader.indexOf( "charset" ) < 0) { - _headers.put( "Content-type".toUpperCase(), contentTypeHeader ); - } - } - - private void readHeaders( URLConnection connection ) { loadHeaders( connection ); if (connection instanceof HttpURLConnection) { _responseCode = getResponseCode( connection, connection.getHeaderField(0) ); } else { _responseCode = HttpURLConnection.HTTP_OK; - if (getContentType().startsWith( "text" )) { - _headers.put( "Content-type".toUpperCase(), getContentType() + "; charset=" + FILE_ENCODING ); + if (connection.getContentType().startsWith( "text" )) { + setContentTypeHeader( connection.getContentType() + "; charset=" + FILE_ENCODING ); } } } @@ -207,7 +132,7 @@ } if (connection.getContentType() != null) { - _headers.put( "Content-type".toUpperCase(), connection.getContentType() ); + setContentTypeHeader( connection.getContentType() ); } } @@ -221,95 +146,5 @@ } } -} - -//======================================================================================= - -class ByteTag { - - ByteTag( byte[] buffer, int start, int length ) throws UnsupportedEncodingException { - _buffer = new String( buffer, start, length, "iso-8859-1" ).toCharArray(); - _name = nextToken(); - - String attribute = ""; - String token = nextToken(); - while (token.length() != 0) { - if (token.equals( "=" ) && attribute.length() != 0) { - _attributes.put( attribute.toLowerCase(), nextToken() ); - attribute = ""; - } else { - if (attribute.length() > 0) _attributes.put( attribute.toLowerCase(), "" ); - attribute = token; - } - token = nextToken(); - } - } - - - public String getName() { - return _name; - } - - public String getAttribute( String attributeName ) { - return (String) _attributes.get( attributeName ); - } - - public String toString() { - return "ByteTag[ name=" + _name + ";attributes = " + _attributes + ']'; - } - - private String _name = ""; - private Hashtable _attributes = new Hashtable(); - - - private char[] _buffer; - private int _start; - private int _end = -1; - - - private String nextToken() { - _start = _end+1; - while (_start < _buffer.length && Character.isWhitespace( _buffer[ _start ] )) _start++; - if (_start >= _buffer.length) { - return ""; - } else if (_buffer[ _start ] == '"') { - for (_end = _start+1; _end < _buffer.length && _buffer[ _end ] != '"'; _end++); - return new String( _buffer, _start+1, _end-_start-1 ); - } else if (_buffer[ _start ] == '\'') { - for (_end = _start+1; _end < _buffer.length && _buffer[ _end ] != '\''; _end++); - return new String( _buffer, _start+1, _end-_start-1 ); - } else if (_buffer[ _start ] == '=') { - _end = _start; - return "="; - } else { - for (_end = _start+1; _end < _buffer.length && _buffer[ _end ] != '=' && !Character.isWhitespace( _buffer[ _end ] ); _end++); - return new String( _buffer, _start, (_end--)-_start ); - } - } -} - -//======================================================================================= - - -class ByteTagParser { - - ByteTagParser( byte[] buffer ) { - _buffer = buffer; - } - - - ByteTag getNextTag() throws UnsupportedEncodingException { - _start = _end+1; - while (_start < _buffer.length && _buffer[ _start ] != '<') _start++; - for (_end =_start+1; _end < _buffer.length && _buffer[ _end ] != '>'; _end++); - if (_end >= _buffer.length || _end < _start) return null; - return new ByteTag( _buffer, _start+1, _end-_start-1 ); - } - - - private int _start = 0; - private int _end = -1; - - private byte[] _buffer; } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.37 retrieving revision 1.38 diff -u -r1.37 -r1.38 --- WebResponse.java 2001/07/02 13:05:56 1.37 +++ WebResponse.java 2001/07/06 17:11:04 1.38 @@ -20,17 +20,22 @@ * *******************************************************************************************************************/ +import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.IOException; import java.io.StringReader; +import java.io.UnsupportedEncodingException; + import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.net.URL; import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLConnection; import java.util.Enumeration; import java.util.Hashtable; @@ -52,6 +57,15 @@ /** + * Returns a web response built from a URL connection. Provided to allow + * access to WebResponse parsing without using a WebClient. + **/ + public static WebResponse newResponse( URLConnection connection ) throws IOException { + return new HttpWebResponse( "_top", connection.getURL(), connection ); + } + + + /** * Returns true if the response is HTML. **/ public boolean isHTML() { @@ -168,15 +182,18 @@ * Returns the text of the response (excluding headers) as a string. Use this method in preference to 'toString' * which may be used to represent internal state of this object. **/ - abstract - public String getText() throws IOException; + public String getText() throws IOException { + if (_responseText == null) loadResponseText(); + return _responseText; + } /** - * Returns an input stream for reading the contents of this reply. + * Returns a buffered input stream for reading the contents of this reply. **/ - abstract - public InputStream getInputStream() throws IOException; + public InputStream getInputStream() throws IOException { + return _inputStream; + } /** @@ -343,6 +360,15 @@ final + protected void defineRawInputStream( InputStream inputStream ) { + if (_inputStream != null || _responseText != null) { + throw new IllegalStateException( "Must be called before response text is defined." ); + } + _inputStream = inputStream; + } + + + final protected void readRefreshRequest( String contentTypeHeader ) { int splitIndex = contentTypeHeader.indexOf( ';' ); if (splitIndex < 0) splitIndex = 0; @@ -355,6 +381,14 @@ } + /** + * Overwrites the current value (if any) of the content type header. + **/ + protected void setContentTypeHeader( String value ) { + _contentHeader = value; + } + + //------------------------------------------ package members ------------------------------------------------ @@ -391,6 +425,8 @@ private ReceivedPage _page; + private String _contentHeader; + private String _contentType; private String _characterSet; @@ -401,7 +437,11 @@ private int _refreshDelay; + private String _responseText; + + private InputStream _inputStream; + // the following variables are essentially final; however, the JDK 1.1 compiler does not handle blank final variables properly with // multiple constructors that call each other, so the final qualifiers have been removed. @@ -410,6 +450,57 @@ private String _target; + protected void loadResponseText() throws IOException { + if (_responseText != null) throw new IllegalStateException( "May only invoke loadResponseText once" ); + _responseText = ""; + + InputStream inputStream = _inputStream; + try { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + byte[] buffer = new byte[8 * 1024]; + int count = 0; + do { + outputStream.write( buffer, 0, count ); + count = inputStream.read( buffer, 0, buffer.length ); + } while (count != -1); + + byte[] bytes = outputStream.toByteArray(); + readMetaTags( bytes ); + _responseText = new String( bytes, getCharacterSet() ); + _inputStream = new ByteArrayInputStream( bytes ); + } finally { + inputStream.close(); + } + } + + + private void readMetaTags( byte[] rawMessage ) throws UnsupportedEncodingException { + ByteTagParser parser = new ByteTagParser( rawMessage ); + ByteTag tag = parser.getNextTag(); + while (tag != null && !tag.getName().equalsIgnoreCase( "body" )) { + if (tag.getName().equalsIgnoreCase( "meta" )) processMetaTag( tag ); + tag = parser.getNextTag(); + } + } + + + private void processMetaTag( ByteTag tag ) { + if ("content-type".equalsIgnoreCase( tag.getAttribute( "http_equiv" ) )) { + inferContentType( tag.getAttribute( "content" ) ); + } else if ("refresh".equalsIgnoreCase( tag.getAttribute( "http_equiv" ) )) { + readRefreshRequest( tag.getAttribute( "content" ) ); + } + } + + + private void inferContentType( String contentTypeHeader ) { + String originalHeader = getHeaderField( "Content-type" ); + if (originalHeader == null || originalHeader.indexOf( "charset" ) < 0) { + setContentTypeHeader( contentTypeHeader ); + } + } + + private Hashtable getNewCookies() { if (_newCookies == null) { _newCookies = new Hashtable(); @@ -446,17 +537,12 @@ private void readContentTypeHeader() { - String contentHeader = getHeaderField( "Content-type" ); + String contentHeader = (_contentHeader != null) ? _contentHeader + : getHeaderField( "Content-type" ); if (contentHeader == null) contentHeader = DEFAULT_CONTENT_HEADER; - StringTokenizer st = new StringTokenizer( contentHeader, ";=" ); - _contentType = st.nextToken(); - while (st.hasMoreTokens()) { - String parameter = st.nextToken(); - if (st.hasMoreTokens()) { - String value = st.nextToken(); - if (parameter.trim().equalsIgnoreCase( "charset" )) _characterSet = value; - } - } + String[] parts = HttpUnitUtils.parseContentTypeHeader( contentHeader ); + _contentType = parts[0]; + if (parts[1] != null) _characterSet = parts[1]; } @@ -536,6 +622,100 @@ } + +//======================================================================================= + +class ByteTag { + + ByteTag( byte[] buffer, int start, int length ) throws UnsupportedEncodingException { + _buffer = new String( buffer, start, length, "iso-8859-1" ).toCharArray(); + _name = nextToken(); + + String attribute = ""; + String token = nextToken(); + while (token.length() != 0) { + if (token.equals( "=" ) && attribute.length() != 0) { + _attributes.put( attribute.toLowerCase(), nextToken() ); + attribute = ""; + } else { + if (attribute.length() > 0) _attributes.put( attribute.toLowerCase(), "" ); + attribute = token; + } + token = nextToken(); + } + } + + + public String getName() { + return _name; + } + + public String getAttribute( String attributeName ) { + return (String) _attributes.get( attributeName ); + } + + public String toString() { + return "ByteTag[ name=" + _name + ";attributes = " + _attributes + ']'; + } + + private String _name = ""; + private Hashtable _attributes = new Hashtable(); + + + private char[] _buffer; + private int _start; + private int _end = -1; + + + private String nextToken() { + _start = _end+1; + while (_start < _buffer.length && Character.isWhitespace( _buffer[ _start ] )) _start++; + if (_start >= _buffer.length) { + return ""; + } else if (_buffer[ _start ] == '"') { + for (_end = _start+1; _end < _buffer.length && _buffer[ _end ] != '"'; _end++); + return new String( _buffer, _start+1, _end-_start-1 ); + } else if (_buffer[ _start ] == '\'') { + for (_end = _start+1; _end < _buffer.length && _buffer[ _end ] != '\''; _end++); + return new String( _buffer, _start+1, _end-_start-1 ); + } else if (_buffer[ _start ] == '=') { + _end = _start; + return "="; + } else { + for (_end = _start+1; _end < _buffer.length && _buffer[ _end ] != '=' && !Character.isWhitespace( _buffer[ _end ] ); _end++); + return new String( _buffer, _start, (_end--)-_start ); + } + } +} + + +//======================================================================================= + + +class ByteTagParser { + + ByteTagParser( byte[] buffer ) { + _buffer = buffer; + } + + + ByteTag getNextTag() throws UnsupportedEncodingException { + _start = _end+1; + while (_start < _buffer.length && _buffer[ _start ] != '<') _start++; + for (_end =_start+1; _end < _buffer.length && _buffer[ _end ] != '>'; _end++); + if (_end >= _buffer.length || _end < _start) return null; + return new ByteTag( _buffer, _start+1, _end-_start-1 ); + } + + + private int _start = 0; + private int _end = -1; + + private byte[] _buffer; +} + + +//======================================================================================= class DefaultWebResponse extends WebResponse { |
From: Russell G. <rus...@us...> - 2001-07-06 17:11:06
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv3916/doc Modified Files: release_notes.txt Log Message: Release to enable access from Cactus Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- release_notes.txt 2001/07/02 13:23:45 1.41 +++ release_notes.txt 2001/07/06 17:11:04 1.42 @@ -11,7 +11,7 @@ Revision History: - 1-Jul-2001 + 6-Jul-2001 Acknowledgements: Thanks to Marcos Tarruella for adding a test case for the Base64 class @@ -20,11 +20,15 @@ was specified in the response header. 2. WebResponse.getRefreshDelay specifies the delay found in the header, if any. 3. HttpUnitOptions.setAutoRefresh controls whether the refresh URL is automatically followed. + 4. ServletUnit now supports HttpServletResponse.getOutputStream + 5. ServletUnit now supports <meta> tag parsing + 6. WebResponse.newResponse added to allow other libraries (such as Apache Cactus) + to create WebResponse objects without using WebClient. -19-Jun-2001 Problems corrected: 1. The cookbook was missing parentheses for its constructors 2. Updated the NearWords example to accomodate changes to the Merriam-Webster site + 18-Jun-2001 1.2.5 Acknowledgements: |
From: Russell G. <rus...@us...> - 2001-07-06 17:11:06
|
Update of /cvsroot/httpunit/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv3916 Modified Files: build.xml index.html Log Message: Release to enable access from Cactus Index: build.xml =================================================================== RCS file: /cvsroot/httpunit/httpunit/build.xml,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- build.xml 2001/07/02 13:05:56 1.29 +++ build.xml 2001/07/06 17:11:03 1.30 @@ -5,8 +5,8 @@ <project name="httpunit" default="jar" basedir="."> <property name="name" value="httpunit" /> <property name="Name" value="HttpUnit" /> - <property name="version" value="1.2.5" /> - <property name="zip_version" value="1_2_5" /> + <property name="version" value="1.2.6" /> + <property name="zip_version" value="1_2_6" /> <property name="src.dir" value="src" /> <property name="tstsrc.dir" value="test" /> Index: index.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/index.html,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- index.html 2001/06/18 20:21:30 1.16 +++ index.html 2001/07/06 17:11:03 1.17 @@ -45,7 +45,7 @@ <li>We have a <a href="http://lists.sourceforge.net/mailman/listinfo/httpunit-develop">mailing list</a> for discussion of the code. <li>Read-only access to the CVS "<b>HttpUnit</b>" repository is available both -<a href="http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/?cvsroot=httpunit">online</a> as well as with +<a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/httpunit/">online</a> as well as with a cvs client, accessing the repository at <code>:pserver:ano...@cv...:/cvsroot/httpunit</code>. </ul> |
From: Russell G. <rus...@us...> - 2001-07-02 13:23:49
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv14862/test/com/meterware/httpunit Modified Files: Base64Test.java Log Message: Added test for length of base64 decoding string Index: Base64Test.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/Base64Test.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Base64Test.java 2000/09/01 14:54:07 1.1 +++ Base64Test.java 2001/07/02 13:23:45 1.2 @@ -2,14 +2,14 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000, Russell Gold +* Copyright (c) 2000-2001, Russell Gold * -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -* documentation files (the "Software"), to deal in the Software without restriction, including without limitation +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +* documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * -* The above copyright notice and this permission notice shall be included in all copies or substantial portions +* The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO @@ -26,14 +26,17 @@ /** * Tests the base64 converter. + * + * @author <a href="mailto:rus...@ac...">Russell Gold</a> + * @author <a href="mailto:mta...@si...">Marcos Tarruella</a> **/ public class Base64Test extends TestCase { public static void main(String args[]) { junit.textui.TestRunner.run( suite() ); } - - + + public static Test suite() { return new TestSuite( Base64Test.class ); } @@ -42,8 +45,8 @@ public Base64Test( String name ) { super( name ); } + - public void testEncode() { assertEquals( "Result of encoding", "QWxhZGRpbjpvcGVuIHNlc2FtZQ==", Base64.encode( "Aladdin:open sesame" ) ); assertEquals( "Result of encoding", "QWRtaW46Zm9vYmFy", Base64.encode( "Admin:foobar" ) ); @@ -53,6 +56,17 @@ public void testDecode() { assertEquals( "Result of decoding", "Aladdin:open sesame", Base64.decode( "QWxhZGRpbjpvcGVuIHNlc2FtZQ==" ) ); assertEquals( "Result of decoding", "Admin:foobar", Base64.decode( "QWRtaW46Zm9vYmFy" ) ); + } + + + public void testExceptionDecoding() { + try { + Base64.decode( "123"); + fail("valid Base64 codes have a multiple of 4 characters"); + } catch (Exception e) { + assertEquals("valid Base64 codes have a multiple of 4 characters", + e.getMessage()); + } } } |
From: Russell G. <rus...@us...> - 2001-07-02 13:23:49
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv14862/doc Modified Files: release_notes.txt Log Message: Added test for length of base64 decoding string Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.40 retrieving revision 1.41 diff -u -r1.40 -r1.41 --- release_notes.txt 2001/07/02 13:05:56 1.40 +++ release_notes.txt 2001/07/02 13:23:45 1.41 @@ -12,7 +12,10 @@ Revision History: 1-Jul-2001 - Additions: +Acknowledgements: + Thanks to Marcos Tarruella for adding a test case for the Base64 class + +Additions: 1. WebResponse.getRefreshRequest now returns a WebRequest object if a refresh URL was specified in the response header. 2. WebResponse.getRefreshDelay specifies the delay found in the header, if any. |
From: Russell G. <rus...@us...> - 2001-07-02 13:05:59
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv10516/src/com/meterware/httpunit Modified Files: HttpUnitOptions.java HttpWebResponse.java WebClient.java WebResponse.java Log Message: Added support for refresh meta tag Index: HttpUnitOptions.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- HttpUnitOptions.java 2001/06/13 16:38:20 1.6 +++ HttpUnitOptions.java 2001/07/02 13:05:56 1.7 @@ -158,6 +158,27 @@ } + /** + * Returns true if HttpUnit should automatically follow page refresh requests. + * By default, this is false, so that programs can verify the redirect page presented + * to users before the browser switches to the new page. + **/ + public static boolean getAutoRefresh() { + return _autoRefresh; + } + + + /** + * Specifies whether HttpUnit should automatically follow page refresh requests. + * By default, this is false, so that programs can verify the redirect page presented + * to users before the browser switches to the new page. Setting this to true can + * cause an infinite loop on pages that refresh themselves. + **/ + public static void setAutoRefresh( boolean autoRefresh ) { + _autoRefresh = autoRefresh; + } + + //--------------------------------- private members -------------------------------------- @@ -172,6 +193,8 @@ private static boolean _loggingHttpHeaders; private static boolean _matchesIgnoreCase = true; + + private static boolean _autoRefresh; private static int _redirectDelay; Index: HttpWebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- HttpWebResponse.java 2001/06/11 21:21:09 1.10 +++ HttpWebResponse.java 2001/07/02 13:05:56 1.11 @@ -152,7 +152,8 @@ } - private void readMetaTags( byte[] rawMessage ) throws UnsupportedEncodingException { + final + protected void readMetaTags( byte[] rawMessage ) throws UnsupportedEncodingException { ByteTagParser parser = new ByteTagParser( rawMessage ); ByteTag tag = parser.getNextTag(); while (tag != null && !tag.getName().equalsIgnoreCase( "body" )) { @@ -163,9 +164,10 @@ private void processMetaTag( ByteTag tag ) { - if (tag.getAttribute( "http_equiv" ) != null && - tag.getAttribute( "http_equiv" ).equalsIgnoreCase( "content-type" )) { + if ("content-type".equalsIgnoreCase( tag.getAttribute( "http_equiv" ) )) { inferContentType( tag.getAttribute( "content" ) ); + } else if ("refresh".equalsIgnoreCase( tag.getAttribute( "http_equiv" ) )) { + readRefreshRequest( tag.getAttribute( "content" ) ); } } @@ -272,6 +274,9 @@ return ""; } else if (_buffer[ _start ] == '"') { for (_end = _start+1; _end < _buffer.length && _buffer[ _end ] != '"'; _end++); + return new String( _buffer, _start+1, _end-_start-1 ); + } else if (_buffer[ _start ] == '\'') { + for (_end = _start+1; _end < _buffer.length && _buffer[ _end ] != '\''; _end++); return new String( _buffer, _start+1, _end-_start-1 ); } else if (_buffer[ _start ] == '=') { _end = _start; Index: WebClient.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- WebClient.java 2001/06/06 13:25:04 1.6 +++ WebClient.java 2001/07/02 13:05:56 1.7 @@ -218,7 +218,9 @@ protected void updateClient( WebResponse response ) throws MalformedURLException, IOException, SAXException { validateHeaders( response ); updateCookies( response ); - if (response.getHeaderField( "Location" ) == null) { + if (HttpUnitOptions.getAutoRefresh() && response.getRefreshRequest() != null) { + getResponse( response.getRefreshRequest() ); + } else if (response.getHeaderField( "Location" ) == null) { updateFrames( response ); } else { delay( HttpUnitOptions.getRedirectDelay() ); Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- WebResponse.java 2001/06/13 16:38:20 1.36 +++ WebResponse.java 2001/07/02 13:05:56 1.37 @@ -85,6 +85,25 @@ /** + * Returns a request to refresh this page, if any. This request will be defined + * by a <meta> tag in the header. If no tag exists, will return null. + **/ + public WebRequest getRefreshRequest() { + return _refreshRequest; + } + + + /** + * Returns the delay before normally following the request to refresh this page, if any. + * This request will be defined by a <meta> tag in the header. If no tag exists, + * will return zero. + **/ + public int getRefreshDelay() { + return _refreshDelay; + } + + + /** * Returns the response code associated with this response. **/ abstract @@ -323,6 +342,19 @@ } + final + protected void readRefreshRequest( String contentTypeHeader ) { + int splitIndex = contentTypeHeader.indexOf( ';' ); + if (splitIndex < 0) splitIndex = 0; + try { + _refreshDelay = Integer.parseInt( contentTypeHeader.substring( 0, splitIndex ) ); + _refreshRequest = new GetMethodWebRequest( contentTypeHeader.substring( splitIndex+1 ) ); + } catch (NumberFormatException e) { + System.out.println( "Unable to interpret refresh tag: \"" + contentTypeHeader + '"' ); + } + } + + //------------------------------------------ package members ------------------------------------------------ @@ -364,6 +396,10 @@ private String _characterSet; private Hashtable _newCookies; + + private WebRequest _refreshRequest; + + private int _refreshDelay; // the following variables are essentially final; however, the JDK 1.1 compiler does not handle blank final variables properly with |
From: Russell G. <rus...@us...> - 2001-07-02 13:05:59
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv10516/test/com/meterware/httpunit Modified Files: HttpUnitTest.java WebPageTest.java Log Message: Added support for refresh meta tag Index: HttpUnitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitTest.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- HttpUnitTest.java 2001/06/11 21:21:09 1.12 +++ HttpUnitTest.java 2001/07/02 13:05:56 1.13 @@ -47,7 +47,7 @@ } - public void tearDown() { + public void tearDown() throws Exception { if (_server != null) _server.shutDown(); } Index: WebPageTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebPageTest.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- WebPageTest.java 2001/06/11 21:21:09 1.11 +++ WebPageTest.java 2001/07/02 13:05:56 1.12 @@ -54,9 +54,10 @@ } - public void setUp() throws Exception { - super.setUp(); + public void tearDown() throws Exception { + super.tearDown(); HttpUnitOptions.resetDefaultCharacterSet(); + HttpUnitOptions.setAutoRefresh( false ); } @@ -84,6 +85,7 @@ WebResponse simplePage = wc.getResponse( request ); assertEquals( "Title", "A Sample Page", simplePage.getTitle() ); assertEquals( "Character set", "iso-8859-1", simplePage.getCharacterSet() ); + assertNull( "No refresh request should have been found", simplePage.getRefreshRequest() ); } @@ -208,6 +210,41 @@ assertEquals( "Message", "Hello, " + hebrewName, cells[0][0] ); assertEquals( "Character set", "iso-8859-8", answer.getCharacterSet() ); } + + + public void testMetaRefreshRequest() throws Exception { + String refreshURL = getHostPath() + "/NextPage.html"; + String page = "<html><head><title>Sample</title>" + + "<meta Http_equiv=refresh content='2;" + refreshURL + "'></head>\n" + + "<body>This has no data\n" + + "</body></html>\n"; + defineResource( "SimplePage.html", page ); + + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( getHostPath() + "/SimplePage.html" ); + WebResponse simplePage = wc.getResponse( request ); + + assertEquals( "Refresh URL", refreshURL, simplePage.getRefreshRequest().getURL().toExternalForm() ); + assertEquals( "Refresh delay", 2, simplePage.getRefreshDelay() ); + } + + + public void testAutoRefresh() throws Exception { + String refreshURL = getHostPath() + "/NextPage.html"; + String page = "<html><head><title>Sample</title>" + + "<meta Http_equiv=refresh content='2;" + refreshURL + "'></head>\n" + + "<body>This has no data\n" + + "</body></html>\n"; + defineResource( "SimplePage.html", page ); + defineWebPage( "NextPage", "Not much here" ); + + HttpUnitOptions.setAutoRefresh( true ); + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( getHostPath() + "/SimplePage.html" ); + WebResponse simplePage = wc.getResponse( request ); + + assertNull( "No refresh request should have been found", simplePage.getRefreshRequest() ); + } private String toUnicode( String string ) { |
From: Russell G. <rus...@us...> - 2001-07-02 13:05:59
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv10516/doc Modified Files: release_notes.txt todo.txt Log Message: Added support for refresh meta tag Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- release_notes.txt 2001/06/19 14:43:49 1.39 +++ release_notes.txt 2001/07/02 13:05:56 1.40 @@ -11,6 +11,13 @@ Revision History: + 1-Jul-2001 + Additions: + 1. WebResponse.getRefreshRequest now returns a WebRequest object if a refresh URL + was specified in the response header. + 2. WebResponse.getRefreshDelay specifies the delay found in the header, if any. + 3. HttpUnitOptions.setAutoRefresh controls whether the refresh URL is automatically followed. + 19-Jun-2001 Problems corrected: 1. The cookbook was missing parentheses for its constructors Index: todo.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/todo.txt,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- todo.txt 2001/06/18 20:21:30 1.13 +++ todo.txt 2001/07/02 13:05:56 1.14 @@ -1,4 +1,3 @@ -o Support <META HTTP_EQUIV=REFRESH tags> o Support optional tags which hide their contents (as in IFRAME, OBJECT, etc.) o Support IFRAME tag o Support reset button detection |
From: Russell G. <rus...@us...> - 2001-07-02 13:05:58
|
Update of /cvsroot/httpunit/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv10516 Modified Files: build.xml Log Message: Added support for refresh meta tag Index: build.xml =================================================================== RCS file: /cvsroot/httpunit/httpunit/build.xml,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- build.xml 2001/06/18 21:02:23 1.28 +++ build.xml 2001/07/02 13:05:56 1.29 @@ -64,7 +64,7 @@ <target name="compile" depends="prepare,check_for_optional_packages"> <mkdir dir="${build.classes}" /> <javac srcdir="${src.dir}" destdir="${build.classes}" - debug="off" deprecation="on" optimize="off"> + debug="on" deprecation="on" optimize="off"> <classpath refid="base.classpath" /> <exclude name="**/servletunit/*" unless="jsdk.present" /> </javac> |
From: Russell G. <rus...@us...> - 2001-06-19 14:43:52
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv672/doc Modified Files: Cookbook.html release_notes.txt Log Message: Minor documentation / example fixes Index: Cookbook.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/Cookbook.html,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Cookbook.html 2000/10/04 15:45:46 1.2 +++ Cookbook.html 2001/06/19 14:43:49 1.3 @@ -10,14 +10,14 @@ which it does via cookies returned by the server. To use it, one must create a <A HREF="api/com/meterware/httpunit/WebRequest.html">request</A> and ask the WebConversation for a response.<BR> For example: -<PRE><CODE> WebConversation wc = new WebConversation; +<PRE><CODE> WebConversation wc = new WebConversation(); WebRequest req = new GetMethodWebRequest( "http://www.meterware.com/testpage.html" ); WebResponse resp = wc.getResponse( req ); </CODE></PRE> The <A HREF="api/com/meterware/httpunit/WebResponse.html">response</A> may now be manipulated either as pure text (via the <CODE>toString()</CODE> method), as a DOM (via the <CODE>getDOM()</CODE> method), or by using the various other methods described below. Because the above sequence is so common, it can be abbreviated to: -<PRE><CODE> WebConversation wc = new WebConversation; +<PRE><CODE> WebConversation wc = new WebConversation(); WebResponse resp = wc.getResponse( "http://www.meterware.com/testpage.html" ); </CODE></PRE> @@ -25,7 +25,7 @@ The simplest and most common form of navigation among web pages is via links. HttpUnit allows users to find links by the text within them, and to use those links as new page requests. For example, this page contains a link to the JavaDoc for the <CODE>WebResponse</CODE> class, above. That page could therefore be obtained as follows: -<PRE><CODE> WebConversation wc = new WebConversation; +<PRE><CODE> WebConversation wc = new WebConversation(); WebResponse resp = wc.getResponse( "http://httpunit.sourceforge.net/doc/Cookbook.html" ); // read this page WebLink link = resp.getLinkWith( "response" ); // find the link WebRequest req = link.getRequest(); // convert it to a request @@ -132,7 +132,7 @@ which are currently active. Each response replaces the contents of the appropriate frame, which is not necessarily the topmost frame ("_top"). In the following scenation, there are two active subframes, named "overview" and "details": -<PRE><CODE> WebConversation wc = new WebConversation; +<PRE><CODE> WebConversation wc = new WebConversation(); WebResponse top = wc.getResponse( "http://www.meterware.com/Frames.html" ); // read a page with two frames WebResponse summary = wc.getFrameContents( "summary" ); // read the summary frame WebLink link = summary.getLinkWith( "Cake Recipe" ); // find the link (which targets "details" ); Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- release_notes.txt 2001/06/18 20:21:30 1.38 +++ release_notes.txt 2001/06/19 14:43:49 1.39 @@ -11,6 +11,11 @@ Revision History: +19-Jun-2001 +Problems corrected: + 1. The cookbook was missing parentheses for its constructors + 2. Updated the NearWords example to accomodate changes to the Merriam-Webster site + 18-Jun-2001 1.2.5 Acknowledgements: Thanks to Rolf Schmidiger for corrected behavior when failing to find a site |