httpunit-commit Mailing List for httpunit (Page 72)
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-10-19 18:26:32
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv7181/doc Modified Files: release_notes.txt Log Message: Allow file uploads in POST w/o form Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.54 retrieving revision 1.55 diff -u -r1.54 -r1.55 --- release_notes.txt 2001/10/16 16:21:23 1.54 +++ release_notes.txt 2001/10/19 18:26:29 1.55 @@ -10,6 +10,11 @@ Revision History: +18-Oct-2001 + Additions: + 1. It is now possible to upload a file via a POST request not derived from a form. To do this, call + PostMessageWebRequest.setMimeEncoded( true ) before calling selectFile. + 16-Oct-2001 Problems corrected: 1. WebRequest.isFileParameter is now functioning and public |
From: Russell G. <rus...@us...> - 2001-10-19 18:26:32
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv7181/src/com/meterware/httpunit Modified Files: PostMethodWebRequest.java WebRequest.java Log Message: Allow file uploads in POST w/o form Index: PostMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/PostMethodWebRequest.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- PostMethodWebRequest.java 2001/08/21 19:56:22 1.16 +++ PostMethodWebRequest.java 2001/10/19 18:26:29 1.17 @@ -69,6 +69,18 @@ /** + * Selects whether MIME-encoding will be used for this request. MIME-encoding changes the way the request is sent + * and is required for requests which include file parameters. This method may only be called for a request which + * was not created from a form. + **/ + public void setMimeEncoded( boolean mimeEncoded ) + { + if (isFormBased()) throw new IllegalStateException( "Encoding is defined by the form from which this request is derived." ); + _mimeEncoded = mimeEncoded; + } + + + /** * Returns the HTTP method defined for this request. **/ public String getMethod() { @@ -106,6 +118,23 @@ } + /** + * Returns true if selectFile may be called with this parameter. + */ + protected boolean maySelectFile( String parameterName ) + { + return !isFormBased() || super.isFileParameter( parameterName ); + } + + + /** + * Returns true if this request is to be MIME-encoded. + **/ + protected boolean isMimeEncoded() { + return isFormBased() ? super.isMimeEncoded() : _mimeEncoded; + } + + //----------------------------- MessageBodyWebRequest methods --------------------------- @@ -146,6 +175,8 @@ private InputStream _source; private MessageBody _body; + /** If true, non-form-based request will be MIME-encoded. **/ + private boolean _mimeEncoded; } Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- WebRequest.java 2001/10/16 16:21:25 1.24 +++ WebRequest.java 2001/10/19 18:26:29 1.25 @@ -64,9 +64,7 @@ * Sets the file for a parameter upload in a web request. **/ public void selectFile( String parameterName, File file ) { - if (_sourceForm == null || !_sourceForm.isFileParameter( parameterName )) { - throw new IllegalNonFileParameterException( parameterName ); - } + assertFileParameter( parameterName ); if (!isMimeEncoded()) throw new MultipartFormRequiredException(); } @@ -75,9 +73,7 @@ * Sets the file for a parameter upload in a web request. **/ public void selectFile( String parameterName, File file, String contentType ) { - if (_sourceForm == null || !_sourceForm.isFileParameter( parameterName )) { - throw new IllegalNonFileParameterException( parameterName ); - } + assertFileParameter( parameterName ); if (!isMimeEncoded()) throw new MultipartFormRequiredException(); } @@ -86,9 +82,16 @@ * Sets the file for a parameter upload in a web request. **/ public void selectFile( String parameterName, String fileName, InputStream inputStream, String contentType ) { - if (_sourceForm == null || !_sourceForm.isFileParameter( parameterName )) { - throw new IllegalNonFileParameterException( parameterName ); - } + assertFileParameter( parameterName ); + } + + + /** + * Throws an exception if the specified parameter may not be set as a file. + */ + private void assertFileParameter( String parameterName ) + { + if (!maySelectFile( parameterName )) throw new IllegalNonFileParameterException( parameterName ); if (!isMimeEncoded()) throw new MultipartFormRequiredException(); } @@ -233,9 +236,26 @@ /** - * Returns true if this request is to be MIME-encoded. + * Returns true if this request is based on a web form. **/ final + protected boolean isFormBased() { + return _sourceForm != null; + } + + + /** + * Returns true if selectFile may be called with this parameter. + */ + protected boolean maySelectFile( String parameterName ) + { + return isFileParameter( parameterName ); + } + + + /** + * Returns true if this request is to be MIME-encoded. + **/ protected boolean isMimeEncoded() { return _sourceForm != null && _sourceForm.isSubmitAsMime(); } |
From: Russell G. <rus...@us...> - 2001-10-16 16:37:47
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv30402/doc Modified Files: release_notes.txt Log Message: Handle relative refresh URLs; make isFileParameter public Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.53 retrieving revision 1.54 diff -u -r1.53 -r1.54 --- release_notes.txt 2001/10/15 18:25:58 1.53 +++ release_notes.txt 2001/10/16 16:21:23 1.54 @@ -10,6 +10,11 @@ Revision History: +16-Oct-2001 + Problems corrected: + 1. WebRequest.isFileParameter is now functioning and public + 2. auto-redirect now handles relative URLs + 15-Oct-2001 Problems corrected: 1. The http-equiv meta tag was incorrectly matched as "http_equiv" |
From: Russell G. <rus...@us...> - 2001-10-16 16:37:47
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv30402/src/com/meterware/httpunit Modified Files: WebRequest.java WebResponse.java Log Message: Handle relative refresh URLs; make isFileParameter public Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- WebRequest.java 2001/08/13 21:29:41 1.23 +++ WebRequest.java 2001/10/16 16:21:25 1.24 @@ -53,6 +53,14 @@ /** + * Returns true if the specified parameter is a file field. + **/ + public boolean isFileParameter( String name ) { + return _sourceForm != null && _sourceForm.isFileParameter( name ); + } + + + /** * Sets the file for a parameter upload in a web request. **/ public void selectFile( String parameterName, File file ) { @@ -221,14 +229,6 @@ **/ protected WebRequest( WebRequest baseRequest, String urlString, String target ) throws MalformedURLException { this( baseRequest.getURL(), urlString, target ); - } - - - /** - * Returns true if the specified parameter is a file field. - **/ - protected boolean isFileParameter( String name ) { - return false; } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.47 retrieving revision 1.48 diff -u -r1.47 -r1.48 --- WebResponse.java 2001/10/15 18:25:59 1.47 +++ WebResponse.java 2001/10/16 16:21:25 1.48 @@ -382,7 +382,7 @@ if (splitIndex < 0) splitIndex = 0; try { _refreshDelay = Integer.parseInt( contentTypeHeader.substring( 0, splitIndex ) ); - _refreshRequest = new GetMethodWebRequest( getRefreshURL( contentTypeHeader.substring( splitIndex+1 ) ) ); + _refreshRequest = new GetMethodWebRequest( _url, getRefreshURL( contentTypeHeader.substring( splitIndex+1 ) ), _target ); } catch (NumberFormatException e) { System.out.println( "Unable to interpret refresh tag: \"" + contentTypeHeader + '"' ); } |
From: Russell G. <rus...@us...> - 2001-10-16 16:37:47
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv30402/test/com/meterware/httpunit Modified Files: WebPageTest.java Log Message: Handle relative refresh URLs; make isFileParameter public Index: WebPageTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebPageTest.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- WebPageTest.java 2001/10/15 18:25:59 1.14 +++ WebPageTest.java 2001/10/16 16:21:25 1.15 @@ -232,7 +232,7 @@ public void testMetaRefreshURLRequest() throws Exception { String refreshURL = getHostPath() + "/NextPage.html"; String page = "<html><head><title>Sample</title>" + - "<meta Http-equiv=refresh content='2;URL=" + refreshURL + "'></head>\n" + + "<meta Http-equiv=refresh content='2;URL=NextPage.html'></head>\n" + "<body>This has no data\n" + "</body></html>\n"; defineResource( "SimplePage.html", page ); |
From: Russell G. <rus...@us...> - 2001-10-15 18:26:02
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv7786/test/com/meterware/httpunit Modified Files: WebPageTest.java Log Message: Default to no charset on POST, match http-equiv Index: WebPageTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebPageTest.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- WebPageTest.java 2001/09/13 15:11:30 1.13 +++ WebPageTest.java 2001/10/15 18:25:59 1.14 @@ -232,7 +232,7 @@ public void testMetaRefreshURLRequest() throws Exception { String refreshURL = getHostPath() + "/NextPage.html"; String page = "<html><head><title>Sample</title>" + - "<meta Http_equiv=refresh content='2;URL=" + refreshURL + "'></head>\n" + + "<meta Http-equiv=refresh content='2;URL=" + refreshURL + "'></head>\n" + "<body>This has no data\n" + "</body></html>\n"; defineResource( "SimplePage.html", page ); |
From: Russell G. <rus...@us...> - 2001-10-15 18:26:02
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv7786/src/com/meterware/httpunit Modified Files: HttpUnitOptions.java WebResponse.java Log Message: Default to no charset on POST, match http-equiv Index: HttpUnitOptions.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- HttpUnitOptions.java 2001/08/21 19:56:22 1.10 +++ HttpUnitOptions.java 2001/10/15 18:25:59 1.11 @@ -44,7 +44,7 @@ _redirectDelay = 0; _characterSet = DEFAULT_CHARACTER_SET; _contentType = DEFAULT_CONTENT_TYPE; - _postIncludesCharset = true; + _postIncludesCharset = false; } @@ -279,7 +279,7 @@ private static boolean _autoRefresh; - private static boolean _postIncludesCharset = true; + private static boolean _postIncludesCharset = false; private static int _redirectDelay; Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.46 retrieving revision 1.47 diff -u -r1.46 -r1.47 --- WebResponse.java 2001/09/13 15:11:30 1.46 +++ WebResponse.java 2001/10/15 18:25:59 1.47 @@ -521,11 +521,18 @@ private void processMetaTag( ByteTag tag ) { - if ("content-type".equalsIgnoreCase( tag.getAttribute( "http_equiv" ) )) { + if (isHttpEquivMetaTag( tag, "content-type" )) { inferContentType( tag.getAttribute( "content" ) ); - } else if ("refresh".equalsIgnoreCase( tag.getAttribute( "http_equiv" ) )) { + } else if (isHttpEquivMetaTag( tag, "refresh" )) { readRefreshRequest( tag.getAttribute( "content" ) ); } + } + + + private boolean isHttpEquivMetaTag( ByteTag tag, String headerName ) + { + return headerName.equalsIgnoreCase( tag.getAttribute( "http_equiv" ) ) || + headerName.equalsIgnoreCase( tag.getAttribute( "http-equiv" ) ); } |
From: Russell G. <rus...@us...> - 2001-10-15 18:26:01
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv7786/doc Modified Files: release_notes.txt todo.txt Log Message: Default to no charset on POST, match http-equiv Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.52 retrieving revision 1.53 diff -u -r1.52 -r1.53 --- release_notes.txt 2001/09/13 15:11:30 1.52 +++ release_notes.txt 2001/10/15 18:25:58 1.53 @@ -10,6 +10,11 @@ Revision History: +15-Oct-2001 + Problems corrected: + 1. The http-equiv meta tag was incorrectly matched as "http_equiv" + 2. By default, POSTs included charset attributes which messed up some servlet engines + 13-Sep-2001 Problems corrected: 1. The refresh handling now recognizes requests with content syntax "<seconds>;<location>" or "<seconds>; URL=<location>" Index: todo.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/todo.txt,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- todo.txt 2001/07/31 16:08:59 1.16 +++ todo.txt 2001/10/15 18:25:58 1.17 @@ -1,3 +1,10 @@ +High Priority +o Allow servlet initialization parameters in registerServlet +o Allow multiple text parameters with the same name +o Add support for getLinkWithName +o Allow creation of POST method with file upload w/o form +o Other changes already submitted + Medium priority: o Support optional tags which hide their contents (as in IFRAME, OBJECT, etc.) o Support IFRAME tag |
From: Russell G. <rus...@us...> - 2001-09-13 15:11:32
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv13691/doc Modified Files: release_notes.txt Log Message: Now handle refresh requests with URL=<location> syntax Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.51 retrieving revision 1.52 diff -u -r1.51 -r1.52 --- release_notes.txt 2001/08/21 19:56:21 1.51 +++ release_notes.txt 2001/09/13 15:11:30 1.52 @@ -10,6 +10,10 @@ Revision History: +13-Sep-2001 + Problems corrected: + 1. The refresh handling now recognizes requests with content syntax "<seconds>;<location>" or "<seconds>; URL=<location>" + 21-Aug-2001 Acknowledgements: Thanks to Richard Scothern for identiying the cause of problems with POST requests and older servlet engines. |
From: Russell G. <rus...@us...> - 2001-09-13 15:11:32
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv13691/test/com/meterware/httpunit Modified Files: WebPageTest.java Log Message: Now handle refresh requests with URL=<location> syntax Index: WebPageTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebPageTest.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- WebPageTest.java 2001/07/02 13:05:56 1.12 +++ WebPageTest.java 2001/09/13 15:11:30 1.13 @@ -229,6 +229,23 @@ } + public void testMetaRefreshURLRequest() throws Exception { + String refreshURL = getHostPath() + "/NextPage.html"; + String page = "<html><head><title>Sample</title>" + + "<meta Http_equiv=refresh content='2;URL=" + 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>" + |
From: Russell G. <rus...@us...> - 2001-09-13 15:11:32
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv13691/src/com/meterware/httpunit Modified Files: WebResponse.java Log Message: Now handle refresh requests with URL=<location> syntax Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.45 retrieving revision 1.46 diff -u -r1.45 -r1.46 --- WebResponse.java 2001/08/13 21:29:41 1.45 +++ WebResponse.java 2001/09/13 15:11:30 1.46 @@ -382,9 +382,20 @@ if (splitIndex < 0) splitIndex = 0; try { _refreshDelay = Integer.parseInt( contentTypeHeader.substring( 0, splitIndex ) ); - _refreshRequest = new GetMethodWebRequest( contentTypeHeader.substring( splitIndex+1 ) ); + _refreshRequest = new GetMethodWebRequest( getRefreshURL( contentTypeHeader.substring( splitIndex+1 ) ) ); } catch (NumberFormatException e) { System.out.println( "Unable to interpret refresh tag: \"" + contentTypeHeader + '"' ); + } + } + + + private String getRefreshURL( String text ) { + text = text.trim(); + if (!text.toUpperCase().startsWith( "URL" )) { + return text; + } else { + int splitIndex = text.indexOf( '=' ); + return text.substring( splitIndex+1 ).trim(); } } |
From: Russell G. <rus...@us...> - 2001-08-21 19:56:24
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv18783/src/com/meterware/httpunit Modified Files: HttpUnitOptions.java PostMethodWebRequest.java WebForm.java Log Message: Allow users to disable sending the charset with POST requests Index: HttpUnitOptions.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- HttpUnitOptions.java 2001/08/08 19:18:12 1.9 +++ HttpUnitOptions.java 2001/08/21 19:56:22 1.10 @@ -44,6 +44,7 @@ _redirectDelay = 0; _characterSet = DEFAULT_CHARACTER_SET; _contentType = DEFAULT_CONTENT_TYPE; + _postIncludesCharset = true; } @@ -81,6 +82,26 @@ /** + * Determines whether a normal POST request will include the character set in the content-type header. + * The default is to include it; however, some older servlet engines (most notably Tomcat 3.1) get confused + * when they see it. + **/ + public static void setPostIncludesCharset( boolean postIncludesCharset ) + { + _postIncludesCharset = postIncludesCharset; + } + + + /** + * Returns true if POST requests should include the character set in the content-type header. + **/ + public static boolean isPostIncludesCharset() + { + return _postIncludesCharset; + } + + + /** * Sets the default content type for pages which do not specify one. **/ public static void setDefaultContentType( String contentType ) { @@ -257,6 +278,8 @@ private static boolean _matchesIgnoreCase = true; private static boolean _autoRefresh; + + private static boolean _postIncludesCharset = true; private static int _redirectDelay; Index: PostMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/PostMethodWebRequest.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- PostMethodWebRequest.java 2001/07/31 16:08:59 1.15 +++ PostMethodWebRequest.java 2001/08/21 19:56:22 1.16 @@ -168,7 +168,9 @@ * Returns the content type of this message body. **/ String getContentType() { - return "application/x-www-form-urlencoded; charset=" + getRequest().getCharacterSet(); + return "application/x-www-form-urlencoded" + + (!HttpUnitOptions.isPostIncludesCharset() ? "" + : "; charset=" + getRequest().getCharacterSet()); } Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- WebForm.java 2001/08/06 20:19:41 1.25 +++ WebForm.java 2001/08/21 19:56:22 1.26 @@ -698,6 +698,12 @@ return getValue( optionNode.getFirstChild() ); } } + + + private String getTextValue( Node optionNode ) { + NamedNodeMap nnm = optionNode.getAttributes(); + return getValue( optionNode.getFirstChild() ); + } } |
From: Russell G. <rus...@us...> - 2001-08-21 19:56:24
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv18783/doc Modified Files: faq.html release_notes.txt Log Message: Allow users to disable sending the charset with POST requests Index: faq.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/faq.html,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- faq.html 2001/07/24 15:28:03 1.9 +++ faq.html 2001/08/21 19:56:21 1.10 @@ -15,46 +15,47 @@ <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 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> +<LI><A HREF="#badPost">Why doesn't my servlet see parameters on a POST request?</A></LI> </OL> <A NAME="Cannot unzip"><H2>Why can't I unzip the download library?</H2></A> -HttpUnit is archived using the classes in the java.util.zip package. Some older Unzip programs cannot understand this format. +HttpUnit is archived using the classes in the java.util.zip package. Some older Unzip programs cannot understand this format. If you are using WinZip, stick to version 7.0 or later. <A NAME="org.xml.sax"><H2>What is the org.xml.sax package?</H2></A> You may be getting compile or runtime errors asking for the org.xml.sax package. This package is found in JTidy, the HTML parser used -by HttpUnit. You should download Jtidy from +by HttpUnit. You should download Jtidy from <A HREF="http://sourceforge.net/project/showfiles.php?group_id=13153">its SourceForge download page</A> and install Tidy.jar in your classpath. <A NAME="meterware.com"><H2>Where is meterware.com?</H2></A> -When I started HttpUnit, I had a web site with the meterware.com domain, and relied on it to host some of the example code. -Since then, my ISP has dropped the hosting package I was using and I have not yet signed up with another host, mostly due to +When I started HttpUnit, I had a web site with the meterware.com domain, and relied on it to host some of the example code. +Since then, my ISP has dropped the hosting package I was using and I have not yet signed up with another host, mostly due to lack of funds. I hope to correct this in the near future. <A NAME="javascript"><H2>How do I use HttpUnit to test my pages that use JavaScript?</H2></A> -Unfortunately, you can't. HttpUnit does not support any dialect of JavaScript. I have been shown a JavaScript library and it is possible +Unfortunately, you can't. HttpUnit does not support any dialect of JavaScript. I have been shown a JavaScript library and it is possible that I will one day add JavaScript support, but since I use it very little in my own development, and since it looks like a lot of work, it is not a major priority for me. If you feel ambitious enough to add JavaScript support yourself, I would be happy to accept submissions. <A NAME="proxy"><H2>Can I use HttpUnit through a proxy server?</H2></A> -Yes. HttpUnit uses java.net.HttpURLConnection, so the +Yes. HttpUnit uses java.net.HttpURLConnection, so the <A HREF="http://www.javaworld.com/javaworld/javatips/jw-javatip42.html">normal Java way to use -proxies</A> will work. At some point HttpUnit may support this more directly, but for now, you will need to set the system properties yourself. +proxies</A> will work. At some point HttpUnit may support this more directly, but for now, you will need to set the system properties yourself. <A NAME="charset"><H2>Why isn't HttpUnit handling my non-English pages?</H2></A> -Older versions of HttpUnit (through 1.2) incorrectly assumed that all pages were in the default character set for the client platform. -As of version 1.2.1, HttpUnit correctly recognizes the charset parameter of the Content-type header which may +Older versions of HttpUnit (through 1.2) incorrectly assumed that all pages were in the default character set for the client platform. +As of version 1.2.1, HttpUnit correctly recognizes the charset parameter of the Content-type header which may specify an alternative character set; -when none is specified, HTML 1.1 says that the character set is to be taken as iso-8859-1. -Unfortunately, some HTTP servers do not send this parameter correctly, and many browsers incorrectly use this +when none is specified, HTML 1.1 says that the character set is to be taken as iso-8859-1. +Unfortunately, some HTTP servers do not send this parameter correctly, and many browsers incorrectly use this as an indication that they should determine the character set in some other fashion. To imitate this behavior, HttpUnit allows you to set the expected character -set for future pages by calling HttpUnitOptions.setDefaultCharacterSet(). This setting will not apply to those +set for future pages by calling HttpUnitOptions.setDefaultCharacterSet(). This setting will not apply to those pages for which the server specifies -the character set. +the character set. <p> Non-English form handling is supported as well. Any parameter values entered into a form will be encoded as the same character set as the document containing the form. The server code will then have to handle those characters @@ -67,20 +68,20 @@ <A NAME="utf8"><H2>HttpUnit fails with an IllegalArgumentException: sun.io.CharToByteUTF-8, what do I do?</H2></A> JTidy requires bytes, not characters, and HttpUnit 1.2.1 sends it bytes in UTF-8 -encoding, which it obtains from the input page +encoding, which it obtains from the input page using <code>getBytes( "UTF-8" )</code>. Unfortunately, Sun used the wrong -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. +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 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. +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 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 +This happens when you use HttpUnit and JTidy with one of the JUnit graphical test runners, which reloads classes every time to run a test. Unfortunately, this places different versions of the JTidy classes in different class loaders, so you get this error. To avoid it, you can do any of the following:<ul><li>Use only the text test runner</li> @@ -92,8 +93,14 @@ This will require extracting the file, modifying it and then putting it back <em>in the same directory</em>, but it should allow your tests to reload safely.</ul> +<A HREF="#badPost"><H2>Why doesn't my servlet see parameters on a POST request?</H2></A> +Some older servlet engines, such as Tomcat 3.1, get confused when they see a charset attribute on the Content-Type +header. HttpUnit normally sends this attribute; +however you can disable it by calling <code>HttpUnitOptions.setPostIncludesCharset(false)</code>. If you run into this +problem trying disabling the charset attribute. -</BODY></HTML> + +</BODY></HTML> Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.50 retrieving revision 1.51 diff -u -r1.50 -r1.51 --- release_notes.txt 2001/08/13 21:29:41 1.50 +++ release_notes.txt 2001/08/21 19:56:21 1.51 @@ -10,6 +10,14 @@ Revision History: +21-Aug-2001 +Acknowledgements: + Thanks to Richard Scothern for identiying the cause of problems with POST requests and older servlet engines. + + Additions: + 1. HttpUnitOptions now has a postIncludesCharset which can be set to false to interoperate with older servlet + engines, such as Tomcat 3.1, which cannot handle the charset attribute + 13-Aug-2001 Acknowledgements: Thanks to Brett Neumeier for some Javadoc fixes and adding support for the non-standard "Charset" header |
From: Russell G. <rus...@us...> - 2001-08-21 19:55:19
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv18285/src/com/meterware/servletunit Modified Files: ServletUnitServletContext.java Log Message: Hide package-local class Index: ServletUnitServletContext.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitServletContext.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ServletUnitServletContext.java 2001/06/18 20:21:30 1.2 +++ ServletUnitServletContext.java 2001/08/21 19:55:16 1.3 @@ -33,9 +33,9 @@ /** - * This class acts as a test environment for servlets. + * This class is a private implementation of the ServletContext class. **/ -public class ServletUnitServletContext implements ServletContext { +class ServletUnitServletContext implements ServletContext { /** * Returns a ServletContext object that corresponds to a specified URL on the server. |
From: Russell G. <rus...@us...> - 2001-08-13 21:29:44
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv30155/src/com/meterware/httpunit Modified Files: WebRequest.java WebResponse.java Log Message: Added support for Charset header Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- WebRequest.java 2001/07/31 16:08:59 1.22 +++ WebRequest.java 2001/08/13 21:29:41 1.23 @@ -95,7 +95,8 @@ /** * Returns the value of a parameter in this web request. - * @return the value of the named parameter, or null if it is not set. + * @return the value of the named parameter, or empty string + * if it is not set. **/ public String getParameter( String name ) { Object value = _parameters.get( name ); Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.44 retrieving revision 1.45 diff -u -r1.44 -r1.45 --- WebResponse.java 2001/08/08 19:18:13 1.44 +++ WebResponse.java 2001/08/13 21:29:41 1.45 @@ -142,6 +142,7 @@ public String getCharacterSet() { if (_characterSet == null) { readContentTypeHeader(); + if (_characterSet == null) _characterSet = getHeaderField( "Charset" ); if (_characterSet == null) _characterSet = HttpUnitOptions.getDefaultCharacterSet(); } return _characterSet; |
From: Russell G. <rus...@us...> - 2001-08-13 21:29:44
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv30155/doc Modified Files: release_notes.txt Log Message: Added support for Charset header Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.49 retrieving revision 1.50 diff -u -r1.49 -r1.50 --- release_notes.txt 2001/08/08 19:18:12 1.49 +++ release_notes.txt 2001/08/13 21:29:41 1.50 @@ -10,6 +10,13 @@ Revision History: +13-Aug-2001 +Acknowledgements: + Thanks to Brett Neumeier for some Javadoc fixes and adding support for the non-standard "Charset" header + + Additions: + 1. Now recognizes a Charset header if no charset is specified in the Content-type header. + 8-Aug-2001 Acknowledgements: Thanks to Dave Glowacki for the default content-type code. |
From: Russell G. <rus...@us...> - 2001-08-08 19:18:17
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv2695/src/com/meterware/httpunit Modified Files: HttpUnitOptions.java WebResponse.java Log Message: Added defaultContentType to HttpUnitOptions Index: HttpUnitOptions.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- HttpUnitOptions.java 2001/07/17 12:50:47 1.8 +++ HttpUnitOptions.java 2001/08/08 19:18:12 1.9 @@ -22,16 +22,33 @@ /** - * A collection of global options to control testing. + * A collection of global options to control HttpUnit's behavior. * - * @author Russell Gold + * @author <a href="mailto:rus...@ac...">Russell Gold</a> + * @author <a href="mailto:dg...@ss...">Dave Glowacki</a> **/ abstract public class HttpUnitOptions { + /** + * Resets all options to their default values. + */ + public static void reset() { + _parserWarningsEnabled = false; + _exceptionsOnErrorStatus = true; + _parameterValuesValidated = true; + _imagesTreatedAsAltText = false; + _loggingHttpHeaders = false; + _matchesIgnoreCase = true; + _autoRefresh = false; + _redirectDelay = 0; + _characterSet = DEFAULT_CHARACTER_SET; + _contentType = DEFAULT_CONTENT_TYPE; + } + /** - * Resets the default character set to the platform default encoding. + * Resets the default character set to the HTTP default encoding. **/ public static void resetDefaultCharacterSet() { _characterSet = DEFAULT_CHARACTER_SET; @@ -39,6 +56,14 @@ /** + * Resets the default content type to plain text. + **/ + public static void resetDefaultContentType() { + _contentType = DEFAULT_CONTENT_TYPE; + } + + + /** * Sets the default character set for pages which do not specify one. By default, HttpUnit uses the platform * default encoding. **/ @@ -56,6 +81,22 @@ /** + * Sets the default content type for pages which do not specify one. + **/ + public static void setDefaultContentType( String contentType ) { + _contentType = contentType; + } + + + /** + * Returns the content type to be used for pages which do not specify one. + **/ + public static String getDefaultContentType() { + return _contentType; + } + + + /** * Returns true if parser warnings are enabled. **/ public static boolean getParserWarningsEnabled() { @@ -196,26 +237,12 @@ } -//------------------------------ 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 String DEFAULT_CONTENT_TYPE = "text/plain"; + private static String DEFAULT_CONTENT_HEADER = DEFAULT_CONTENT_TYPE; + private static String DEFAULT_CHARACTER_SET = "iso-8859-1"; private static boolean _parserWarningsEnabled; @@ -235,5 +262,6 @@ private static String _characterSet = DEFAULT_CHARACTER_SET; + private static String _contentType = DEFAULT_CONTENT_TYPE; } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.43 retrieving revision 1.44 diff -u -r1.43 -r1.44 --- WebResponse.java 2001/07/31 16:08:59 1.43 +++ WebResponse.java 2001/08/08 19:18:13 1.44 @@ -54,6 +54,7 @@ * * @author <a href="mailto:rus...@ac...">Russell Gold</a> * @author <a href="mailto:DRE...@or...">Drew Varner</a> + * @author <a href="mailto:dg...@ss...">Dave Glowacki</a> **/ abstract public class WebResponse implements HTMLSegment { @@ -130,10 +131,7 @@ * Returns the content type of this response. **/ public String getContentType() { - if (_contentType == null) { - readContentTypeHeader(); - if (_contentType == null) _contentType = DEFAULT_CONTENT_TYPE; - } + if (_contentType == null) readContentTypeHeader(); return _contentType; } @@ -445,9 +443,6 @@ **/ final private static int IETF_RFC2965 = 1; - final private static String DEFAULT_CONTENT_TYPE = "text/plain"; - final private static String DEFAULT_CONTENT_HEADER = DEFAULT_CONTENT_TYPE; - final private static String HTML_CONTENT = "text/html"; private WebFrame[] _frames; @@ -686,10 +681,15 @@ private void readContentTypeHeader() { String contentHeader = (_contentHeader != null) ? _contentHeader : getHeaderField( "Content-type" ); - if (contentHeader == null) contentHeader = DEFAULT_CONTENT_HEADER; - String[] parts = HttpUnitUtils.parseContentTypeHeader( contentHeader ); - _contentType = parts[0]; - if (parts[1] != null) _characterSet = parts[1]; + if (contentHeader == null) { + _contentType = HttpUnitOptions.getDefaultContentType(); + _characterSet = HttpUnitOptions.getDefaultCharacterSet(); + _contentHeader = _contentType + ";charset=" + _characterSet; + } else { + String[] parts = HttpUnitUtils.parseContentTypeHeader( contentHeader ); + _contentType = parts[0]; + if (parts[1] != null) _characterSet = parts[1]; + } } |
From: Russell G. <rus...@us...> - 2001-08-08 19:18:17
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv2695/doc Modified Files: release_notes.txt Log Message: Added defaultContentType to HttpUnitOptions Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.48 retrieving revision 1.49 diff -u -r1.48 -r1.49 --- release_notes.txt 2001/08/06 20:19:41 1.48 +++ release_notes.txt 2001/08/08 19:18:12 1.49 @@ -10,6 +10,14 @@ Revision History: + 8-Aug-2001 +Acknowledgements: + Thanks to Dave Glowacki for the default content-type code. + + Additions: + 1. HttpUnitOptions.setDefaultContentType() lets you define a content-type to use when the web server does not + supply a Content-Type header. + 2-Aug-2001 Problems Corrected: 1. Set-Cookie headers are now processed even on responses with 4xx and 5xx status |
From: Russell G. <rus...@us...> - 2001-08-06 20:19:44
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv18857/test/com/meterware/httpunit Modified Files: FormParametersTest.java HttpUnitTest.java WebFormTest.java Log Message: Return option values in HTML order Index: FormParametersTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormParametersTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- FormParametersTest.java 2000/10/31 19:54:15 1.4 +++ FormParametersTest.java 2001/08/06 20:19:41 1.5 @@ -156,6 +156,7 @@ WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); WebRequest request = page.getForms()[0].getRequest(); HttpUnitOptions.setParameterValuesValidated( true ); + assertEquals( "color options", new String[] { "red", "blue", "green" }, page.getForms()[0].getOptionValues( "color" ) ); request.setParameter( "color", "red" ); request.setParameter( "color", "blue" ); validateSetParameterRejected( request, "color", "black", "setting radio buttons to unknown value" ); Index: HttpUnitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitTest.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- HttpUnitTest.java 2001/07/17 12:50:47 1.14 +++ HttpUnitTest.java 2001/08/06 20:19:41 1.15 @@ -98,6 +98,24 @@ } + protected void assertEquals( String comment, Object[] expected, Object[] found ) { + if (!equals( expected, found )) { + fail( comment + " expected: " + asText( expected ) + " but found " + asText( found ) ); + } + } + + private boolean equals( Object[] first, Object[] second ) + { + if (first.length != second.length) return false; + for (int i = 0; i < first.length; i++) + { + if (!first[i].equals( second[i] )) return false; + } + return true; + } + + + protected void assertMatchingSet( String comment, Object[] expected, Object[] found ) { Vector expectedItems = new Vector(); Index: WebFormTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- WebFormTest.java 2001/06/11 21:21:09 1.11 +++ WebFormTest.java 2001/08/06 20:19:41 1.12 @@ -222,7 +222,7 @@ assertEquals( "parameter name", "colors", parameterNames[0] ); assertMatchingSet( "Select defaults", new String[] { "red", "pink" }, form.getParameterValues( "colors" ) ); assertMatchingSet( "Select options", new String[] { "blue", "red", "green", "salmon" }, form.getOptions( "colors" ) ); - assertMatchingSet( "Select values", new String[] { "blue", "red", "green", "pink" }, form.getOptionValues( "colors" ) ); + assertEquals( "Select values", new String[] { "blue", "red", "green", "pink" }, form.getOptionValues( "colors" ) ); WebRequest request = form.getRequest(); assertMatchingSet( "Request defaults", new String[] { "red", "pink" }, request.getParameterValues( "colors" ) ); assertEquals( "URL", getHostPath() + "/ask?colors=red&colors=pink", request.getURL().toExternalForm() ); |
From: Russell G. <rus...@us...> - 2001-08-06 20:19:44
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv18857/doc Modified Files: release_notes.txt Log Message: Return option values in HTML order Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.47 retrieving revision 1.48 diff -u -r1.47 -r1.48 --- release_notes.txt 2001/07/31 16:08:59 1.47 +++ release_notes.txt 2001/08/06 20:19:41 1.48 @@ -10,6 +10,11 @@ Revision History: + 2-Aug-2001 + Problems Corrected: + 1. Set-Cookie headers are now processed even on responses with 4xx and 5xx status + 2. WebForm.getOptionValues now returns the options in the order listed in the form for both selections and radio buttons. + 31-Jul-2001 Additions: 1. Added ID property to SubmitButton and WebLink @@ -35,7 +40,7 @@ invoking getText or reading the input stream. Additions: - 1. The Set_Cookie2 header is now handled + 1. The Set-Cookie2 header is now handled 19-Jul-2001 Additions: |
From: Russell G. <rus...@us...> - 2001-08-06 20:19:44
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv18857/src/com/meterware/httpunit Modified Files: WebClient.java WebForm.java Log Message: Return option values in HTML order Index: WebClient.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- WebClient.java 2001/07/17 12:50:47 1.8 +++ WebClient.java 2001/08/06 20:19:41 1.9 @@ -97,7 +97,7 @@ * Defines a cookie to be sent to the server on every request. **/ public void addCookie( String name, String value ) { - _cookies.put( name, value ); + _cookies.put( name, value ); } @@ -216,8 +216,8 @@ **/ final protected void updateClient( WebResponse response ) throws MalformedURLException, IOException, SAXException { - validateHeaders( response ); updateCookies( response ); + validateHeaders( response ); if (HttpUnitOptions.getAutoRefresh() && response.getRefreshRequest() != null) { getResponse( response.getRefreshRequest() ); } else if (response.getHeaderField( "Location" ) == null) { Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- WebForm.java 2001/07/31 16:08:59 1.24 +++ WebForm.java 2001/08/06 20:19:41 1.25 @@ -503,8 +503,8 @@ **/ private String[] withNewValue( String[] group, String value ) { String[] result = new String[ group.length+1 ]; - System.arraycopy( group, 0, result, 1, group.length ); - result[0] = value; + System.arraycopy( group, 0, result, 0, group.length ); + result[ group.length ] = value; return result; } |
From: Russell G. <rus...@us...> - 2001-07-31 16:09:02
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv10743/test/com/meterware/httpunit Modified Files: FileUploadTest.java FormSubmitTest.java PseudoServerTest.java WebFrameTest.java WebLinkTest.java Log Message: Minor feature additions and bug fixes Index: FileUploadTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FileUploadTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- FileUploadTest.java 2001/06/11 21:21:09 1.6 +++ FileUploadTest.java 2001/07/31 16:08:59 1.7 @@ -164,6 +164,24 @@ } + public void testInputStreamAsFile() throws Exception { + ByteArrayInputStream bais = new ByteArrayInputStream( "Not much text\nBut two lines\n".getBytes() ); + + defineResource( "ListParams", new MimeEcho() ); + defineWebPage( "Default", "<form method=POST action = \"ListParams\" enctype=\"multipart/form-data\"> " + + "<Input type=file name=message>" + + "<Input type=submit name=update value=age>" + + "</form>" ); + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( getHostPath() + "/Default.html" ); + WebResponse simplePage = wc.getResponse( request ); + WebRequest formSubmit = simplePage.getForms()[0].getRequest(); + formSubmit.selectFile( "message", "temp.txt", bais, "text/plain" ); + WebResponse encoding = wc.getResponse( formSubmit ); + assertEquals( "update=age&text/plain:message.name=temp.txt&message.lines=2", encoding.getText().trim() ); + } + + public void testFileContentType() throws Exception { File file = new File( "temp.gif" ); FileOutputStream fos = new FileOutputStream( file ); Index: FormSubmitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormSubmitTest.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- FormSubmitTest.java 2001/07/17 12:50:47 1.9 +++ FormSubmitTest.java 2001/07/31 16:08:59 1.10 @@ -81,6 +81,19 @@ } + public void testFormProperties() throws Exception { + defineWebPage( "Default", "<form method=GET action = \"/ask\">" + + "<Input type=text name=age value=12>" + + "<select name=empty></select>" + + "<Input type=submit>" + + "</form>" ); + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + WebForm form = page.getForms()[0]; + assertEquals( "Form method", "GET", form.getMethod() ); + assertEquals( "Form action", "/ask", form.getAction() ); + } + + public void testSubmitString() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=age>" + @@ -118,6 +131,23 @@ } + public void testButtonIDDetection() throws Exception { + defineWebPage( "Default", "<form method=GET action = \"/ask\">" + + "<Input type=text name=age value=12>" + + "<Input type=submit id=main name=update>" + + "<Input type=submit name=recalculate>" + + "</form>" ); + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + WebForm form = page.getForms()[0]; + SubmitButton button = form.getSubmitButton( "update" ); + assertEquals( "Null ID", "", form.getSubmitButton( "recalculate" ).getID() ); + assertEquals( "Button ID", "main", button.getID() ); + + SubmitButton button2 = form.getSubmitButtonWithID( "main" ); + assertEquals( "Submit button", button, button2 ); + } + + public void testButtonTagDetection() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=age value=12>" + Index: PseudoServerTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServerTest.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- PseudoServerTest.java 2001/07/23 03:05:30 1.15 +++ PseudoServerTest.java 2001/07/31 16:08:59 1.16 @@ -191,6 +191,7 @@ ps.addResourceHeader( resourceName, "Set-Cookie: age=12, name=george" ); ps.addResourceHeader( resourceName, "Set-Cookie: type=short" ); ps.addResourceHeader( resourceName, "Set-Cookie: funky=ab$==" ); + ps.addResourceHeader( resourceName, "Set-Cookie: p30waco_sso=3.0,en,us,AMERICA,Drew;path=/, PORTAL30_SSO_TEST=X" ); try { WebConversation wc = new WebConversation(); @@ -198,11 +199,13 @@ WebResponse response = wc.getResponse( request ); assertEquals( "requested resource", resourceValue, response.getText().trim() ); assertEquals( "content type", "text/html", response.getContentType() ); - assertEquals( "number of cookies", 4, wc.getCookieNames().length ); + assertEquals( "number of cookies", 6, wc.getCookieNames().length ); assertEquals( "cookie 'age' value", "12", wc.getCookieValue( "age" ) ); assertEquals( "cookie 'name' value", "george", wc.getCookieValue( "name" ) ); assertEquals( "cookie 'type' value", "short", wc.getCookieValue( "type" ) ); assertEquals( "cookie 'funky' value", "ab$==", wc.getCookieValue( "funky" ) ); + assertEquals( "cookie 'p30waco_sso' value", "3.0,en,us,AMERICA,Drew", wc.getCookieValue( "p30waco_sso" ) ); + assertEquals( "cookie 'PORTAL30_SSO_TEST' value", "X", wc.getCookieValue( "PORTAL30_SSO_TEST" ) ); } finally { ps.shutDown(); } Index: WebFrameTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFrameTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- WebFrameTest.java 2001/06/13 16:38:20 1.6 +++ WebFrameTest.java 2001/07/31 16:08:59 1.7 @@ -219,7 +219,7 @@ } - public void testSelfTarget() throws Exception { + public void testSelfTargetLink() throws Exception { defineWebPage( "Linker", "This is a trivial page with <a href=Target.html target=_self>one link</a>" ); _wc.getResponse( getHostPath() + "/Frames.html" ); @@ -230,6 +230,19 @@ } + public void testSelfTargetForm() throws Exception { + defineWebPage( "Linker", "<form action=redirect.html target=_self><input type=text name=sample value=z></form>" ); + defineResource( "redirect.html?sample=z", "" ); + addResourceHeader( "redirect.html?sample=z", "Location: " + getHostPath() + "/Target.html" ); + + _wc.getResponse( getHostPath() + "/Frames.html" ); + WebResponse response = _wc.getResponse( _wc.getFrameContents( "red" ).getForms()[0].getRequest() ); + assertMatchingSet( "Frames defined for the conversation", new String[] { "_top", "red", "blue" }, _wc.getFrameNames() ); + assert( "Second response not the same as source frame contents", response == _wc.getFrameContents( "red" ) ); + assertEquals( "URL for second request", getHostPath() + "/Target.html", response.getURL().toExternalForm() ); + } + + public void testSubFrameRedirect() throws Exception { defineResource( "Linker.html", "" ); addResourceHeader( "Linker.html", "Location: " + getHostPath() + "/Target.html" ); Index: WebLinkTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebLinkTest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- WebLinkTest.java 2001/06/11 21:21:09 1.8 +++ WebLinkTest.java 2001/07/31 16:08:59 1.9 @@ -176,6 +176,25 @@ } + public void testImageMapLinks() throws Exception { + WebConversation wc = new WebConversation(); + defineWebPage( "pageWithMap", "Here is a page with <a href=\"somewhere\">a link</a>" + + " and a map: <IMG src=\"navbar1.gif\" usemap=\"#map1\" alt=\"navigation bar\">" + + "<map name=\"map1\">" + + " <area href=\"guide.html\" alt=\"Guide\" shape=\"rect\" coords=\"0,0,118,28\">" + + " <area href=\"search.html\" alt=\"Search\" shape=\"circle\" coords=\"184,200,60\">" + + "</map>" ); + WebResponse mapPage = wc.getResponse( getHostPath() + "/pageWithMap.html" ); + WebLink[] links = mapPage.getLinks(); + assertEquals( "number of links found", 3, links.length ); + + WebLink guide = mapPage.getLinkWith( "Guide" ); + assertNotNull( "Did not find the guide area", guide ); + assertEquals( "Relative URL", "guide.html", guide.getURLString() ); + } + + + private WebResponse _simplePage; |
From: Russell G. <rus...@us...> - 2001-07-31 16:09:02
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv10743/src/com/meterware/httpunit Modified Files: MimeEncodedMessageBody.java NodeUtils.java ParsedHTML.java PostMethodWebRequest.java SubmitButton.java WebForm.java WebLink.java WebRequest.java WebResponse.java Added Files: WebRequestSource.java Log Message: Minor feature additions and bug fixes ***** Error reading new file[Errno 2] No such file or directory: 'WebRequestSource.java' Index: MimeEncodedMessageBody.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/MimeEncodedMessageBody.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- MimeEncodedMessageBody.java 2001/06/06 13:25:33 1.7 +++ MimeEncodedMessageBody.java 2001/07/31 16:08:59 1.8 @@ -19,9 +19,9 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ -import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; +import java.io.InputStream; import java.net.URLConnection; @@ -77,11 +77,11 @@ String name = (String) e.nextElement(); WebRequest.UploadFileSpec spec = (WebRequest.UploadFileSpec) files.get( name ); writeLn( outputStream, "--" + BOUNDARY ); - writeLn( outputStream, "Content-Disposition: form-data; name=\"" + encode( name ) + "\"; filename=\"" + encode( spec.getFile().getAbsolutePath() ) + '"' ); // XXX need to handle non-ascii names here + writeLn( outputStream, "Content-Disposition: form-data; name=\"" + encode( name ) + "\"; filename=\"" + encode( spec.getFileName() ) + '"' ); // XXX need to handle non-ascii names here writeLn( outputStream, "Content-Type: " + spec.getContentType() ); writeLn( outputStream, "" ); - FileInputStream in = new FileInputStream( spec.getFile() ); + InputStream in = spec.getInputStream(); byte[] buffer = new byte[8 * 1024]; int count = 0; do { Index: NodeUtils.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/NodeUtils.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- NodeUtils.java 2000/10/04 15:45:47 1.5 +++ NodeUtils.java 2001/07/31 16:08:59 1.6 @@ -55,9 +55,14 @@ public static String getNodeAttribute( Node node, String attributeName ) { + return getNodeAttribute( node, attributeName, "" ); + } + + + public static String getNodeAttribute( Node node, String attributeName, String defaultValue ) { NamedNodeMap nnm = node.getAttributes(); Node attribute = nnm.getNamedItem( attributeName ); - return (attribute == null) ? "" : attribute.getNodeValue(); + return (attribute == null) ? defaultValue : attribute.getNodeValue(); } Index: ParsedHTML.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- ParsedHTML.java 2001/06/13 16:38:20 1.16 +++ ParsedHTML.java 2001/07/31 16:08:59 1.17 @@ -81,14 +81,9 @@ **/ public WebLink[] getLinks() { if (_links == null) { - NodeList nl = NodeUtils.getElementsByTagName( _rootNode, "a" ); Vector list = new Vector(); - for (int i = 0; i < nl.getLength(); i++) { - Node child = nl.item(i); - if (isLinkAnchor( child )) { - list.addElement( new WebLink( _baseURL, _baseTarget, child ) ); - } - } + addLinkAnchors( list, NodeUtils.getElementsByTagName( _rootNode, "a" ) ); + addLinkAnchors( list, NodeUtils.getElementsByTagName( _rootNode, "area" ) ); _links = new WebLink[ list.size() ]; list.copyInto( _links ); } @@ -97,20 +92,28 @@ } + private void addLinkAnchors(Vector list, NodeList nl) { + for (int i = 0; i < nl.getLength(); i++) { + Node child = nl.item(i); + if (isLinkAnchor( child )) { + list.addElement( new WebLink( _baseURL, _baseTarget, child ) ); + } + } + } + + /** * Returns the first link which contains the specified text. **/ public WebLink getLinkWith( String text ) { WebLink[] links = getLinks(); for (int i = 0; i < links.length; i++) { - String linkText = NodeUtils.asText( links[i].getDOMSubtree().getChildNodes() ); - if (contains( linkText, text )) return links[i]; + if (contains( links[i].asText(), text )) return links[i]; } return null; } - /** * Returns the first link which contains an image with the specified text as its 'alt' attribute. **/ @@ -304,7 +307,7 @@ private boolean isLinkAnchor( Node node ) { if (node.getNodeType() != Node.ELEMENT_NODE) { return false; - } else if (!node.getNodeName().equals( "a" )) { + } else if (!node.getNodeName().equals( "a" ) && !node.getNodeName().equals( "area" )) { return false; } else { return (node.getAttributes().getNamedItem( "href" ) != null); Index: PostMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/PostMethodWebRequest.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- PostMethodWebRequest.java 2001/06/06 13:25:33 1.14 +++ PostMethodWebRequest.java 2001/07/31 16:08:59 1.15 @@ -96,6 +96,16 @@ } + /** + * Sets the file for a parameter upload in a web request. + **/ + public void selectFile( String parameterName, String fileName, InputStream inputStream, String contentType ) { + super.selectFile( parameterName, fileName, inputStream, contentType ); + + _files.put( parameterName, new UploadFileSpec( fileName, inputStream, contentType ) ); + } + + //----------------------------- MessageBodyWebRequest methods --------------------------- Index: SubmitButton.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/SubmitButton.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SubmitButton.java 2000/11/02 18:37:37 1.2 +++ SubmitButton.java 2001/07/31 16:08:59 1.3 @@ -50,6 +50,15 @@ /** + * Returns the ID associated with the button, if any. + * @return the button ID, or an empty string if no ID is defined. + **/ + public String getID() { + return NodeUtils.getNodeAttribute( _node, "id" ); + } + + + /** * Returns true if this submit button is an image map. **/ public boolean isImageButton() { Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- WebForm.java 2001/07/17 12:50:12 1.23 +++ WebForm.java 2001/07/31 16:08:59 1.24 @@ -30,22 +30,26 @@ * defined for the form, the structure of the form (as a DOM), or the text of the form. They * may also create a {@link WebRequest} to simulate the submission of the form. **/ -public class WebForm { +public class WebForm extends WebRequestSource { /** - * Returns the target for this form. + * Returns the method defined for this form. **/ - public String getTarget() { - if (_node.getAttributes().getNamedItem( "target" ) == null) { - return _parentTarget; - } else { - return getValue( _node.getAttributes().getNamedItem( "target" ) ); - } + public String getMethod() { + return NodeUtils.getNodeAttribute( getNode(), "method", "GET" ); } /** + * Returns the action defined for this form. + **/ + public String getAction() { + return NodeUtils.getNodeAttribute( getNode(), "action" ); + } + + + /** * Returns the character set encoding for this form. **/ public String getCharacterSet() { @@ -57,19 +61,11 @@ * Returns the name of the form. **/ public String getName() { - return emptyIfNull( getValue( _node.getAttributes().getNamedItem( "name" ) ) ); + return NodeUtils.getNodeAttribute( getNode(), "name" ); } /** - * Returns the ID associated with the form. - **/ - public String getID() { - return emptyIfNull( getValue( _node.getAttributes().getNamedItem( "id" ) ) ); - } - - - /** * Returns an array containing the names of the parameters defined for this form, * in the order in which they appear. **/ @@ -118,7 +114,7 @@ if (_buttonVector == null) { _buttonVector = new Vector(); - NodeList nl = ((Element) _node).getElementsByTagName( "input" ); + NodeList nl = ((Element) getNode()).getElementsByTagName( "input" ); for (int i = 0; i < nl.getLength(); i++) { if (NodeUtils.getNodeAttribute( nl.item(i), "type" ).equalsIgnoreCase( "submit" ) || NodeUtils.getNodeAttribute( nl.item(i), "type" ).equalsIgnoreCase( "image" )) { @@ -126,7 +122,7 @@ } } - nl = ((Element) _node).getElementsByTagName( "button" ); + nl = ((Element) getNode()).getElementsByTagName( "button" ); for (int i = 0; i < nl.getLength(); i++) { if (NodeUtils.getNodeAttribute( nl.item(i), "type" ).equalsIgnoreCase( "submit" ) || NodeUtils.getNodeAttribute( nl.item(i), "type" ).equalsIgnoreCase( "" )) { @@ -172,6 +168,22 @@ /** + * Returns the submit button defined in this form with the specified ID. + * If more than one such button exists, will return the first found. + * If no such button is found, will return null. + **/ + public SubmitButton getSubmitButtonWithID( String ID ) { + SubmitButton[] buttons = getSubmitButtons(); + for (int i = 0; i < buttons.length; i++) { + if (buttons[i].getID().equals( ID )) { + return buttons[i]; + } + } + return null; + } + + + /** * Creates and returns a web request which will simulate the submission of this form with an unnamed submit button. **/ public WebRequest getRequest() { @@ -236,18 +248,18 @@ } } - NamedNodeMap nnm = _node.getAttributes(); + NamedNodeMap nnm = getNode().getAttributes(); String action = getValue( nnm.getNamedItem( "action" ) ); if (action.trim().length() == 0) { - action = this._baseURL.getFile(); + action = getBaseURL().getFile(); } WebRequest result; if (getValue( nnm.getNamedItem( "method" ) ).equalsIgnoreCase( "post" )) { - result = new PostMethodWebRequest( _baseURL, action, getTarget(), this, button ); + result = new PostMethodWebRequest( getBaseURL(), action, getTarget(), this, button ); } else { - result = new GetMethodWebRequest( _baseURL, action, getTarget(), this, button ); + result = new GetMethodWebRequest( getBaseURL(), action, getTarget(), this, button ); } String[] parameterNames = getParameterNames(); @@ -261,7 +273,7 @@ } } } - result.setRequestHeader( "Referer", _baseURL.toExternalForm() ); + result.setRequestHeader( "Referer", getBaseURL().toExternalForm() ); return result; } @@ -336,18 +348,10 @@ * Returns true if this form is to be submitted using mime encoding (the default is URL encoding). **/ public boolean isSubmitAsMime() { - return "multipart/form-data".equalsIgnoreCase( NodeUtils.getNodeAttribute( _node, "enctype" ) ); + return "multipart/form-data".equalsIgnoreCase( NodeUtils.getNodeAttribute( getNode(), "enctype" ) ); } - /** - * Returns a copy of the domain object model subtree associated with this form. - **/ - public Node getDOMSubtree() { - return _node.cloneNode( /* deep */ true ); - } - - //---------------------------------- package members -------------------------------- /** @@ -355,9 +359,7 @@ * from that page. **/ WebForm( URL baseURL, String parentTarget, Node node, String characterSet ) { - _node = node; - _baseURL = baseURL; - _parentTarget = parentTarget; + super( node, baseURL, parentTarget ); _characterSet = characterSet; } @@ -377,12 +379,6 @@ private final static Integer TYPE_FILE = new Integer(4); - /** The URL of the page containing this form. **/ - private URL _baseURL; - - /** The DOM node representing the form. **/ - private Node _node; - /** The attributes of the form parameters. **/ private NamedNodeMap[] _parameters; @@ -398,9 +394,6 @@ /** The parameters mapped to the type of data which they accept. **/ private Hashtable _dataTypes; - /** The target in which the parent response is to be rendered. **/ - private String _parentTarget; - /** The submit buttons in this form. **/ private SubmitButton[] _submitButtons; @@ -505,6 +498,9 @@ } + /** + * Adds a string to an array of strings and returns the result. + **/ private String[] withNewValue( String[] group, String value ) { String[] result = new String[ group.length+1 ]; System.arraycopy( group, 0, result, 1, group.length ); @@ -551,7 +547,7 @@ **/ private HTMLSelectElement[] getSelections() { if (_selections == null) { - NodeList nl = ((Element) _node).getElementsByTagName( "select" ); + NodeList nl = ((Element) getNode()).getElementsByTagName( "select" ); HTMLSelectElement[] result = new HTMLSelectElement[ nl.getLength() ]; for (int i = 0; i < result.length; i++) { result[i] = new HTMLSelectElement( nl.item(i) ); @@ -566,7 +562,7 @@ **/ private HTMLTextAreaElement[] getTextAreas() { if (_textAreas == null) { - NodeList nl = ((Element) _node).getElementsByTagName( "textarea" ); + NodeList nl = ((Element) getNode()).getElementsByTagName( "textarea" ); HTMLTextAreaElement[] result = new HTMLTextAreaElement[ nl.getLength() ]; for (int i = 0; i < result.length; i++) { result[i] = new HTMLTextAreaElement( nl.item(i) ); @@ -582,7 +578,7 @@ private NamedNodeMap[] getParameters() { if (_parameters == null) { Vector list = new Vector(); - if (_node.hasChildNodes()) addFormParametersToList( _node.getChildNodes(), list ); + if (getNode().hasChildNodes()) addFormParametersToList( getNode().getChildNodes(), list ); _parameters = new NamedNodeMap[ list.size() ]; list.copyInto( _parameters ); } Index: WebLink.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- WebLink.java 2001/03/23 20:50:41 1.6 +++ WebLink.java 2001/07/31 16:08:59 1.7 @@ -2,27 +2,23 @@ import java.net.URL; -import java.util.Vector; - -import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; -import org.w3c.dom.NodeList; /** * This class represents a link in an HTML page. Users of this class may examine the * structure of the link (as a DOM), or create a {@tag WebRequest} to simulate clicking * on the link. **/ -public class WebLink { +public class WebLink extends WebRequestSource { /** * Creates and returns a web request which will simulate clicking on this link. **/ public WebRequest getRequest() { - WebRequest request = new GetMethodWebRequest( _baseURL, getURLString(), getTarget() ); - request.setRequestHeader( "Referer", _baseURL.toExternalForm() ); - return request; + WebRequest request = new GetMethodWebRequest( getBaseURL(), getURLString(), getTarget() ); + request.setRequestHeader( "Referer", getBaseURL().toExternalForm() ); + return request; } @@ -30,34 +26,7 @@ * Returns the URL referenced by this link. This may be a relative URL. **/ public String getURLString() { - return getValue( _node.getAttributes().getNamedItem( "href" ) ); - } - - - /** - * Returns the target for this link. - **/ - public String getTarget() { - if (getSpecifiedTarget().length() == 0) { - return _parentTarget; - } else if (getSpecifiedTarget().equalsIgnoreCase( "_self" )) { - return _parentTarget; - } else { - return getSpecifiedTarget(); - } - } - - - private String getSpecifiedTarget() { - return NodeUtils.getNodeAttribute( _node, "target" ); - } - - - /** - * Returns a copy of the domain object model subtree associated with this link. - **/ - public Node getDOMSubtree() { - return _node.cloneNode( /* deep */ true ); + return NodeUtils.getNodeAttribute( getNode(), "href" ); } @@ -65,10 +34,12 @@ * Returns the text value of this link. **/ public String asText() { - if (!_node.hasChildNodes()) { + if (getNode().getNodeName().equals( "area" )) { + return NodeUtils.getNodeAttribute( getNode(), "alt" ); + } else if (!getNode().hasChildNodes()) { return ""; } else { - return NodeUtils.asText( _node.getChildNodes() ); + return NodeUtils.asText( getNode().getChildNodes() ); } } @@ -81,30 +52,8 @@ * from that page. **/ WebLink( URL baseURL, String parentTarget, Node node ) { - if (node == null) throw new IllegalArgumentException( "node must not be null" ); - _node = node; - _baseURL = baseURL; - _parentTarget = parentTarget; + super( node, baseURL, parentTarget ); } - - -//---------------------------------- private members -------------------------------- - - - /** The URL of the page containing this link. **/ - private URL _baseURL; - - /** The DOM node representing the link. **/ - private Node _node; - - /** The target window to which the parent response was directed. **/ - private String _parentTarget; - - - private String getValue( Node node ) { - return (node == null) ? "" : node.getNodeValue(); - } - } Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- WebRequest.java 2001/06/04 20:45:33 1.21 +++ WebRequest.java 2001/07/31 16:08:59 1.22 @@ -64,7 +64,7 @@ /** - * Sets the file for a parameter upload in a web request. + * Sets the file for a parameter upload in a web request. **/ public void selectFile( String parameterName, File file, String contentType ) { if (_sourceForm == null || !_sourceForm.isFileParameter( parameterName )) { @@ -75,6 +75,17 @@ /** + * Sets the file for a parameter upload in a web request. + **/ + public void selectFile( String parameterName, String fileName, InputStream inputStream, String contentType ) { + if (_sourceForm == null || !_sourceForm.isFileParameter( parameterName )) { + throw new IllegalNonFileParameterException( parameterName ); + } + if (!isMimeEncoded()) throw new MultipartFormRequiredException(); + } + + + /** * Returns an enumeration of all parameters in this web request. **/ public Enumeration getParameterNames() { @@ -319,9 +330,27 @@ _contentType = contentType; } + + UploadFileSpec( String fileName, InputStream inputStream, String contentType ) { + _fileName = fileName; + _inputStream = inputStream; + _contentType = contentType; + } + + + InputStream getInputStream() throws IOException { + if (_inputStream == null) { + _inputStream = new FileInputStream( _file ); + } + return _inputStream; + } + - File getFile() { - return _file; + String getFileName() { + if (_fileName == null) { + _fileName = _file.getAbsolutePath(); + } + return _fileName; } @@ -330,6 +359,10 @@ } private File _file; + + private InputStream _inputStream; + + private String _fileName; private String _contentType = "text/plain"; Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- WebResponse.java 2001/07/26 18:48:11 1.42 +++ WebResponse.java 2001/07/31 16:08:59 1.43 @@ -547,23 +547,16 @@ * 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 ); - } + if (_newCookies == null) _newCookies = new Hashtable(); + processCookieHeader( getHeaderField( "Set-Cookie" ), IETF_RFC2109 ); + processCookieHeader( getHeaderField( "Set-Cookie2" ), IETF_RFC2965 ); return _newCookies; } - private void processCookieTokens(Vector tokens, - int version) { + private void processCookieHeader( String cookieHeader, int version ) { + if (cookieHeader == null) return; + Vector tokens = getCookieTokens(cookieHeader); // holds tokens that should be part of the value of // the first token before it that contains an // equals sign (=) @@ -623,8 +616,8 @@ st.wordChars(0,Character.MAX_VALUE); // set up characters for quoting - st.quoteChar(34); //double quotes - st.quoteChar(39); //single quotes + st.quoteChar( '"' ); //double quotes + st.quoteChar( '\'' ); //single quotes // set up characters to separate tokens st.whitespaceChars(59,59); //semicolon |
From: Russell G. <rus...@us...> - 2001-07-31 16:09:02
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv10743/doc Modified Files: release_notes.txt todo.txt Log Message: Minor feature additions and bug fixes Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.46 retrieving revision 1.47 diff -u -r1.46 -r1.47 --- release_notes.txt 2001/07/23 03:05:30 1.46 +++ release_notes.txt 2001/07/31 16:08:59 1.47 @@ -2,29 +2,41 @@ Known problems: 1. The "_parent" and "_empty" frame targets are not handled correctly - 2. The "_self" target only works for links, not forms - 3. The "accept-charset" attribute for forms is ignored; the page content character set is used to encode any response. + 2. The "accept-charset" attribute for forms is ignored; the page content character set is used to encode any response. This behavior matches that currently used by IE and Navigator. - 4. No order is guaranteed for parameters from forms, contrary to the HTML 4.01 spec + 3. No order is guaranteed for parameters from forms, contrary to the HTML 4.01 spec Limitations: HttpUnit does not support JavaScript Revision History: +31-Jul-2001 + Additions: + 1. Added ID property to SubmitButton and WebLink + 2. Added getSubmitButtonWithID to WebForm + 3. Added getMethod and getAction to WebForm + 4. Image map <area> tags are now recognized as links, whose text is equal to their 'alt' tag. This allows + them to be retrieved using getLinkWith( altText ). + 5. Added version of WebRequest.selectFile which allows clients to specify the file to upload using an input + stream rather than an actual file. + + Problems corrected: + 1. The _self target now works for forms. + 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 - + 19-Jul-2001 Additions: 1. Added getHeaderFieldNames to WebResponse @@ -39,14 +51,14 @@ 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 - + Additions: 1. WebResponse.getRefreshRequest now returns a WebRequest object if a refresh URL was specified in the response header. @@ -60,9 +72,9 @@ 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 +18-Jun-2001 1.2.5 Acknowledgements: Thanks to Rolf Schmidiger for corrected behavior when failing to find a site Thanks to Tom Watkins, Deepa Dihr, Marcos Tarruella for their implementation of @@ -85,7 +97,7 @@ 8. Added getInputStream method in WebResponse to support non-text responses. 9. Matching of text in web pages is now controlled by the HttpUnitOption property 'matchesIgnoreCase'. The default behavior is as before - matches are not case sensitive - + Problems corrected: 1. Now throws HttpNotFoundException rather than NullPointerException when unable to connect to a web site @@ -101,20 +113,20 @@ 5-May-01 1.2.4 Acknowledgements: Thanks to Jim Kimball for finding and fixing the redirection of subframes - + Problems corrected: 1. Redirection with subframes was incorrectly targeted at the top frame. 2. No longer capitalizes all header names; this was necessary for compatibility with those servers that do not understand case-insensitive header names. - 3. Repeated requests to the same URL were not resending requests properly. + 3. Repeated requests to the same URL were not resending requests properly. This caused some problems with validation. 4. Now correctly passes the full specification of uploaded files, rather than just the name. Additions: 1. Transmitted headers as well as received headers are now shown when loggingHttpHeaders is enabled. - 2. The GetMethodWebRequest and PostMethodWebRequest constructors which accept a target + 2. The GetMethodWebRequest and PostMethodWebRequest constructors which accept a target are now public. 3. Added getID to WebForm 4. Added getFormWithID to HTMLSegment interface @@ -123,7 +135,7 @@ 2-Apr-01 1.2.3 Acknowledgements: Thanks to Silvio Samadelli for improved cookie-recognition logic - + Problems corrected: 1. Under JDK 1.3, error headers would sometimes cause a FileNotFoundException 2. Cookies containing '=' or wrapped in quotes are now recognized @@ -143,23 +155,23 @@ Additions: 1. Initial implementation of file upload capability - + Problems corrected: 1. Multiple cookies were not being sent correctly 2. When a response was received with a bad response code, it was treated either as a RuntimeException or a file not found exception. 3. Creating a request from a form with an empty <select> tag was generating a SingleValuedParameterException. 4. Corrected IllegalArgumentException: sun.io.CharToByteUTF-8 that happened in JDK 1.1.x - + 01-Jan-01 1.2.1 Acknowledgements: Thanks to Toyoshi Ushio for helping with the handling of non-English scripts and for translating the home page and cookbook into Japanese. - + Problems corrected: 1. Content-type charset attribute is now recognized, allowing for the proper handling of non-ascii html pages. 2. Form submissions now use the page character set encoding. 3. Old format cookie headers (with the expires=attribute) are now recognized. - + Additions: 1. Introductory ServletUnit functionality (parameters and sessions, but no JSP, no forwarding) 2. Added getTableWithID method to WebResponse, ParsedHTML @@ -172,7 +184,7 @@ Acknowledgements: Thanks to Robert Krueger for providing an interface to the xerces parser for XML web responses. Thanks to Marco Tamanti and Gabriele Antonelli for suggesting ways to support file URLs - + Problems corrected: 1. Unnamed parameters are no longer submitted as part of a form request 2. Searching for tables beginning with a string no longer aborts with NullPointerException if the table is missing cells @@ -181,10 +193,10 @@ Additions: 1. Forms with multiple buttons are now supported, using the SubmitButton class. 2. WebResponse now supports finding a table via its summary text, using getTableWithSummary(). - 3. XML parsing is now supported. If WebResponse.getDOM is called for a non-HTML response (content type is not "text/html"), + 3. XML parsing is now supported. If WebResponse.getDOM is called for a non-HTML response (content type is not "text/html"), the xerces parser will be invoked to treat the response as XML. - 4. File URLs (file:xxx) are now supported - + 4. File URLs (file:xxx) are now supported + 17-Oct-00 1.1 Acknowledgements: Thanks to Seth Ladd for specific exceptions from WebConversation.getResponse @@ -193,7 +205,7 @@ Thanks to Perry Doell for the methods to examine cookies on WebConversation Thanks to Ken Hygh for the proper handling of parameters with no specified type Thanks to Gabriel Hauser for finding a bug in the handling of parameter defaults - + Problems corrected: 1. The value parameter for checkboxes is no longer ignored 2. Previously, getTableStartingWith[Prefix] only checked the nested tables in cell (0,0) of each outer table @@ -203,7 +215,7 @@ Additions: 1. The license agreement is now available from the home page and javadoc - 2. Https support is now built in; however, it depends on the JSSE extension (not included). + 2. Https support is now built in; however, it depends on the JSSE extension (not included). See http://java.sun.com/products/jsse. 3. Frames are now supported. The WebConversation method has two methods: getFrameNames and getFrameContents which allow manipulation of frames. @@ -217,10 +229,10 @@ 7. WebResponse.getTitle() returns the HTML title of the page 8. WebLink.getURLString() returns the URL string specified by the link in its href attribute 9. WebResponse.getURL() return the URL used to retrieve the page - 10. WebConversation now supports getCookieNames and getCookieValue to return the current cookies + 10. WebConversation now supports getCookieNames and getCookieValue to return the current cookies 11. The WebResponse now can return the response code associated with it (2xx) 12. Non-breaking spaces are converted to spaces on any conversion to text - + 1-Sep-00 1.0 @@ -258,13 +270,13 @@ 5. Added copyright notices to most source files 6. Added support for checkboxes, radio buttons, text areas, and selects - + 29-Jun-00 0.9.1 Additions: 1. The PostMethodWebRequest class is now public. 2. Row and column spans are now handled 3. Formatting inside table cells is ignored in computing the text value of a cell - + 19-Jun-00 0.9 Additions: 1. The parser may be tested during the build by issuing the command: 'ant test -Dclasspath="%classpath%"' @@ -285,6 +297,6 @@ ExampleTest now demonstrates the use of httpunit and JUnit to test servlets NearWords demonstrates the use of httpunit to access web site functionality -03-May-00 0.8 +03-May-00 0.8 Initial public release Index: todo.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/todo.txt,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- todo.txt 2001/07/17 12:50:47 1.15 +++ todo.txt 2001/07/31 16:08:59 1.16 @@ -1,8 +1,3 @@ -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 @@ -14,7 +9,6 @@ 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 |
From: Russell G. <rus...@us...> - 2001-07-26 18:48:14
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv22658/src/com/meterware/httpunit Modified Files: WebResponse.java Log Message: Removed tabs from file Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- WebResponse.java 2001/07/23 03:05:30 1.41 +++ WebResponse.java 2001/07/26 18:48:11 1.42 @@ -58,26 +58,6 @@ 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 * access to WebResponse parsing without using a WebClient. @@ -445,6 +425,26 @@ //--------------------------------- private members -------------------------------------- + /** + * 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 + **/ + final private static 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 + **/ + final private static int IETF_RFC2965 = 1; + final private static String DEFAULT_CONTENT_TYPE = "text/plain"; final private static String DEFAULT_CONTENT_HEADER = DEFAULT_CONTENT_TYPE; @@ -529,165 +529,165 @@ } } + + /** + * 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 = ""; + } - /** - * 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; - } + 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 readContentTypeHeader() { |