httpunit-commit Mailing List for httpunit (Page 76)
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-04-05 22:16:09
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv20682/src/com/meterware/httpunit Modified Files: WebClient.java WebConversation.java WebRequest.java Log Message: Use nominal header capitalization Index: WebClient.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- WebClient.java 2001/04/03 16:49:08 1.4 +++ WebClient.java 2001/04/05 22:16:07 1.5 @@ -161,11 +161,25 @@ * removes the header from those to be sent. **/ public void setHeaderField( String fieldName, String fieldValue ) { + fieldName = matchPreviousFieldName( fieldName ); if (fieldValue == null) { - _headers.remove( fieldName.toUpperCase() ); + _headers.remove( fieldName ); } else { - _headers.put( fieldName.toUpperCase(), fieldValue ); + _headers.put( fieldName, fieldValue ); } + } + + + /** + * If a matching field name with different case is already known, returns the older name. + * Otherwise, returns the specified name. + **/ + private String matchPreviousFieldName( String fieldName ) { + for (Enumeration e = _headers.keys(); e.hasMoreElements(); ) { + String key = (String) e.nextElement(); + if (key.equalsIgnoreCase( fieldName )) return key; + } + return fieldName; } Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- WebConversation.java 2001/03/23 20:50:41 1.19 +++ WebConversation.java 2001/04/05 22:16:07 1.20 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000, Russell Gold +* Copyright (c) 2000-2001, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- WebRequest.java 2001/04/03 16:49:08 1.17 +++ WebRequest.java 2001/04/05 22:16:07 1.18 @@ -267,7 +267,7 @@ void setRequestHeader( String headerName, String headerValue ) { - _headers.put( headerName.toUpperCase(), headerValue ); + _headers.put( headerName, headerValue ); } |
From: Russell G. <rus...@us...> - 2001-04-05 22:16:09
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv20682/doc Modified Files: release_notes.txt Log Message: Use nominal header capitalization Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- release_notes.txt 2001/04/03 16:49:08 1.25 +++ release_notes.txt 2001/04/05 22:16:06 1.26 @@ -17,6 +17,9 @@ 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. 2-Apr-01 1.2.3 Acknowledgements: |
From: Russell G. <rus...@us...> - 2001-04-03 16:49:12
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv19605/test/com/meterware/httpunit Modified Files: HttpUnitSuite.java HttpUnitTest.java WebFrameTest.java Log Message: Handle redirection in subframes Index: HttpUnitSuite.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitSuite.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- HttpUnitSuite.java 2001/04/02 19:03:54 1.12 +++ HttpUnitSuite.java 2001/04/03 16:49:08 1.13 @@ -40,6 +40,7 @@ suite.addTest( WebLinkTest.suite() ); suite.addTest( HtmlTablesTest.suite() ); suite.addTest( WebFormTest.suite() ); + suite.addTest( WebFrameTest.suite() ); suite.addTest( RequestTargetTest.suite() ); suite.addTest( FormParametersTest.suite() ); suite.addTest( FormSubmitTest.suite() ); Index: HttpUnitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitTest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- HttpUnitTest.java 2001/03/20 23:35:43 1.10 +++ HttpUnitTest.java 2001/04/03 16:49:08 1.11 @@ -1,5 +1,24 @@ package com.meterware.httpunit; - +/******************************************************************************************************************** +* $Id$ +* +* Copyright (c) 2000-2001, Russell Gold +* +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +* documentation files (the "Software"), to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and +* to permit persons to whom the Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or substantial portions +* of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO +* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +* +*******************************************************************************************************************/ import java.net.URL; import junit.framework.Test; @@ -48,6 +67,11 @@ protected void defineResource( String resourceName, String value, String contentType ) { _server.setResource( resourceName, value, contentType ); + } + + + protected void addResourceHeader( String resourceName, String header ) { + _server.addResourceHeader( resourceName, header ); } Index: WebFrameTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFrameTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- WebFrameTest.java 2000/10/11 19:15:11 1.4 +++ WebFrameTest.java 2001/04/03 16:49:08 1.5 @@ -1,5 +1,24 @@ package com.meterware.httpunit; - +/******************************************************************************************************************** +* $Id$ +* +* Copyright (c) 2000-2001, Russell Gold +* +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +* documentation files (the "Software"), to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and +* to permit persons to whom the Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or substantial portions +* of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO +* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +* +*******************************************************************************************************************/ import java.net.URL; import junit.framework.Test; @@ -201,6 +220,17 @@ 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" ); + + _wc.getResponse( getHostPath() + "/Frames.html" ); + assertMatchingSet( "Frames defined for the conversation", new String[] { "_top", "red", "blue" }, _wc.getFrameNames() ); + assert( "Did not redirect", _wc.getFrameContents( "red" ).getURL().toExternalForm().endsWith( "Target.html" ) ); + } |
From: Russell G. <rus...@us...> - 2001-04-03 16:49:12
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv19605/src/com/meterware/httpunit Modified Files: WebClient.java WebRequest.java Log Message: Handle redirection in subframes Index: WebClient.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- WebClient.java 2001/01/08 16:40:36 1.3 +++ WebClient.java 2001/04/03 16:49:08 1.4 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000, Russell Gold +* Copyright (c) 2000-2001, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -68,7 +68,9 @@ updateCookies( response ); if (response.getHeaderField( "Location" ) != null) { delay( HttpUnitOptions.getRedirectDelay() ); - return getResponse( new RedirectWebRequest( request, response.getHeaderField( "Location" ) ) ); + return getResponse( new RedirectWebRequest( request, + response.getHeaderField( "Location" ), + request.getTarget() ) ); } else { updateFrames( response ); return response; @@ -300,8 +302,8 @@ class RedirectWebRequest extends WebRequest { - RedirectWebRequest( WebRequest baseRequest, String relativeURL ) throws MalformedURLException { - super( baseRequest, relativeURL ); + RedirectWebRequest( WebRequest baseRequest, String relativeURL, String target ) throws MalformedURLException { + super( baseRequest, relativeURL, target ); } Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- WebRequest.java 2001/04/02 19:54:29 1.16 +++ WebRequest.java 2001/04/03 16:49:08 1.17 @@ -176,8 +176,8 @@ /** * Constructs a web request using a base request and a relative URL string. **/ - protected WebRequest( WebRequest baseRequest, String urlString ) throws MalformedURLException { - this( baseRequest.getURL(), urlString ); + protected WebRequest( WebRequest baseRequest, String urlString, String target ) throws MalformedURLException { + this( baseRequest.getURL(), urlString, target ); } |
From: Russell G. <rus...@us...> - 2001-04-03 16:49:12
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv19605/doc Modified Files: release_notes.txt Log Message: Handle redirection in subframes Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- release_notes.txt 2001/04/02 19:35:45 1.24 +++ release_notes.txt 2001/04/03 16:49:08 1.25 @@ -11,7 +11,14 @@ Revision History: -2-Apr-01 +3-Apr-01 +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-Apr-01 1.2.3 Acknowledgements: Thanks to Silvio Samadelli for improved cookie-recognition logic |
From: Russell G. <rus...@us...> - 2001-04-02 19:54:33
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv7923/src/com/meterware/httpunit Modified Files: AuthorizationRequiredException.java MimeEncodedMessageBody.java WebRequest.java Log Message: Miscellaneous cleanup Index: AuthorizationRequiredException.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/AuthorizationRequiredException.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AuthorizationRequiredException.java 2001/04/02 19:35:46 1.2 +++ AuthorizationRequiredException.java 2001/04/02 19:54:29 1.3 @@ -33,7 +33,7 @@ int i = wwwAuthenticateHeader.indexOf( ' ' ); if (i < 0) { // non-conforming header _scheme = "Basic"; - _params = wwwAuthenticationHeader; + _params = wwwAuthenticateHeader; } else { _scheme = wwwAuthenticateHeader.substring( 0, i ); _params = wwwAuthenticateHeader.substring( i+1 ); Index: MimeEncodedMessageBody.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/MimeEncodedMessageBody.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MimeEncodedMessageBody.java 2001/04/02 19:07:36 1.2 +++ MimeEncodedMessageBody.java 2001/04/02 19:54:29 1.3 @@ -44,7 +44,7 @@ * Updates the headers for this request as needed. **/ void updateHeaders( URLConnection connection ) throws IOException { - connection.setRequestProperty( "Content-type", "multipart/form-data;boundary=\"" + BOUNDARY + "\"" ); + connection.setRequestProperty( "Content-type", "multipart/form-data; boundary=" + BOUNDARY ); } Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- WebRequest.java 2001/03/23 20:50:41 1.15 +++ WebRequest.java 2001/04/02 19:54:29 1.16 @@ -356,12 +356,13 @@ result.append( '+' ); } else if ((candidate >= 'A' && candidate <= 'Z') || (candidate >= 'a' && candidate <= 'z') || + (candidate == '.') || (candidate >= '0' && candidate <= '9')) { result.append( (char) rawBytes[i] ); } else if (candidate < 16) { - result.append( "%0" ).append( Integer.toHexString( candidate ) ); + result.append( "%0" ).append( Integer.toHexString( candidate ).toUpperCase() ); } else { - result.append( '%' ).append( Integer.toHexString( candidate ) ); + result.append( '%' ).append( Integer.toHexString( candidate ).toUpperCase() ); } } return result.toString(); |
From: Russell G. <rus...@us...> - 2001-04-02 19:38:49
|
Update of /cvsroot/httpunit/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv4319 Modified Files: build.xml Log Message: Correct typo in build.xml Index: build.xml =================================================================== RCS file: /cvsroot/httpunit/httpunit/build.xml,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- build.xml 2001/04/02 19:03:55 1.23 +++ build.xml 2001/04/02 19:38:30 1.24 @@ -32,7 +32,6 @@ <available property="javamail.present" classname="javax.mail.internet.MimeMultipart" /> <available property="xerces.present" classname="org.apache.xerces.parsers.DOMParser" /> </target> -</target> <!-- =================================================================== --> |
From: Russell G. <rus...@us...> - 2001-04-02 19:35:50
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv3720/src/com/meterware/httpunit Modified Files: AuthorizationRequiredException.java Log Message: Handle authentication headers w/o scheme specification Index: AuthorizationRequiredException.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/AuthorizationRequiredException.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AuthorizationRequiredException.java 2000/09/01 14:54:03 1.1 +++ AuthorizationRequiredException.java 2001/04/02 19:35:46 1.2 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000, Russell Gold +* Copyright (c) 2000-2001, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -31,15 +31,20 @@ AuthorizationRequiredException( String wwwAuthenticateHeader ) throws IOException { int i = wwwAuthenticateHeader.indexOf( ' ' ); - _scheme = wwwAuthenticateHeader.substring( 0, i ); - _params = wwwAuthenticateHeader.substring( i+1 ); + if (i < 0) { // non-conforming header + _scheme = "Basic"; + _params = wwwAuthenticationHeader; + } else { + _scheme = wwwAuthenticateHeader.substring( 0, i ); + _params = wwwAuthenticateHeader.substring( i+1 ); + } _properties = new Properties(); _properties.load( new ByteArrayInputStream( _params.getBytes() ) ); } public String getMessage() { - return _scheme + " authorization required: " + _params; + return _scheme + " authentication required: " + _params; } |
From: Russell G. <rus...@us...> - 2001-04-02 19:35:49
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv3720/doc Modified Files: release_notes.txt Log Message: Handle authentication headers w/o scheme specification Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- release_notes.txt 2001/04/02 19:07:36 1.23 +++ release_notes.txt 2001/04/02 19:35:45 1.24 @@ -21,6 +21,7 @@ 3. The JavaDoc now correctly shows the public methods in TableCell used for handling nested tables. 4. The XML retrieval test is no longer run when Xerces is not in the classpath, rather than giving an error. 5. File upload capability no longer depends on JavaMail and JAF, although its test does + 6. Non-conforming authentication headers are now assumed to be requesting Basic authentication Additions: 1. The Referer header is now sent for requests derived from links and forms. |
From: Russell G. <rus...@us...> - 2001-04-02 19:07:40
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv29110/src/com/meterware/httpunit Modified Files: MimeEncodedMessageBody.java PostMethodWebRequest.java Log Message: Reimplement file upload w/o JavaMail Index: MimeEncodedMessageBody.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/MimeEncodedMessageBody.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MimeEncodedMessageBody.java 2001/01/05 14:00:36 1.1 +++ MimeEncodedMessageBody.java 2001/04/02 19:07:36 1.2 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000, Russell Gold +* Copyright (c) 2000-2001, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -19,6 +19,7 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ +import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; @@ -27,19 +28,9 @@ import java.util.Dictionary; import java.util.Enumeration; -import javax.activation.*; - -import javax.mail.MessagingException; - -import javax.mail.internet.MimeBodyPart; -import javax.mail.internet.MimeMultipart; - - /** * A POST-method message body which is MIME-encoded. This is used when uploading files, and is selected when the enctype * parameter of a form is set to "multi-part/form-data". - * - * Note that this class is only compiled if the JavaMail and Java Activation Framework are accessible. **/ class MimeEncodedMessageBody extends MessageBody { @@ -53,7 +44,7 @@ * Updates the headers for this request as needed. **/ void updateHeaders( URLConnection connection ) throws IOException { - connection.setRequestProperty( "Content-type", getMimeBody().getContentType() ); + connection.setRequestProperty( "Content-type", "multipart/form-data;boundary=\"" + BOUNDARY + "\"" ); } @@ -61,43 +52,54 @@ * Transmits the body of this request as a sequence of bytes. **/ void writeTo( OutputStream outputStream ) throws IOException { - try { - getMimeBody().writeTo( outputStream ); - } catch (MessagingException e) { - throw new IOException( e.toString() ); + for (Enumeration e = getRequest().getParameterNames(); e.hasMoreElements();) { + String name = (String) e.nextElement(); + String[] values = getRequest().getParameterValues( name ); + for (int i = 0; i < values.length; i++) { + writeLn( outputStream, "--" + BOUNDARY ); + writeLn( outputStream, "Content-Disposition: form-data; name=\"" + name + '"' ); // XXX need to handle non-ascii names here + writeLn( outputStream, "Content-Type: text/plain; charset=" + getRequest().getCharacterSet() ); + writeLn( outputStream, "" ); + writeLn( outputStream, values[i], getRequest().getCharacterSet() ); + } } + + Dictionary files = getRequest().getSelectedFiles(); + for (Enumeration e = files.keys(); e.hasMoreElements();) { + String name = (String) e.nextElement(); + WebRequest.UploadFileSpec spec = (WebRequest.UploadFileSpec) files.get( name ); + writeLn( outputStream, "--" + BOUNDARY ); + writeLn( outputStream, "Content-Disposition: form-data; name=\"" + name + "\"; filename=\"" + spec.getFile().getName() + '"' ); // XXX need to handle non-ascii names here +// writeLn( outputStream, "Content-Type: application/octet-stream" ); // XXX want to support real content types + writeLn( outputStream, "" ); + + FileInputStream in = new FileInputStream( spec.getFile() ); + byte[] buffer = new byte[8 * 1024]; + int count = 0; + do { + outputStream.write( buffer, 0, count ); + count = in.read( buffer, 0, buffer.length ); + } while (count != -1); + + in.close(); + writeLn( outputStream, "" ); + } + writeLn( outputStream, "--" + BOUNDARY + "--" ); } - private MimeMultipart _mimeMultipart; + private final static String BOUNDARY = "--HttpUnit-part0-aSgQ2M"; + private final static byte[] CRLF = { 0x0d, 0x0A }; - private MimeMultipart getMimeBody() throws IOException { - if (_mimeMultipart == null) { - try { - _mimeMultipart = new MimeMultipart( "form-data" ); - for (Enumeration e = getRequest().getParameterNames(); e.hasMoreElements();) { - String name = (String) e.nextElement(); - MimeBodyPart mbp = new MimeBodyPart(); - mbp.setDisposition( "form-data; name=\"" + name + '"' ); // XXX need to handle non-ascii names here - mbp.setText( getRequest().getParameter( name ), getRequest().getCharacterSet() ); - _mimeMultipart.addBodyPart( mbp ); - } - - Dictionary files = getRequest().getSelectedFiles(); - for (Enumeration e = files.keys(); e.hasMoreElements();) { - String name = (String) e.nextElement(); - WebRequest.UploadFileSpec spec = (WebRequest.UploadFileSpec) files.get( name ); - FileDataSource fds = new FileDataSource( spec.getFile() ); - MimeBodyPart mbp = new MimeBodyPart(); - mbp.setDisposition( "form-data; name=\"" + name + "\"; filename=\"" + spec.getFile().getName() + '"' ); // XXX need to handle non-ascii names here - mbp.setDataHandler( new DataHandler( fds ) ); - _mimeMultipart.addBodyPart( mbp ); - } - } catch (MessagingException e) { - throw new IOException( e.toString() ); - } - } - return _mimeMultipart; + + private void writeLn( OutputStream os, String value, String encoding ) throws IOException { + os.write( value.getBytes( encoding ) ); + os.write( CRLF ); + } + + + private void writeLn( OutputStream os, String value ) throws IOException { + writeLn( os, value, getRequest().getCharacterSet() ); } } Index: PostMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/PostMethodWebRequest.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- PostMethodWebRequest.java 2001/01/05 14:00:36 1.9 +++ PostMethodWebRequest.java 2001/04/02 19:07:36 1.10 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000, Russell Gold +* Copyright (c) 2000-2001, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -107,73 +107,11 @@ private MessageBody newMessageBody() { if (isMimeEncoded()) { - return newMimeEncodedMessageBody( this ); + return new MimeEncodedMessageBody( this ); } else { return new URLEncodedMessageBody( this ); } } - - - private static Constructor _bodyConstructor; - - - static private MessageBody newMimeEncodedMessageBody( PostMethodWebRequest request ) { - try { - return (MessageBody) getMimeEncodedMessageBodyConstructor().newInstance( new Object[] { request } ); - } catch (IllegalAccessException e) { - throw new RuntimeException( "Programming error: no access to desired message body constructor. Please report this problem." ); - } catch (InstantiationException e) { - throw new RuntimeException( "Programming error: message body class is abstract. Please report this problem." ); - } catch (InvocationTargetException e) { - if (e.getTargetException() instanceof RuntimeException) { - throw (RuntimeException) e.getTargetException(); - } else if (e.getTargetException() instanceof Error) { - throw (Error) e.getTargetException(); - } else { - throw new RuntimeException( "Error during construction of MimeEncodedMessageBody: " + e.getTargetException() ); - } - - } - } - - - static private Constructor getMimeEncodedMessageBodyConstructor() { - if (_bodyConstructor == null) { - try { - confirmJavaMail(); - confirmJavaActivationFramework(); - Class bodyClass = Class.forName( "com.meterware.httpunit.MimeEncodedMessageBody" ); - _bodyConstructor = bodyClass.getConstructor( new Class[] { PostMethodWebRequest.class } ); - } catch (ClassNotFoundException e) { - throw new RuntimeException( "Multi-part form support was not compiled.\n" + - "Please rebuild HttpUnit or obtain a version which has this capability included." ); - } catch (NoSuchMethodException e) { - throw new RuntimeException( "Programming error: cannot find desired message body constructor. Please report this problem." ); - } - } - return _bodyConstructor; - } - - - static private void confirmJavaMail() { - try { - Class.forName( "javax.mail.MessagingException" ); - } catch (ClassNotFoundException e) { - throw new RuntimeException( "Multi-part form support requires the Java Mail and Java Activation Framework extensions.\n" + - "The Java Mail extension is not in your classpath." ); - } - } - - - static private void confirmJavaActivationFramework() { - try { - Class.forName( "javax.activation.DataSource" ); - } catch (ClassNotFoundException e) { - throw new RuntimeException( "Multi-part form support requires the Java Mail and Java Activation Framework extensions.\n" + - "The Java Activation Framework extension is not in your classpath." ); - } - } - } |
From: Russell G. <rus...@us...> - 2001-04-02 19:07:40
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv29110/test/com/meterware/httpunit Modified Files: FileUploadTest.java PseudoServer.java Log Message: Reimplement file upload w/o JavaMail Index: FileUploadTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FileUploadTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- FileUploadTest.java 2001/03/20 23:35:43 1.2 +++ FileUploadTest.java 2001/04/02 19:07:36 1.3 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000, Russell Gold +* Copyright (c) 2000-2001, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -212,8 +212,10 @@ if (i < numParts-1) sb.append( '&' ); } } catch (MessagingException e) { + e.printStackTrace(); sb.append( "Oops: " + e ); } catch (IOException e) { + e.printStackTrace(); sb.append( "Oops: " + e ); } Index: PseudoServer.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServer.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- PseudoServer.java 2001/03/23 20:50:41 1.10 +++ PseudoServer.java 2001/04/02 19:07:36 1.11 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000, Russell Gold +* Copyright (c) 2000-2001, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -245,7 +245,6 @@ } header = br.readLine(); } - readContent( headers, br ); return headers; } @@ -262,6 +261,22 @@ } } + + private void printContent( char[] content ) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < content.length; i++) { + if (i == 0) { + } else if ((i % 40) == 0) { + sb.append( '\n' ); + } else if (i % 4 == 0) { + sb.append( ' ' ); + } + sb.append( Integer.toHexString( content[i] ) ); + } + System.out.println( sb.toString() ); + } + + private Dictionary getParameters( String content ) throws IOException { Hashtable parameters = new Hashtable(); if (content == null || content.trim().length() == 0) return parameters; |
From: Russell G. <rus...@us...> - 2001-04-02 19:07:40
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv29110/doc Modified Files: release_notes.txt Log Message: Reimplement file upload w/o JavaMail Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- release_notes.txt 2001/04/02 01:53:21 1.22 +++ release_notes.txt 2001/04/02 19:07:36 1.23 @@ -11,7 +11,7 @@ Revision History: -23-Mar-01 +2-Apr-01 Acknowledgements: Thanks to Silvio Samadelli for improved cookie-recognition logic @@ -19,6 +19,8 @@ 1. Under JDK 1.3, error headers would sometimes cause a FileNotFoundException 2. Cookies containing '=' or wrapped in quotes are now recognized 3. The JavaDoc now correctly shows the public methods in TableCell used for handling nested tables. + 4. The XML retrieval test is no longer run when Xerces is not in the classpath, rather than giving an error. + 5. File upload capability no longer depends on JavaMail and JAF, although its test does Additions: 1. The Referer header is now sent for requests derived from links and forms. |
From: Russell G. <rus...@us...> - 2001-04-02 19:07:40
|
Update of /cvsroot/httpunit/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv29110 Modified Files: index.html Log Message: Reimplement file upload w/o JavaMail Index: index.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/index.html,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- index.html 2000/12/26 14:40:16 1.14 +++ index.html 2001/04/02 19:07:35 1.15 @@ -30,16 +30,13 @@ Several working example files come with the distribution download.</blockquote> <h2>Where do I get releases?</h2> -<blockquote>The latest release of HttpUnit is available -<var:dist from the <a href="http://httpunit.sourceforge.net"><var:dist HttpUnit home page</A> -<var:publish>as a <a href="http://httpunit.sourceforge.net/httpunit_<version>.zip"><var:publish>zip file</A> -.<var:publish><br><var:publish>Other builds are available by <a href="ftp://httpunit.sourceforge.net/pub/httpunit"> +<blockquote>Releases of HttpUnit are available +from <a href="http://sourceforge.net/project/showfiles.php?group_id=6550"> the project download page.</a> +<var:publish><br><var:publish>Other builds are available by <a href="ftp://httpunit.sourceforge.net/pub/httpunit"> <var:publish>anonymous ftp</a>. -<var:publish><br><b><var:publish>Note: JTidy is now being hosted on SourceForge. -You may download it from <a href="http://sourceforge.net/project/showfiles.php?group_id=13153"><var:publish>the project download area</a></b>. </blockquote> -<h2>How do I contribute, give feedback, fix bugs and so on?</h2> +<h2>How do I get help, contribute, give feedback, fix bugs and so on?</h2> <ul> <li>We have a <a href="http://lists.sourceforge.net/mailman/listinfo/httpunit-develop">mailing list</a> for discussion of the code. |
From: Russell G. <rus...@us...> - 2001-04-02 19:03:59
|
Update of /cvsroot/httpunit/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv27919 Modified Files: build.xml Log Message: Clean up errors in test Index: build.xml =================================================================== RCS file: /cvsroot/httpunit/httpunit/build.xml,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- build.xml 2001/02/21 19:01:07 1.22 +++ build.xml 2001/04/02 19:03:55 1.23 @@ -30,7 +30,9 @@ <target name="check_for_optional_packages"> <available property="jsdk.present" classname="javax.servlet.http.HttpServlet" /> <available property="javamail.present" classname="javax.mail.internet.MimeMultipart" /> + <available property="xerces.present" classname="org.apache.xerces.parsers.DOMParser" /> </target> +</target> <!-- =================================================================== --> @@ -49,7 +51,6 @@ <javac srcdir="${src.dir}" destdir="${build.classes}" classpath="${classpath}" debug="on" deprecation="on" optimize="off"> <exclude name="**/servletunit/*" unless="jsdk.present" /> - <exclude name="**/MimeEncodedMessageBody.java" unless="javamail.present" /> </javac> </target> @@ -62,6 +63,7 @@ debug="on" deprecation="on" optimize="off"> <exclude name="**/servletunit/*" unless="jsdk.present" /> <exclude name="**/FileUploadTest.java" unless="javamail.present" /> + <exclude name="**/XMLPageTest.java" unless="xerces.present" /> </javac> </target> |
From: Russell G. <rus...@us...> - 2001-04-02 19:03:59
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv27919/test/com/meterware/httpunit Modified Files: WebPageTest.java HttpUnitSuite.java Added Files: XMLPageTest.java Log Message: Clean up errors in test ***** Error reading new file[Errno 2] No such file or directory: 'XMLPageTest.java' Index: WebPageTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebPageTest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- WebPageTest.java 2001/01/05 14:00:36 1.8 +++ WebPageTest.java 2001/04/02 19:03:54 1.9 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000, Russell Gold +* Copyright (c) 2000-2001, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -84,18 +84,6 @@ WebResponse simplePage = wc.getResponse( request ); assertEquals( "Title", "A Sample Page", simplePage.getTitle() ); assertEquals( "Character set", "iso-8859-1", simplePage.getCharacterSet() ); - } - - - public void testXML() throws Exception { - defineResource( "SimplePage.xml", - "<?xml version=\"1.0\" ?><main><title>See me now</title></main>", - "text/xml" ); - - WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest( getHostPath() + "/SimplePage.xml" ); - WebResponse simplePage = wc.getResponse( request ); - Document doc = simplePage.getDOM(); } Index: HttpUnitSuite.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitSuite.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- HttpUnitSuite.java 2001/02/21 19:01:07 1.11 +++ HttpUnitSuite.java 2001/04/02 19:03:54 1.12 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000, Russell Gold +* Copyright (c) 2000-2001, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -45,6 +45,7 @@ suite.addTest( FormSubmitTest.suite() ); suite.addTest( Base64Test.suite() ); suite.addTest( PseudoServerTest.suite() ); + addOptionalTestCase( suite, "com.meterware.httpunit.XMLPageTest" ); addOptionalTestCase( suite, "com.meterware.httpunit.FileUploadTest" ); return suite; } @@ -54,7 +55,7 @@ try { suite.addTest( new TestSuite( Class.forName( testCaseName ) ) ); } catch (ClassNotFoundException e) { - System.out.println( "Test suite " + testCaseName + " not found; skipping." ); + System.out.println( "Note: test suite " + testCaseName + " not found; skipping." ); } } |
From: Russell G. <rus...@us...> - 2001-04-02 01:53:25
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv16641/src/com/meterware/httpunit Modified Files: ParsedHTML.java TableCell.java WebResponse.java Added Files: HTMLSegment.java Log Message: Add JavaDoc for TableCell public methods ***** Error reading new file[Errno 2] No such file or directory: 'HTMLSegment.java' Index: ParsedHTML.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- ParsedHTML.java 2000/12/27 20:02:17 1.13 +++ ParsedHTML.java 2001/04/02 01:53:21 1.14 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000, Russell Gold +* Copyright (c) 2000-2001, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -19,8 +19,6 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ -import java.util.Vector; - import java.net.URL; import java.util.Vector; Index: TableCell.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/TableCell.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- TableCell.java 2000/12/27 20:02:17 1.5 +++ TableCell.java 2001/04/02 01:53:21 1.6 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000, Russell Gold +* Copyright (c) 2000-2001, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -30,7 +30,7 @@ /** * A single cell in an HTML table. **/ -public class TableCell extends ParsedHTML { +public class TableCell extends ParsedHTML implements HTMLSegment { /** @@ -57,6 +57,14 @@ } + /** + * Returns a copy of the domain object model associated with this HTML segment. + **/ + public Node getDOM() { + return super.getDOM(); + } + + //---------------------------------------- package methods ----------------------------------------- Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- WebResponse.java 2001/03/23 19:13:27 1.30 +++ WebResponse.java 2001/04/02 01:53:21 1.31 @@ -46,7 +46,7 @@ * A response from a web server to a web request. **/ abstract -public class WebResponse { +public class WebResponse implements HTMLSegment { /** @@ -167,6 +167,8 @@ } +//---------------------- HTMLSegment methods ----------------------------- + /** * Returns the forms found in the page in the order in which they appear. * @exception SAXException thrown if there is an error parsing the response. @@ -282,6 +284,9 @@ public WebTable getTableWithID( String text ) throws SAXException { return getReceivedPage().getTableWithID( text ); } + + +//---------------------------------------- Object methods -------------------------------------------- public String toString() { |
From: Russell G. <rus...@us...> - 2001-04-02 01:53:25
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv16641/doc Modified Files: release_notes.txt Log Message: Add JavaDoc for TableCell public methods Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- release_notes.txt 2001/03/23 20:50:40 1.21 +++ release_notes.txt 2001/04/02 01:53:21 1.22 @@ -18,6 +18,7 @@ Problems corrected: 1. Under JDK 1.3, error headers would sometimes cause a FileNotFoundException 2. Cookies containing '=' or wrapped in quotes are now recognized + 3. The JavaDoc now correctly shows the public methods in TableCell used for handling nested tables. Additions: 1. The Referer header is now sent for requests derived from links and forms. |
From: Russell G. <rus...@us...> - 2001-03-23 20:50:45
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv8865/src/com/meterware/httpunit Modified Files: WebConversation.java WebForm.java WebLink.java WebRequest.java Log Message: Added referer header support Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- WebConversation.java 2000/11/21 20:44:58 1.18 +++ WebConversation.java 2001/03/23 20:50:41 1.19 @@ -55,6 +55,7 @@ **/ protected WebResponse newResponse( WebRequest request ) throws MalformedURLException, IOException { URLConnection connection = openConnection( request.getURL() ); + sendHeaders( connection, request.getHeaders() ); request.completeRequest( connection ); return new HttpWebResponse( request.getTarget(), request.getURL(), connection ); } @@ -76,11 +77,14 @@ private void sendHeaders( URLConnection connection ) { - Dictionary headers = getHeaderFields(); + sendHeaders( connection, getHeaderFields() ); + } + + + private void sendHeaders( URLConnection connection, Dictionary headers ) { for (Enumeration e = headers.keys(); e.hasMoreElements();) { String key = (String) e.nextElement(); connection.setRequestProperty( key, (String) headers.get( key ) ); } } - } Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- WebForm.java 2001/02/21 19:01:07 1.19 +++ WebForm.java 2001/03/23 20:50:41 1.20 @@ -240,6 +240,7 @@ } } } + result.setRequestHeader( "Referer", _baseURL.toExternalForm() ); return result; } Index: WebLink.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- WebLink.java 2000/10/05 14:45:14 1.5 +++ WebLink.java 2001/03/23 20:50:41 1.6 @@ -20,7 +20,9 @@ * Creates and returns a web request which will simulate clicking on this link. **/ public WebRequest getRequest() { - return new GetMethodWebRequest( _baseURL, getURLString(), getTarget() ); + WebRequest request = new GetMethodWebRequest( _baseURL, getURLString(), getTarget() ); + request.setRequestHeader( "Referer", _baseURL.toExternalForm() ); + return request; } Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- WebRequest.java 2001/02/21 19:01:07 1.14 +++ WebRequest.java 2001/03/23 20:50:41 1.15 @@ -266,6 +266,16 @@ } + void setRequestHeader( String headerName, String headerValue ) { + _headers.put( headerName.toUpperCase(), headerValue ); + } + + + Dictionary getHeaders() { + return _headers; + } + + static class UploadFileSpec { UploadFileSpec( File file ) { _file = file; @@ -311,6 +321,7 @@ private WebForm _sourceForm; private String _imageButtonName; private String _target = TOP_FRAME; + private Hashtable _headers = new Hashtable(); private boolean _httpsProtocolSupportEnabled; |
From: Russell G. <rus...@us...> - 2001-03-23 20:50:44
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv8865/test/com/meterware/httpunit Modified Files: PseudoServer.java PseudoServerTest.java PseudoServlet.java Log Message: Added referer header support Index: PseudoServer.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServer.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- PseudoServer.java 2001/03/20 23:35:43 1.9 +++ PseudoServer.java 2001/03/23 20:50:41 1.10 @@ -203,6 +203,8 @@ socket.close(); throw e; } catch (Throwable t) { + System.out.println( "Internal error: " + t ); + t.printStackTrace(); sendResponse( pw, HttpURLConnection.HTTP_INTERNAL_ERROR, t.toString() ); } } @@ -219,6 +221,9 @@ } else if (command.equals( "POST" ) && resource instanceof PseudoServlet) { Dictionary requestData = readRequest( br ); return ((PseudoServlet) resource).getPostResponse( getParameters( (String) requestData.get( PseudoServlet.CONTENTS ) ), requestData ); + } else if (command.equals( "GET" ) && resource instanceof PseudoServlet) { + Dictionary requestData = readRequest( br ); + return ((PseudoServlet) resource).getGetResponse( getParameters( (String) requestData.get( PseudoServlet.CONTENTS ) ), requestData ); } else { return null; } @@ -258,8 +263,10 @@ } private Dictionary getParameters( String content ) throws IOException { - StringTokenizer st = new StringTokenizer( content, "&=" ); Hashtable parameters = new Hashtable(); + if (content == null || content.trim().length() == 0) return parameters; + + StringTokenizer st = new StringTokenizer( content, "&=" ); while (st.hasMoreTokens()) { String name = st.nextToken(); if (st.hasMoreTokens()) { Index: PseudoServerTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServerTest.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- PseudoServerTest.java 2001/03/23 19:13:27 1.9 +++ PseudoServerTest.java 2001/03/23 20:50:41 1.10 @@ -190,6 +190,7 @@ } + public void testPseudoServlet() throws Exception { String resourceName = "tellMe"; String name = "Charlie"; @@ -212,6 +213,47 @@ WebResponse response = wc.getResponse( request ); assertEquals( "Content type", "text/plain", response.getContentType() ); assertEquals( "Response", expectedResponse, response.getText().trim() ); + } finally { + ps.shutDown(); + } + } + + + public void testRefererHeader() throws Exception { + String resourceName = "tellMe"; + String linkSource = "fromLink"; + String formSource = "fromForm"; + + PseudoServer ps = new PseudoServer(); + int port = ps.getConnectedPort(); + + String page0 = "http://localhost:" + port + '/' + resourceName; + String page1 = "http://localhost:" + port + '/' + linkSource; + String page2 = "http://localhost:" + port + '/' + formSource; + + ps.setResource( linkSource, "<html><head></head><body><a href=\"tellMe\">Go</a></body></html>" ); + ps.setResource( formSource, "<html><body><form action=\"tellMe\"><input type=submit></form></body></html>" ); + + try { + ps.setResource( resourceName, new PseudoServlet() { + public WebResource getGetResponse( Dictionary parameters, Dictionary headers ) { + String referer = (String) headers.get( "REFERER" ); + return new WebResource( referer == null ? "null" : referer, "text/plain" ); + } + } ); + + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( page0 ); + assertEquals( "Content type", "text/plain", response.getContentType() ); + assertEquals( "Default Referer header", "null", response.getText().trim() ); + + response = wc.getResponse( page1 ); + response = wc.getResponse( response.getLinks()[0].getRequest() ); + assertEquals( "Link Referer header", page1, response.getText().trim() ); + + response = wc.getResponse( page2 ); + response = wc.getResponse( response.getForms()[0].getRequest() ); + assertEquals( "Form Referer header", page2, response.getText().trim() ); } finally { ps.shutDown(); } Index: PseudoServlet.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServlet.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- PseudoServlet.java 2001/01/05 14:00:36 1.2 +++ PseudoServlet.java 2001/03/23 20:50:41 1.3 @@ -32,13 +32,26 @@ /** + * Returns a resource object as a result of a get request. + * @param parameters a mapping of parameter names to arrays of value string. + * @param headers a mapping of header names to header contents. Also contains a special 'header' named CONTENTS + * which is the raw bytes of the request contents stored in a string. + **/ + public WebResource getGetResponse( Dictionary parameters, Dictionary headers ) { + throw new RuntimeException( "get not implemented" ); + } + + + /* * Returns a resource object as a result of a post request. * @param parameters a mapping of parameter names to arrays of value string. * @param headers a mapping of header names to header contents. Also contains a special 'header' named CONTENTS * which is the raw bytes of the request contents stored in a string. **/ - abstract - public WebResource getPostResponse( Dictionary parameters, Dictionary headers ); + public WebResource getPostResponse( Dictionary parameters, Dictionary headers ) { + throw new RuntimeException( "post not implemented" ); + } + } |
From: Russell G. <rus...@us...> - 2001-03-23 20:50:44
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv8865/doc Modified Files: release_notes.txt Log Message: Added referer header support Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- release_notes.txt 2001/03/23 19:13:27 1.20 +++ release_notes.txt 2001/03/23 20:50:40 1.21 @@ -18,7 +18,10 @@ Problems corrected: 1. Under JDK 1.3, error headers would sometimes cause a FileNotFoundException 2. Cookies containing '=' or wrapped in quotes are now recognized - + +Additions: + 1. The Referer header is now sent for requests derived from links and forms. + 08-Jan-01 1.2.2 Acknowledgements: Thanks to Rocky Rhodes for finding the multiple cookie bug |
From: Russell G. <rus...@us...> - 2001-03-23 19:13:35
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv24514/doc Modified Files: release_notes.txt Log Message: Added improved cookie handling Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- release_notes.txt 2001/02/21 19:01:07 1.19 +++ release_notes.txt 2001/03/23 19:13:27 1.20 @@ -11,7 +11,15 @@ Revision History: -08-Jan-01 +23-Mar-01 +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 + +08-Jan-01 1.2.2 Acknowledgements: Thanks to Rocky Rhodes for finding the multiple cookie bug Thanks to Scott Croco for correcting the response code problem |
From: Russell G. <rus...@us...> - 2001-03-23 19:13:31
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv24514/test/com/meterware/httpunit Modified Files: PseudoServerTest.java Log Message: Added improved cookie handling Index: PseudoServerTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServerTest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- PseudoServerTest.java 2001/02/21 19:01:07 1.8 +++ PseudoServerTest.java 2001/03/23 19:13:27 1.9 @@ -148,6 +148,7 @@ ps.setResource( resourceName, resourceValue ); ps.addResourceHeader( resourceName, "Set-Cookie: age=12, name=george" ); ps.addResourceHeader( resourceName, "Set-Cookie: type=short" ); + ps.addResourceHeader( resourceName, "Set-Cookie: funky=ab$==" ); try { WebConversation wc = new WebConversation(); @@ -155,10 +156,11 @@ WebResponse response = wc.getResponse( request ); assertEquals( "requested resource", resourceValue, response.getText().trim() ); assertEquals( "content type", "text/html", response.getContentType() ); - assertEquals( "number of cookies", 3, wc.getCookieNames().length ); + assertEquals( "number of cookies", 4, 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" ) ); } finally { ps.shutDown(); } |
From: Russell G. <rus...@us...> - 2001-03-23 19:13:31
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv24514/src/com/meterware/httpunit Modified Files: WebResponse.java Log Message: Added improved cookie handling Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- WebResponse.java 2001/01/02 15:20:29 1.29 +++ WebResponse.java 2001/03/23 19:13:27 1.30 @@ -367,14 +367,26 @@ } + private void recognizeOneCookie( String cookieSpec ) { - StringTokenizer st = new StringTokenizer( cookieSpec, "=;" ); - String name = st.nextToken().trim(); - if (st.hasMoreTokens()) { - String value = st.nextToken().trim(); - _newCookies.put( name, value ); - } + StringTokenizer st = new StringTokenizer( cookieSpec, ";" ); + String token = st.nextToken().trim(); + int i = token.indexOf("="); + if (i > -1) { + String name = token.substring(0, i).trim(); + String value = stripQuote( token.substring( i+1, token.length() ).trim() ); + _newCookies.put( name, value ); + } } + + + private String stripQuote( String value ) { + if (((value.startsWith("\"")) && (value.endsWith("\""))) || + ((value.startsWith("'") && (value.endsWith("'"))))) { + return value.substring(1,value.length()-1); + } + return value; + } private void readContentTypeHeader() { |
From: Russell G. <rus...@us...> - 2001-03-20 23:33:23
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv26791/src/com/meterware/httpunit Modified Files: HttpWebResponse.java Log Message: Clean up implementation dependancies Index: HttpWebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- HttpWebResponse.java 2001/02/21 19:01:07 1.5 +++ HttpWebResponse.java 2001/03/20 23:35:42 1.6 @@ -48,7 +48,10 @@ HttpWebResponse( String target, URL url, URLConnection connection ) throws IOException { super( target, url ); readHeaders( connection ); - if (((HttpURLConnection) connection).getResponseCode() == HttpURLConnection.HTTP_OK) loadResponseText( url, connection ); + + + if (_responseCode == HttpURLConnection.HTTP_OK) loadResponseText( url, connection ); + if (connection instanceof HttpURLConnection) ((HttpURLConnection) connection).disconnect(); } @@ -115,18 +118,28 @@ } + private int getResponseCode( String statusHeader ) { + StringTokenizer st = new StringTokenizer( statusHeader ); + st.nextToken(); + if (!st.hasMoreTokens()) { + return HttpURLConnection.HTTP_OK; + } else try { + return Integer.parseInt( st.nextToken() ); + } catch (NumberFormatException e) { + return HttpURLConnection.HTTP_INTERNAL_ERROR; + } + } + + private void readHeaders( URLConnection connection ) { loadHeaders( connection ); - try { - if (connection instanceof HttpURLConnection) { - _responseCode = ((HttpURLConnection) connection).getResponseCode(); - } else { - _responseCode = HttpURLConnection.HTTP_OK; - if (getContentType().startsWith( "text" )) { - _headers.put( "Content-type".toUpperCase(), getContentType() + "; charset=" + _fileEncoding ); - } + if (connection instanceof HttpURLConnection) { + _responseCode = getResponseCode( connection.getHeaderField(0) ); + } else { + _responseCode = HttpURLConnection.HTTP_OK; + if (getContentType().startsWith( "text" )) { + _headers.put( "Content-type".toUpperCase(), getContentType() + "; charset=" + _fileEncoding ); } - } catch (IOException e) { } } |
From: Russell G. <rus...@us...> - 2001-03-20 23:33:23
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv26791/test/com/meterware/httpunit Modified Files: FileUploadTest.java FormSubmitTest.java HttpUnitTest.java PseudoServer.java WebResource.java Log Message: Clean up implementation dependancies Index: FileUploadTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FileUploadTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- FileUploadTest.java 2001/01/05 14:00:36 1.1 +++ FileUploadTest.java 2001/03/20 23:35:43 1.2 @@ -75,7 +75,7 @@ WebResponse simplePage = wc.getResponse( request ); WebRequest formSubmit = simplePage.getForms()[0].getRequest(); WebResponse encoding = wc.getResponse( formSubmit ); - assertEquals( "Parameters", "update=age&age=12", encoding.getText().trim() ); + assertEqualQueries( "http://dummy?update=age&age=12", "http://dummy?" + encoding.getText().trim() ); } Index: FormSubmitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormSubmitTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- FormSubmitTest.java 2001/02/21 19:01:07 1.6 +++ FormSubmitTest.java 2001/03/20 23:35:43 1.7 @@ -77,7 +77,7 @@ WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); WebForm form = page.getForms()[0]; WebRequest request = form.getRequest(); - assertEquals( getHostPath() + "/ask?age=12", request.getURL().toExternalForm() ); + assertEqualQueries( getHostPath() + "/ask?age=12", request.getURL().toExternalForm() ); } @@ -226,13 +226,13 @@ WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); WebForm form = page.getForms()[0]; WebRequest request = form.getRequest( form.getSubmitButton( "update", "name" ) ); - assertEquals( getHostPath() + "/ask?update=name&age=12", request.getURL().toExternalForm() ); + assertEqualQueries( getHostPath() + "/ask?update=name&age=12", request.getURL().toExternalForm() ); request = form.getRequest( "update", "name" ); - assertEquals( getHostPath() + "/ask?update=name&age=12", request.getURL().toExternalForm() ); + assertEqualQueries( getHostPath() + "/ask?update=name&age=12", request.getURL().toExternalForm() ); request = form.getRequest( "update" ); - assertEquals( getHostPath() + "/ask?update=age&age=12", request.getURL().toExternalForm() ); + assertEqualQueries( getHostPath() + "/ask?update=age&age=12", request.getURL().toExternalForm() ); } @@ -290,50 +290,7 @@ } - protected void assertEqualQueries( String query1, String query2 ) { - assertEquals( new QuerySpec( query1 ), new QuerySpec( query2 ) ); - } - - - static class QuerySpec { - QuerySpec( String urlString ) { - if (urlString.indexOf( '?' ) < 0) { - _path = urlString; - } else { - _path = urlString.substring( 0, urlString.indexOf( '?' ) ); - } - _fullString = urlString; - - StringTokenizer st = new StringTokenizer( urlString.substring( urlString.indexOf( '?' )+1 ), "&" ); - while (st.hasMoreTokens()) _parameters.addElement( st.nextToken() ); - } - - public String toString() { - return _fullString; - } - - public boolean equals( Object o ) { - return getClass().equals( o.getClass() ) && equals( (QuerySpec) o ); - } - private String _path; - private String _fullString; - private Vector _parameters = new Vector(); - - private boolean equals( QuerySpec o ) { - if (!_path.equals( o._path )) { - return false; - } else if (_parameters.size() != o._parameters.size() ) { - return false; - } else { - for (Enumeration e = o._parameters.elements(); e.hasMoreElements();) { - if (!_parameters.contains( e.nextElement() )) return false; - } - return true; - } - } - } - //---------------------------------------------- private members ------------------------------------------------ Index: HttpUnitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitTest.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- HttpUnitTest.java 2000/12/27 20:02:17 1.9 +++ HttpUnitTest.java 2001/03/20 23:35:43 1.10 @@ -6,6 +6,8 @@ import junit.framework.TestCase; import junit.framework.TestSuite; +import java.util.Enumeration; +import java.util.StringTokenizer; import java.util.Vector; @@ -66,6 +68,12 @@ } + protected void assertEqualQueries( String query1, String query2 ) { + assertEquals( new QuerySpec( query1 ), new QuerySpec( query2 ) ); + } + + + protected void assertMatchingSet( String comment, Object[] expected, Object[] found ) { Vector expectedItems = new Vector(); Vector foundItems = new Vector(); @@ -109,5 +117,45 @@ private String _hostPath; private PseudoServer _server; + + static class QuerySpec { + QuerySpec( String urlString ) { + if (urlString.indexOf( '?' ) < 0) { + _path = urlString; + } else { + _path = urlString.substring( 0, urlString.indexOf( '?' ) ); + } + _fullString = urlString; + + StringTokenizer st = new StringTokenizer( urlString.substring( urlString.indexOf( '?' )+ 1 ), "&" ); + while (st.hasMoreTokens()) _parameters.addElement( st.nextToken() ); + } + + public String toString() { + return _fullString; + } + + public boolean equals( Object o ) { + return getClass().equals( o.getClass() ) && equals( (QuerySpec) o ); + } + + private String _path; + private String _fullString; + private Vector _parameters = new Vector(); + + private boolean equals( QuerySpec o ) { + if (!_path.equals( o._path )) { + return false; + } else if (_parameters.size() != o._parameters.size() ) { + return false; + } else { + for (Enumeration e = o._parameters.elements(); e.hasMoreElements();) { + if (!_parameters.contains( e.nextElement() )) return false; + } + return true; + } + } + } + } Index: PseudoServer.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServer.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- PseudoServer.java 2001/02/21 19:01:07 1.8 +++ PseudoServer.java 2001/03/20 23:35:43 1.9 @@ -46,6 +46,11 @@ _active = false; } } + try { + if (_serverSocket != null) _serverSocket.close(); + _serverSocket = null; + } catch (IOException e) { + } } }; t.start(); @@ -178,7 +183,9 @@ sendResponse( pw, HttpURLConnection.HTTP_NOT_FOUND, "unable to find " + uri ); } else if (resource.getResponseCode() != HttpURLConnection.HTTP_OK) { sendResponse( pw, resource.getResponseCode(), resource.getContents() ); - } else { + sendLine( pw, "" ); + pw.flush(); + } else { sendResponse( pw, HttpURLConnection.HTTP_OK, "OK" ); sendLine( pw, "Content-type: " + resource.getContentType() + resource.getCharacterSetParameter() ); String[] headers = resource.getHeaders(); @@ -220,11 +227,17 @@ private Dictionary readRequest( BufferedReader br ) throws IOException { Hashtable headers = new Hashtable(); + String lastHeader = null; String header = br.readLine(); while (header.length() > 0) { - headers.put( header.substring( 0, header.indexOf(':') ).toUpperCase(), - header.substring( header.indexOf(':')+1 ).trim() ); + if (header.charAt(0) <= ' ') { + if (lastHeader == null) continue; + headers.put( lastHeader, headers.get( lastHeader ) + header.trim() ); + } else { + lastHeader = header.substring( 0, header.indexOf(':') ).toUpperCase(); + headers.put( lastHeader, header.substring( header.indexOf(':')+1 ).trim() ); + } header = br.readLine(); } Index: WebResource.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebResource.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- WebResource.java 2001/02/21 19:01:07 1.2 +++ WebResource.java 2001/03/20 23:35:43 1.3 @@ -109,6 +109,12 @@ } + public String toString() { + return "WebResource [code=" + _responseCode + "; type = " + _contentType + + "; charset = " + _characterSet + "]\n" + _contents; + } + + private int _responseCode; private boolean _sendCharacterSet; private String _contents; |