httpunit-commit Mailing List for httpunit (Page 77)
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-02-21 19:00:08
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv7381/src/com/meterware/httpunit Modified Files: HttpWebResponse.java WebForm.java WebRequest.java Log Message: bug fixes for 1.2.2 Index: HttpWebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- HttpWebResponse.java 2001/01/02 15:20:29 1.4 +++ HttpWebResponse.java 2001/02/21 19:01:07 1.5 @@ -45,10 +45,10 @@ * @param url the url from which the response was received * @param inputStream the input stream from which the response can be read **/ - HttpWebResponse( String target, URL url, URLConnection connection ) throws FileNotFoundException { + HttpWebResponse( String target, URL url, URLConnection connection ) throws IOException { super( target, url ); readHeaders( connection ); - loadResponseText( url, connection ); + if (((HttpURLConnection) connection).getResponseCode() == HttpURLConnection.HTTP_OK) loadResponseText( url, connection ); } Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- WebForm.java 2001/01/05 14:00:36 1.18 +++ WebForm.java 2001/02/21 19:01:07 1.19 @@ -116,6 +116,7 @@ _buttonVector.addElement( new SubmitButton( nl.item(i) ) ); } } + if (_buttonVector.isEmpty()) _buttonVector.addElement( SubmitButton.UNNAMED_BUTTON ); } return _buttonVector; } Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- WebRequest.java 2001/01/05 14:00:36 1.13 +++ WebRequest.java 2001/02/21 19:01:07 1.14 @@ -372,7 +372,7 @@ private void validateParameterValues( String name, String[] values ) { if (_sourceForm == null) return; - if (values.length != 1 && !_sourceForm.isMultiValuedParameter( name )) { + if (values.length > 1 && !_sourceForm.isMultiValuedParameter( name )) { throw new SingleValuedParameterException( name ); } |
From: Russell G. <rus...@us...> - 2001-02-21 19:00:08
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv7381/test/com/meterware/httpunit Modified Files: FormSubmitTest.java HttpUnitSuite.java PseudoServer.java PseudoServerTest.java WebResource.java Log Message: bug fixes for 1.2.2 Index: FormSubmitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormSubmitTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- FormSubmitTest.java 2001/01/05 14:00:36 1.5 +++ FormSubmitTest.java 2001/02/21 19:01:07 1.6 @@ -25,6 +25,8 @@ import junit.framework.TestCase; import junit.framework.TestSuite; +import java.util.Enumeration; +import java.util.StringTokenizer; import java.util.Vector; @@ -54,6 +56,31 @@ } + public void testEmbeddedEquals() throws Exception { + defineWebPage( "Default", "<form method=GET action = \"/ask\">" + + "<Input type=text name=\"age=x\" value=12>" + + "<Input type=submit>" + + "</form>" ); + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + WebForm form = page.getForms()[0]; + WebRequest request = form.getRequest(); + assertEquals( getHostPath() + "/ask?age%3Dx=12", request.getURL().toExternalForm() ); + } + + + public void testEmptyChoiceSubmit() 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]; + WebRequest request = form.getRequest(); + assertEquals( getHostPath() + "/ask?age=12", request.getURL().toExternalForm() ); + } + + public void testSubmitString() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=age>" + @@ -112,7 +139,7 @@ WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); WebForm form = page.getForms()[0]; WebRequest request = form.getRequest(); - assertEquals( getHostPath() + "/ask?update=name&update.y=0&update.x=0&age=12", request.getURL().toExternalForm() ); + assertEqualQueries( getHostPath() + "/ask?update=name&update.y=0&update.x=0&age=12", request.getURL().toExternalForm() ); } @@ -136,7 +163,7 @@ WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); WebForm form = page.getForms()[0]; WebRequest request = form.getRequest( form.getSubmitButton( "update" ), 10, 15 ); - assertEquals( getHostPath() + "/ask?update=name&update.y=15&update.x=10&age=12", request.getURL().toExternalForm() ); + assertEqualQueries( getHostPath() + "/ask?update=name&update.y=15&update.x=10&age=12", request.getURL().toExternalForm() ); } @@ -262,6 +289,50 @@ } } + + 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: HttpUnitSuite.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitSuite.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- HttpUnitSuite.java 2001/01/05 14:00:36 1.10 +++ HttpUnitSuite.java 2001/02/21 19:01:07 1.11 @@ -40,7 +40,6 @@ 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: PseudoServer.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServer.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- PseudoServer.java 2001/01/05 14:00:36 1.7 +++ PseudoServer.java 2001/02/21 19:01:07 1.8 @@ -90,6 +90,14 @@ /** + * Defines a resource which will result in an error message. + **/ + public void setErrorResource( String name, int errorCode, String errorMessage ) { + _resources.put( asResourceName( name ), new WebResource( errorCode, errorMessage ) ); + } + + + /** * Enables the sending of the character set in the content-type header. **/ public void setSendCharacterSet( String name, boolean enabled ) { @@ -161,8 +169,6 @@ String uri = st.nextToken(); String protocol = st.nextToken(); - - if (!command.equals( "GET" ) && !command.equals( "POST" )) { sendResponse( pw, HttpURLConnection.HTTP_BAD_METHOD, "unsupported method: " + command ); } else { @@ -170,6 +176,8 @@ WebResource resource = getResource( command, uri, br ); if (resource == null) { sendResponse( pw, HttpURLConnection.HTTP_NOT_FOUND, "unable to find " + uri ); + } else if (resource.getResponseCode() != HttpURLConnection.HTTP_OK) { + sendResponse( pw, resource.getResponseCode(), resource.getContents() ); } else { sendResponse( pw, HttpURLConnection.HTTP_OK, "OK" ); sendLine( pw, "Content-type: " + resource.getContentType() + resource.getCharacterSetParameter() ); Index: PseudoServerTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServerTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- PseudoServerTest.java 2001/01/05 14:00:36 1.7 +++ PseudoServerTest.java 2001/02/21 19:01:07 1.8 @@ -66,9 +66,27 @@ } + public void testInternalError() throws Exception { + PseudoServer ps = new PseudoServer(); + ps.setErrorResource( "error.htt", 501, "Internal error" ); + int port = ps.getConnectedPort(); + + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + "/error.htt" ); + try { + WebResponse response = wc.getResponse( request ); + fail( "Should have rejected the request" ); + } catch (HttpException e) { + assertEquals( "Response code", 501, e.getResponseCode() ); + } finally { + ps.shutDown(); + } + } + + public void testSimpleGet() throws Exception { String resourceName = "something/interesting"; - String resourceValue = "the desired content\r\n"; + String resourceValue = "the desired content"; PseudoServer ps = new PseudoServer(); ps.setResource( resourceName, resourceValue ); @@ -78,7 +96,7 @@ WebConversation wc = new WebConversation(); WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + resourceName ); WebResponse response = wc.getResponse( request ); - assertEquals( "requested resource", resourceValue, response.toString() ); + assertEquals( "requested resource", resourceValue, response.getText().trim() ); assertEquals( "content type", "text/html", response.getContentType() ); } finally { ps.shutDown(); @@ -86,10 +104,19 @@ } + private String asBytes( String s ) { + StringBuffer sb = new StringBuffer(); + char[] chars = s.toCharArray(); + for (int i = 0; i < chars.length; i++) { + sb.append( Integer.toHexString( chars[i] ) ).append( " " ); + } + return sb.toString(); + } + public void testRedirect() throws Exception { String resourceName = "something/redirected"; - String resourceValue = "the desired content\r\n"; + String resourceValue = "the desired content"; String redirectName = "anOldOne"; @@ -103,7 +130,7 @@ WebConversation wc = new WebConversation(); WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + redirectName ); WebResponse response = wc.getResponse( request ); - assertEquals( "requested resource", resourceValue, response.toString() ); + assertEquals( "requested resource", resourceValue, response.getText().trim() ); assertEquals( "content type", "text/html", response.getContentType() ); } finally { ps.shutDown(); @@ -114,7 +141,7 @@ public void testCookies() throws Exception { String resourceName = "something/baking"; - String resourceValue = "the desired content\r\n"; + String resourceValue = "the desired content"; PseudoServer ps = new PseudoServer(); int port = ps.getConnectedPort(); @@ -126,7 +153,7 @@ WebConversation wc = new WebConversation(); WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + resourceName ); WebResponse response = wc.getResponse( request ); - assertEquals( "requested resource", resourceValue, response.toString() ); + assertEquals( "requested resource", resourceValue, response.getText().trim() ); assertEquals( "content type", "text/html", response.getContentType() ); assertEquals( "number of cookies", 3, wc.getCookieNames().length ); assertEquals( "cookie 'age' value", "12", wc.getCookieValue( "age" ) ); @@ -140,7 +167,7 @@ public void testOldCookies() throws Exception { String resourceName = "something/baking"; - String resourceValue = "the desired content\r\n"; + String resourceValue = "the desired content"; PseudoServer ps = new PseudoServer(); int port = ps.getConnectedPort(); @@ -151,7 +178,7 @@ WebConversation wc = new WebConversation(); WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + resourceName ); WebResponse response = wc.getResponse( request ); - assertEquals( "requested resource", resourceValue, response.toString() ); + assertEquals( "requested resource", resourceValue, response.getText().trim() ); assertEquals( "content type", "text/html", response.getContentType() ); assertEquals( "number of cookies", 1, wc.getCookieNames().length ); assertEquals( "cookie 'CUSTOMER' value", "WILE_E_COYOTE", wc.getCookieValue( "CUSTOMER" ) ); @@ -165,7 +192,7 @@ String resourceName = "tellMe"; String name = "Charlie"; final String prefix = "Hello there, "; - String expectedResponse = prefix + name + "\r\n"; + String expectedResponse = prefix + name; PseudoServer ps = new PseudoServer(); int port = ps.getConnectedPort(); @@ -182,7 +209,7 @@ request.setParameter( "name", name ); WebResponse response = wc.getResponse( request ); assertEquals( "Content type", "text/plain", response.getContentType() ); - assertEquals( "Response", expectedResponse, response.getText() ); + assertEquals( "Response", expectedResponse, response.getText().trim() ); } finally { ps.shutDown(); } Index: WebResource.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebResource.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- WebResource.java 2000/12/27 20:02:17 1.1 +++ WebResource.java 2001/02/21 19:01:07 1.2 @@ -42,8 +42,19 @@ WebResource( String contents, String contentType ) { + this( contents, contentType, HttpURLConnection.HTTP_OK ); + } + + + WebResource( int responseCode, String responseText ) { + this( responseText, DEFAULT_CONTENT_TYPE, responseCode ); + } + + + WebResource( String contents, String contentType, int responseCode ) { _contents = contents; _contentType = contentType; + _responseCode = responseCode; } @@ -92,6 +103,13 @@ } } + + int getResponseCode() { + return _responseCode; + } + + + private int _responseCode; private boolean _sendCharacterSet; private String _contents; private String _contentType; |
From: Russell G. <rus...@us...> - 2001-02-21 19:00:08
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv7381/doc Modified Files: faq.html release_notes.txt Log Message: bug fixes for 1.2.2 Index: faq.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/faq.html,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- faq.html 2001/01/08 16:41:41 1.5 +++ faq.html 2001/02/21 19:01:07 1.6 @@ -8,10 +8,12 @@ <LI><A HREF="#Cannot unzip">Why can't I unzip the download library?</A></LI> <LI><A HREF="#org.xml.sax">What is the org.xml.sax package?</A></LI> <LI><A HREF="#meterware.com">Where is meterware.com?</A></LI> -<LI><A HREF="javascript">How do I use HttpUnit to test my pages that use JavaScript?</A></LI> -<LI><A HREF="https">Does HttpUnit support https?</A></LI> -<LI><A HREF="proxy">Can I use HttpUnit through a proxy server?</A></LI> -<LI><A HREF="charset">Why isn't HttpUnit handling my non-English pages?</A></LI> +<LI><A HREF="#javascript">How do I use HttpUnit to test my pages that use JavaScript?</A></LI> +<LI><A HREF="#https">Does HttpUnit support https?</A></LI> +<LI><A HREF="#proxy">Can I use HttpUnit through a proxy server?</A></LI> +<LI><A HREF="#charset">Why isn't HttpUnit handling my non-English pages?</A></LI> +<LI><A HREF="#utf8">HttpUnit fails with an IllegalArgumentException: sun.io.CharToByteUTF-8, what do I do?</A></LI> +<LI><A HREF="#buttons">HttpUnit is not finding the buttons in my forms. What is wrong?</A></LI> </OL> @@ -65,6 +67,21 @@ String japaneseName = new String(name.getBytes("8859_1"),"EUC_JP"); </code></blockquote> where the proper encoding should be substituted for "EUC_JP". The <code>getBytes</code> call is needed to extract the raw bytes from the parameter string. + +<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 +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. + +<A NAME="buttons"><H2>HttpUnit is not finding the buttons in my forms. What is wrong?</H2></A> +This often happens when your HTML is not valid. Most browsers are extremely forgiving of bad HTML; however, +JTidy (the HTML parser used by HttpUnit) is not. It expects tags to be nested according to the HTML specification and +will reject any that are not. JTidy can display error messages to tell you what is wrong. To see them, +call <code>HttpUnitOptions.setParserWarningsEnabled( true )</code> before retrieving your HTML page. +Once you have corrected any errors, HttpUnit should see your form buttons. </BODY></HTML> Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- release_notes.txt 2001/01/08 16:40:36 1.18 +++ release_notes.txt 2001/02/21 19:01:07 1.19 @@ -14,11 +14,18 @@ 08-Jan-01 Acknowledgements: Thanks to Rocky Rhodes for finding the multiple cookie bug + Thanks to Scott Croco for correcting the response code problem + Thanks to Ken MacLeod for finding the UTF-8 bug. + 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: |
From: Russell G. <rus...@us...> - 2001-02-21 19:00:07
|
Update of /cvsroot/httpunit/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv7381 Modified Files: build.xml Log Message: bug fixes for 1.2.2 Index: build.xml =================================================================== RCS file: /cvsroot/httpunit/httpunit/build.xml,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- build.xml 2001/01/05 14:00:35 1.21 +++ build.xml 2001/02/21 19:01:07 1.22 @@ -5,8 +5,8 @@ <project name="httpunit" default="jar" basedir="."> <property name="name" value="httpunit" /> <property name="Name" value="HttpUnit" /> - <property name="version" value="1.2.1" /> - <property name="zip_version" value="1_2_1" /> + <property name="version" value="1.2.2" /> + <property name="zip_version" value="1_2_2" /> <property name="src.dir" value="src" /> <property name="tstsrc.dir" value="test" /> <property name="examples.dir" value="examples" /> |
From: Russell G. <rus...@us...> - 2001-02-02 14:34:26
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv5293/src/com/meterware/httpunit Modified Files: ReceivedPage.java Log Message: Accomodate UTF8 encoding name in JDK 1.1.x Index: ReceivedPage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ReceivedPage.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- ReceivedPage.java 2000/12/27 20:02:17 1.11 +++ ReceivedPage.java 2001/02/02 14:34:29 1.12 @@ -59,7 +59,7 @@ private static Node getDOM( String pageText ) throws SAXException { try { - return getParser().parseDOM( new ByteArrayInputStream( pageText.getBytes( "UTF-8" ) ), null ); + return getParser().parseDOM( new ByteArrayInputStream( pageText.getBytes( getUTFEncodingName() ) ), null ); } catch (UnsupportedEncodingException e) { throw new RuntimeException( "UTF-8 encoding failed" ); } @@ -67,6 +67,18 @@ //---------------------------------- private members -------------------------------- + + + private static String _utfEncodingName; + + private static String getUTFEncodingName() { + if (_utfEncodingName == null) { + String versionNum = System.getProperty( "java.version" ); + if (versionNum.startsWith( "1.1" )) _utfEncodingName = "UTF8"; + else _utfEncodingName = "UTF-8"; + } + return _utfEncodingName; + } private void setBaseAttributes() throws SAXException { |
From: Russell G. <rus...@us...> - 2001-01-10 15:12:32
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv14576/doc Modified Files: todo.txt Log Message: update todo Index: todo.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/todo.txt,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- todo.txt 2000/10/04 15:45:46 1.4 +++ todo.txt 2001/01/10 15:12:48 1.5 @@ -2,9 +2,10 @@ Possibles: o replace JTidy with a simpler custom parser +o support JavaScript Low priority: o history on web conversation -o Support digest HTTP Authentication (?) +o Support digest HTTP Authentication |
From: Russell G. <rus...@us...> - 2001-01-08 16:41:29
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv29269/doc Modified Files: faq.html Log Message: Correct FAQ formatting Index: faq.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/faq.html,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- faq.html 2000/12/28 13:25:32 1.4 +++ faq.html 2001/01/08 16:41:41 1.5 @@ -61,7 +61,7 @@ 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 appropriately. In Java, that would be converting them to Unicode with statements such as<blockquote><code> -String rawName = request.getParameter( "name" ); +String rawName = request.getParameter( "name" );<br> String japaneseName = new String(name.getBytes("8859_1"),"EUC_JP"); </code></blockquote> where the proper encoding should be substituted for "EUC_JP". The <code>getBytes</code> call is needed to extract the raw bytes from the parameter string. |
From: Russell G. <rus...@us...> - 2001-01-08 16:40:23
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv29019/src/com/meterware/httpunit Modified Files: WebClient.java Log Message: Correct multiple cookie bug Index: WebClient.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- WebClient.java 2000/12/26 16:30:53 1.2 +++ WebClient.java 2001/01/08 16:40:36 1.3 @@ -186,7 +186,7 @@ StringBuffer sb = new StringBuffer(); for (int i = 0; i < names.length; i++) { - if (i != 0) sb.append( ';' ); + if (i != 0) sb.append( "; " ); String name = names[i]; sb.append( name ).append( '=' ).append( getCookieValue( name ) ); } |
From: Russell G. <rus...@us...> - 2001-01-08 16:40:23
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv29019/doc Modified Files: release_notes.txt Log Message: Correct multiple cookie bug Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- release_notes.txt 2001/01/05 14:00:36 1.17 +++ release_notes.txt 2001/01/08 16:40:36 1.18 @@ -11,9 +11,14 @@ Revision History: -04-Jan-01 +08-Jan-01 +Acknowledgements: + Thanks to Rocky Rhodes for finding the multiple cookie bug Additions: 1. Initial implementation of file upload capability + +Problems corrected: + 1. Multiple cookies were not being sent correctly 01-Jan-01 1.2.1 Acknowledgements: |
From: Russell G. <rus...@us...> - 2001-01-05 14:00:33
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv27742/test/com/meterware/httpunit Modified Files: FormSubmitTest.java HttpUnitSuite.java PseudoServer.java PseudoServerTest.java PseudoServlet.java WebPageTest.java Added Files: FileUploadTest.java Log Message: Implemented file upload capability ***** Error reading new file[Errno 2] No such file or directory: 'FileUploadTest.java' Index: FormSubmitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormSubmitTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- FormSubmitTest.java 2000/11/10 18:48:37 1.4 +++ FormSubmitTest.java 2001/01/05 14:00:36 1.5 @@ -112,7 +112,7 @@ WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); WebForm form = page.getForms()[0]; WebRequest request = form.getRequest(); - assertEquals( getHostPath() + "/ask?update=name&update.x=0&update.y=0&age=12", request.getURL().toExternalForm() ); + assertEquals( getHostPath() + "/ask?update=name&update.y=0&update.x=0&age=12", request.getURL().toExternalForm() ); } @@ -136,7 +136,7 @@ WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); WebForm form = page.getForms()[0]; WebRequest request = form.getRequest( form.getSubmitButton( "update" ), 10, 15 ); - assertEquals( getHostPath() + "/ask?update=name&update.x=10&update.y=15&age=12", request.getURL().toExternalForm() ); + assertEquals( getHostPath() + "/ask?update=name&update.y=15&update.x=10&age=12", request.getURL().toExternalForm() ); } Index: HttpUnitSuite.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitSuite.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- HttpUnitSuite.java 2000/10/26 14:16:49 1.9 +++ HttpUnitSuite.java 2001/01/05 14:00:36 1.10 @@ -46,7 +46,17 @@ suite.addTest( FormSubmitTest.suite() ); suite.addTest( Base64Test.suite() ); suite.addTest( PseudoServerTest.suite() ); + addOptionalTestCase( suite, "com.meterware.httpunit.FileUploadTest" ); return suite; + } + + + private static void addOptionalTestCase( TestSuite suite, String testCaseName ) { + try { + suite.addTest( new TestSuite( Class.forName( testCaseName ) ) ); + } catch (ClassNotFoundException e) { + System.out.println( "Test suite " + testCaseName + " not found; skipping." ); + } } Index: PseudoServer.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServer.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- PseudoServer.java 2000/12/27 20:02:17 1.6 +++ PseudoServer.java 2001/01/05 14:00:36 1.7 @@ -203,7 +203,7 @@ return (WebResource) resource; } else if (command.equals( "POST" ) && resource instanceof PseudoServlet) { Dictionary requestData = readRequest( br ); - return ((PseudoServlet) resource).getPostResponse( getParameters( (String) requestData.get( "content" ) ) ); + return ((PseudoServlet) resource).getPostResponse( getParameters( (String) requestData.get( PseudoServlet.CONTENTS ) ), requestData ); } else { return null; } @@ -231,7 +231,7 @@ int contentLength = Integer.parseInt( (String) headers.get( "CONTENT-LENGTH" ) ); char[] content = new char[ contentLength ]; br.read( content ); - headers.put( "content", new String( content ) ); + headers.put( PseudoServlet.CONTENTS, new String( content ) ); } catch (NumberFormatException e) { } } @@ -242,10 +242,23 @@ while (st.hasMoreTokens()) { String name = st.nextToken(); if (st.hasMoreTokens()) { - parameters.put( name, decode( st.nextToken() ) ); + addParameter( parameters, decode( name ), decode( st.nextToken() ) ); } } return parameters; + } + + + private void addParameter( Hashtable parameters, String name, String value ) { + String[] oldValues = (String[]) parameters.get( name ); + if (oldValues == null) { + parameters.put( name, new String[] { value } ); + } else { + String[] values = new String[ oldValues.length+1 ]; + System.arraycopy( oldValues, 0, values, 0, oldValues.length ); + values[ oldValues.length ] = value; + parameters.put( name, values ); + } } Index: PseudoServerTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServerTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- PseudoServerTest.java 2001/01/02 15:20:29 1.6 +++ PseudoServerTest.java 2001/01/05 14:00:36 1.7 @@ -172,8 +172,8 @@ try { ps.setResource( resourceName, new PseudoServlet() { - public WebResource getPostResponse( Dictionary parameters ) { - return new WebResource( prefix + parameters.get( "name" ), "text/plain" ); + public WebResource getPostResponse( Dictionary parameters, Dictionary headers ) { + return new WebResource( prefix + ((String[]) parameters.get( "name" ))[0], "text/plain" ); } } ); Index: PseudoServlet.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServlet.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PseudoServlet.java 2000/12/27 20:02:17 1.1 +++ PseudoServlet.java 2001/01/05 14:00:36 1.2 @@ -28,8 +28,17 @@ public class PseudoServlet { + final static public String CONTENTS = "contents"; + + + /** + * 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 ); + public WebResource getPostResponse( Dictionary parameters, Dictionary headers ); } Index: WebPageTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebPageTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- WebPageTest.java 2000/12/27 20:02:17 1.7 +++ WebPageTest.java 2001/01/05 14:00:36 1.8 @@ -175,9 +175,9 @@ "<input type=text name=name><input type=submit></form></body></html>" ); setResourceCharSet( "HebrewForm.html", "iso-8859-8", true ); defineResource( "SayHello", new PseudoServlet() { - public WebResource getPostResponse( Dictionary parameters ) { + public WebResource getPostResponse( Dictionary parameters, Dictionary headers ) { try { - String name = (String) parameters.get( "name" ); + String name = ((String[]) parameters.get( "name" ))[0]; WebResource result = new WebResource( "<html><body><table><tr><td>Hello, " + new String( name.getBytes( "iso-8859-1" ), "iso-8859-8" ) + "</td></tr></table></body></html>" ); |
From: Russell G. <rus...@us...> - 2001-01-05 14:00:33
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv27742/src/com/meterware/httpunit Modified Files: PostMethodWebRequest.java WebForm.java WebRequest.java Added Files: MessageBody.java MimeEncodedMessageBody.java Log Message: Implemented file upload capability ***** Error reading new file[Errno 2] No such file or directory: 'MessageBody.java' ***** Error reading new file[Errno 2] No such file or directory: 'MimeEncodedMessageBody.java' Index: PostMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/PostMethodWebRequest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- PostMethodWebRequest.java 2000/11/21 20:44:58 1.8 +++ PostMethodWebRequest.java 2001/01/05 14:00:36 1.9 @@ -19,13 +19,20 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ -import java.io.DataOutputStream; +import java.io.File; import java.io.IOException; +import java.io.OutputStream; -import java.net.MalformedURLException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + import java.net.URL; import java.net.URLConnection; +import java.util.Dictionary; +import java.util.Hashtable; + + /** * An HTTP request using the POST method. **/ @@ -48,18 +55,31 @@ } + /** + * Sets the file for a parameter upload in a web request. + **/ + public void selectFile( String parameterName, File file ) { + super.selectFile( parameterName, file ); + + _files.put( parameterName, new UploadFileSpec( file ) ); + } + + //---------------------------------- WebRequest methods -------------------------------- protected void completeRequest( URLConnection connection ) throws IOException { + MessageBody mb = newMessageBody(); + mb.updateHeaders( connection ); connection.setDoInput( true ); connection.setDoOutput( true ); - DataOutputStream printout = new DataOutputStream( connection.getOutputStream() ); - printout.writeBytes( getParameterString() ); - printout.flush(); - printout.close(); + OutputStream stream = connection.getOutputStream(); + mb.writeTo( stream ); + stream.flush(); + stream.close(); } + //----------------------------------- package members ----------------------------------- @@ -71,6 +91,117 @@ } + /** + * Returns a mapping of file parameters to upload specs. + **/ + Dictionary getSelectedFiles() { + return (Dictionary) _files.clone(); + } + +//---------------------------------- private members ------------------------------------- + + private Hashtable _files = new Hashtable(); + + + private MessageBody newMessageBody() { + if (isMimeEncoded()) { + return newMimeEncodedMessageBody( 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." ); + } + } + + +} + +//============================= class URLEncodedMessageBody ====================================== + +/** + * A POST method request message body which uses the default URL encoding. + **/ +class URLEncodedMessageBody extends MessageBody { + + + URLEncodedMessageBody( PostMethodWebRequest request ) { + super( request ); + } + + + /** + * Updates the headers for this request as needed. + **/ + void updateHeaders( URLConnection connection ) throws IOException { + } + + + /** + * Transmits the body of this request as a sequence of bytes. + **/ + void writeTo( OutputStream outputStream ) throws IOException { + outputStream.write( getRequest().getParameterString().getBytes() ); + } } + Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- WebForm.java 2000/12/27 20:02:17 1.17 +++ WebForm.java 2001/01/05 14:00:36 1.18 @@ -302,6 +302,22 @@ /** + * Returns true if the named parameter accepts files for upload. + **/ + public boolean isFileParameter( String name ) { + return TYPE_FILE.equals( getParameterTypes().get( name ) ); + } + + + /** + * 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" ) ); + } + + + /** * Returns a copy of the domain object model subtree associated with this form. **/ public Node getDOMSubtree() { @@ -334,6 +350,9 @@ /** The type of a parameter which accepts multiple predefined values. **/ private final static Integer TYPE_MULTI_VALUED = new Integer(3); + /** The type of a parameter which accepts files for upload. **/ + private final static Integer TYPE_FILE = new Integer(4); + /** The URL of the page containing this form. **/ private URL _baseURL; @@ -486,6 +505,8 @@ types.put( name, TYPE_SCALAR ); } else if (type.equals( "CHECKBOX" )) { types.put( name, TYPE_MULTI_VALUED ); + } else if (type.equals( "FILE" )) { + types.put( name, TYPE_FILE ); } } HTMLSelectElement[] selections = getSelections(); Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- WebRequest.java 2000/12/27 20:02:17 1.12 +++ WebRequest.java 2001/01/05 14:00:36 1.13 @@ -33,6 +33,25 @@ /** + * 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 ); + } + if (!isMimeEncoded()) throw new MultipartFormRequiredException(); + } + + + /** + * Returns an enumeration of all parameters in this web request. + **/ + public Enumeration getParameterNames() { + return _parameters.keys(); + } + + + /** * Returns the value of a parameter in this web request. * @return the value of the named parameter, or null if it is not set. **/ @@ -40,8 +59,10 @@ Object value = _parameters.get( name ); if (value instanceof String[]) { return ((String[]) value)[0]; + } else if (value == null) { + return ""; } else { - return (String) value; + return value.toString(); } } @@ -53,6 +74,7 @@ Object result = _parameters.get( name ); if (result instanceof String) return new String[] { (String) result }; if (result instanceof String[]) return (String[]) result; + if (result instanceof UploadFileSpec) return new String[] { result.toString() }; return new String[0]; } @@ -139,7 +161,15 @@ protected WebRequest( URL urlBase, String urlString, String target, WebForm sourceForm, SubmitButton button ) { this( urlBase, urlString, target ); _sourceForm = sourceForm; - _submitButton = button; + + if (button != null && button.getName().length() > 0) { + _parameters.put( button.getName(), button.getValue() ); + if (button.isImageButton()) { + _imageButtonName = button.getName(); + setSubmitPosition( 0, 0 ); + } + } + } @@ -149,6 +179,36 @@ protected WebRequest( WebRequest baseRequest, String urlString ) throws MalformedURLException { this( baseRequest.getURL(), urlString ); } + + + /** + * Returns true if the specified parameter is a file field. + **/ + protected boolean isFileParameter( String name ) { + return false; + } + + + /** + * Returns true if this request is to be MIME-encoded. + **/ + final + protected boolean isMimeEncoded() { + return _sourceForm != null && _sourceForm.isSubmitAsMime(); + } + + + /** + * Returns the character set required for this request. + **/ + final + protected String getCharacterSet() { + if (_sourceForm == null) { + return "iso-8859-1"; + } else { + return _sourceForm.getCharacterSet(); + } + } /** @@ -180,14 +240,6 @@ StringBuffer sb = new StringBuffer(); Enumeration e = _parameters.keys(); - if (_submitButton != null && _submitButton.getName().length() > 0) { - appendParameter( sb, _submitButton.getName(), _submitButton.getValue(), e.hasMoreElements() || _submitButton.isImageButton() ); - if (_submitButton.isImageButton()) { - appendParameter( sb, _submitButton.getName() + ".x", Integer.toString( _submitX ), true ); - appendParameter( sb, _submitButton.getName() + ".y", Integer.toString( _submitY ), e.hasMoreElements() ); - } - } - while (e.hasMoreElements()) { String name = (String) e.nextElement(); Object value = _parameters.get( name ); @@ -208,11 +260,39 @@ void setSubmitPosition( int x, int y ) { - _submitX = x; - _submitY = y; + if (_imageButtonName == null) return; + _parameters.put( _imageButtonName + ".x", Integer.toString( x ) ); + _parameters.put( _imageButtonName + ".y", Integer.toString( y ) ); } + static class UploadFileSpec { + UploadFileSpec( File file ) { + _file = file; + } + + + UploadFileSpec( File file, String contentType ) { + _file = file; + _contentType = contentType; + } + + + File getFile() { + return _file; + } + + + String getContentType() { + return _contentType; + } + + private File _file; + + private String _contentType; + } + + //--------------------------------------- private members ------------------------------------ /** The name of the system parameter used by java.net to locate protocol handlers. **/ @@ -229,10 +309,8 @@ private String _urlString; private Hashtable _parameters = new Hashtable(); private WebForm _sourceForm; - private SubmitButton _submitButton; + private String _imageButtonName; private String _target = TOP_FRAME; - private int _submitX; - private int _submitY; private boolean _httpsProtocolSupportEnabled; @@ -245,7 +323,7 @@ private void appendParameter( StringBuffer sb, String name, String value, boolean moreToCome ) { - sb.append( name ).append( '=' ); + sb.append( encode( name ) ).append( '=' ); sb.append( encode( value ) ); if (moreToCome) sb.append( '&' ); } @@ -277,7 +355,7 @@ } return result.toString(); } catch (java.io.UnsupportedEncodingException e) { - return "????"; + return "????"; // XXX should pass the exception through as IOException ultimately } } } @@ -286,6 +364,7 @@ private void validateParameterValue( String name, String value ) { if (_sourceForm == null) return; if (_sourceForm.isTextParameter( name )) return; + if (_sourceForm.isFileParameter( name )) throw new IllegalFileParameterException( name ); if (!inArray( name, _sourceForm.getParameterNames() )) throw new NoSuchParameterException( name ); if (!inArray( value, _sourceForm.getOptionValues( name ) )) throw new IllegalParameterValueException( name, value ); } @@ -446,6 +525,75 @@ private String _parameterName; + +} + + +//============================= exception class IllegalFileParameterException ====================================== + + +/** + * This exception is thrown on an attempt to set a file parameter to a text value. + **/ +class IllegalFileParameterException extends IllegalRequestParameterException { + + + IllegalFileParameterException( String parameterName ) { + _parameterName = parameterName; + } + + + public String getMessage() { + return "Parameter '" + _parameterName + "' is a file parameter and may not be set to a text value."; + } + + + private String _parameterName; + +} + + +//============================= exception class IllegalNonFileParameterException ====================================== + + +/** + * This exception is thrown on an attempt to set a non-file parameter to a file value. + **/ +class IllegalNonFileParameterException extends IllegalRequestParameterException { + + + IllegalNonFileParameterException( String parameterName ) { + _parameterName = parameterName; + } + + + public String getMessage() { + return "Parameter '" + _parameterName + "' is not a file parameter and may not be set to a file value."; + } + + + private String _parameterName; + +} + + +//============================= exception class MultipartFormRequiredException ====================================== + + +/** + * This exception is thrown on an attempt to set a file parameter in a form that does not specify MIME encoding. + **/ +class MultipartFormRequiredException extends IllegalRequestParameterException { + + + MultipartFormRequiredException() { + } + + + public String getMessage() { + return "The request does not use multipart/form-data encoding, and cannot be used to upload files "; + } + } |
From: Russell G. <rus...@us...> - 2001-01-05 14:00:32
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv27742/doc Modified Files: release_notes.txt Log Message: Implemented file upload capability Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- release_notes.txt 2001/01/02 15:20:29 1.16 +++ release_notes.txt 2001/01/05 14:00:36 1.17 @@ -10,8 +10,12 @@ Revision History: + +04-Jan-01 +Additions: + 1. Initial implementation of file upload capability -01-Jan-2001 1.2.1 +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. |
From: Russell G. <rus...@us...> - 2001-01-05 14:00:32
|
Update of /cvsroot/httpunit/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv27742 Modified Files: build.xml Log Message: Implemented file upload capability Index: build.xml =================================================================== RCS file: /cvsroot/httpunit/httpunit/build.xml,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- build.xml 2001/01/02 15:20:28 1.20 +++ build.xml 2001/01/05 14:00:35 1.21 @@ -29,6 +29,7 @@ <!-- =================================================================== --> <target name="check_for_optional_packages"> <available property="jsdk.present" classname="javax.servlet.http.HttpServlet" /> + <available property="javamail.present" classname="javax.mail.internet.MimeMultipart" /> </target> @@ -48,6 +49,7 @@ <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> @@ -59,12 +61,13 @@ <javac srcdir="${tstsrc.dir}" destdir="${build.classes}" classpath="${classpath}" debug="on" deprecation="on" optimize="off"> <exclude name="**/servletunit/*" unless="jsdk.present" /> + <exclude name="**/FileUploadTest.java" unless="javamail.present" /> </javac> </target> <!-- =================================================================== --> -<!-- Runs the test code (old) --> +<!-- Runs the test code --> <!-- Note: the classpath variable must be set on the command line --> <!-- =================================================================== --> <target name="test" depends="testcompile"> |
From: Russell G. <rus...@us...> - 2000-12-13 21:56:06
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv18452/src/com/meterware/servletunit Modified Files: ServletRunner.java ServletUnitHttpResponse.java Added Files: ServletUnitServletConfig.java ServletUnitServletContext.java Log Message: Added ServletConfig, ServletContext basic support ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') Index: ServletRunner.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletRunner.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ServletRunner.java 2000/11/21 20:44:59 1.1 +++ ServletRunner.java 2000/12/13 21:56:03 1.2 @@ -108,7 +108,9 @@ HttpSession session = servletRequest.getSession( /* create */ false ); if (session != null) ((ServletUnitHttpSession) session).access(); - getServlet( request.getURL() ).service( servletRequest, servletResponse ); + Servlet servlet = getServlet( request.getURL() ); + servlet.init( new ServletUnitServletConfig( servlet ) ); + servlet.service( servletRequest, servletResponse ); session = servletRequest.getSession( /* create */ false ); if (session != null && session.isNew()) { servletResponse.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, session.getId() ) ); Index: ServletUnitHttpResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpResponse.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ServletUnitHttpResponse.java 2000/11/21 22:18:19 1.2 +++ ServletUnitHttpResponse.java 2000/12/13 21:56:03 1.3 @@ -105,7 +105,7 @@ * Relative URLs are not permitted here. */ public void sendRedirect( String location ) throws IOException { - throw new RuntimeException( "sendRedirect not implemented" ); + setHeader( "Location", location ); } |
From: Russell G. <rus...@us...> - 2000-12-13 21:56:06
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv18452/test/com/meterware/servletunit Modified Files: ServletUnitSuite.java Added Files: ConfigTest.java NavigationTest.java Log Message: Added ServletConfig, ServletContext basic support ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') Index: ServletUnitSuite.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/ServletUnitSuite.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ServletUnitSuite.java 2000/11/21 20:44:59 1.1 +++ ServletUnitSuite.java 2000/12/13 21:56:03 1.2 @@ -41,6 +41,8 @@ suite.addTest( StatelessTest.suite() ); suite.addTest( StatefulTest.suite() ); suite.addTest( SessionTest.suite() ); + suite.addTest( NavigationTest.suite() ); + suite.addTest( ConfigTest.suite() ); return suite; } |
From: Russell G. <rus...@us...> - 2000-12-13 21:56:06
|
Update of /cvsroot/httpunit/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv18452 Modified Files: build.xml Log Message: Added ServletConfig, ServletContext basic support Index: build.xml =================================================================== RCS file: /cvsroot/httpunit/httpunit/build.xml,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- build.xml 2000/11/21 20:56:29 1.16 +++ build.xml 2000/12/13 21:56:02 1.17 @@ -64,13 +64,25 @@ <!-- =================================================================== --> -<!-- Runs the test code --> +<!-- Runs the test code (old) --> <!-- Note: the classpath variable must be set on the command line --> <!-- =================================================================== --> <target name="test" depends="testcompile"> <java classname="${test.class}" fork="yes" classpath="${build.classes};${classpath}" > </java> +</target> + + +<!-- =================================================================== --> +<!-- Runs the test code using the junit task --> +<!-- Note: the classpath variable must be set on the command line --> +<!-- =================================================================== --> +<target name="testn" depends="testcompile"> + <junit fork="no" haltonfailure="yes" printsummary="true"> + <classpath location="${build.classes}" /> + <test name="${test.class}"/> + </junit> </target> |
From: Russell G. <rus...@us...> - 2000-12-13 21:56:05
|
Update of /cvsroot/httpunit/httpunit/doc In directory slayer.i.sourceforge.net:/tmp/cvs-serv18452/doc Modified Files: release_notes.txt Log Message: Added ServletConfig, ServletContext basic support Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- release_notes.txt 2000/11/21 20:44:57 1.11 +++ release_notes.txt 2000/12/13 21:56:03 1.12 @@ -8,6 +8,10 @@ Revision History: +Additions: + 1. Added getTableWithID method to WebResponse, ParsedHTML + 2. Implemented support for sendRedirect, getServletContext in ServletUnit + 21-Nov-00 Additions: 1. Introductory ServletUnit functionality (parameters and sessions, but no JSP, no redirect, no forwarding) |
From: Russell G. <rus...@us...> - 2000-12-13 21:55:19
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv18372/src/com/meterware/httpunit Modified Files: ParsedHTML.java WebResponse.java WebTable.java Log Message: Added getTableWithID Index: ParsedHTML.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- ParsedHTML.java 2000/11/21 20:44:58 1.11 +++ ParsedHTML.java 2000/12/13 21:55:16 1.12 @@ -132,8 +132,14 @@ * its first non-blank row and non-blank column. Will recurse into any nested tables, as needed. * @return the selected table, or null if none is found **/ - public WebTable getTableStartingWith( String text ) { - return getTableStartingWith( text, getTables() ); + public WebTable getTableStartingWith( final String text ) { + return getTableSatisfyingPredicate( getTables(), new TablePredicate() { + public boolean isTrue( WebTable table ) { + table.purgeEmptyCells(); + return table.getRowCount() > 0 && + table.getCellAsText(0,0).equalsIgnoreCase( text ); + } + } ); } @@ -143,7 +149,14 @@ * @return the selected table, or null if none is found **/ public WebTable getTableStartingWithPrefix( String text ) { - return getTableStartingWithPrefix( text.toUpperCase(), getTables() ); + final String prefix = text.toUpperCase(); + return getTableSatisfyingPredicate( getTables(), new TablePredicate() { + public boolean isTrue( WebTable table ) { + table.purgeEmptyCells(); + return table.getRowCount() > 0 && + table.getCellAsText(0,0).toUpperCase().startsWith( prefix ); + } + } ); } @@ -151,9 +164,27 @@ * Returns the first table in the response which has the specified text as its summary attribute. * Will recurse into any nested tables, as needed. * @return the selected table, or null if none is found + **/ + public WebTable getTableWithSummary( final String summary ) { + return getTableSatisfyingPredicate( getTables(), new TablePredicate() { + public boolean isTrue( WebTable table ) { + return table.getSummary().equalsIgnoreCase( summary ); + } + } ); + } + + + /** + * Returns the first table in the response which has the specified text as its ID attribute. + * Will recurse into any nested tables, as needed. + * @return the selected table, or null if none is found **/ - public WebTable getTableWithSummary( String summary ) { - return getTableWithSummary( summary, getTables() ); + public WebTable getTableWithID( final String ID ) { + return getTableSatisfyingPredicate( getTables(), new TablePredicate() { + public boolean isTrue( WebTable table ) { + return table.getID().equalsIgnoreCase( ID ); + } + } ); } @@ -204,6 +235,11 @@ } + interface TablePredicate { + public boolean isTrue( WebTable table ); + } + + //---------------------------------- private members -------------------------------- private Node _rootNode; @@ -236,69 +272,11 @@ /** - * Returns the table with the specified text in its first non-blank row and column. - **/ - private WebTable getTableStartingWith( String text, WebTable[] tables ) { - for (int i = 0; i < tables.length; i++) { - tables[i].purgeEmptyCells(); - if (tables[i].getRowCount() == 0) continue; - if (tables[i].getCellAsText(0,0).equalsIgnoreCase( text )) { - return tables[i]; - } else { - for (int j = 0; j < tables[i].getRowCount(); j++) { - for (int k = 0; k < tables[i].getColumnCount(); k++) { - TableCell cell = tables[i].getTableCell(j,k); - if (cell != null) { - WebTable[] innerTables = cell.getTables(); - if (innerTables.length != 0) { - WebTable result = getTableStartingWith( text, innerTables ); - if (result != null) return result; - } - } - } - } - } - } - return null; - } - - - - /** - * Returns the table with the specified text in its first non-blank row and column. - **/ - private WebTable getTableStartingWithPrefix( String text, WebTable[] tables ) { - for (int i = 0; i < tables.length; i++) { - tables[i].purgeEmptyCells(); - if (tables[i].getRowCount() == 0) continue; - if (tables[i].getCellAsText(0,0).toUpperCase().startsWith( text )) { - return tables[i]; - } else { - for (int j = 0; j < tables[i].getRowCount(); j++) { - for (int k = 0; k < tables[i].getColumnCount(); k++) { - TableCell cell = tables[i].getTableCell(j,k); - if (cell != null) { - WebTable[] innerTables = cell.getTables(); - if (innerTables.length != 0) { - WebTable result = getTableStartingWithPrefix( text, innerTables ); - if (result != null) return result; - } - } - } - } - } - } - return null; - } - - - - /** * Returns the table with the specified text in its summary attribute. **/ - private WebTable getTableWithSummary( String summary, WebTable[] tables ) { + private WebTable getTableSatisfyingPredicate( WebTable[] tables, TablePredicate predicate ) { for (int i = 0; i < tables.length; i++) { - if (tables[i].getSummary().equalsIgnoreCase( summary )) { + if (predicate.isTrue( tables[i] )) { return tables[i]; } else { for (int j = 0; j < tables[i].getRowCount(); j++) { @@ -307,7 +285,7 @@ if (cell != null) { WebTable[] innerTables = cell.getTables(); if (innerTables.length != 0) { - WebTable result = getTableWithSummary( summary, innerTables ); + WebTable result = getTableSatisfyingPredicate( innerTables, predicate ); if (result != null) return result; } } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- WebResponse.java 2000/11/21 20:44:58 1.23 +++ WebResponse.java 2000/12/13 21:55:16 1.24 @@ -261,6 +261,18 @@ } + /** + * Returns the first table in the response which has the specified text as its ID attribute. + * Will recurse into any nested tables, as needed. + * Case is ignored. + * @exception SAXException thrown if there is an error parsing the response. + * @return the selected table, or null if none is found + **/ + public WebTable getTableWithID( String text ) throws SAXException { + return getReceivedPage().getTableWithID( text ); + } + + public String toString() { return getText(); } Index: WebTable.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebTable.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- WebTable.java 2000/10/31 19:54:15 1.11 +++ WebTable.java 2000/12/13 21:55:16 1.12 @@ -172,6 +172,14 @@ } + /** + * Returns the unique ID attribute associated with this table. + **/ + public String getID() { + return NodeUtils.getNodeAttribute( _dom, "id" ); + } + + public String toString() { String eol = System.getProperty( "line.separator" ); if (_cells == null) readTable(); |
From: Russell G. <rus...@us...> - 2000-12-13 21:55:19
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv18372/test/com/meterware/httpunit Modified Files: HtmlTablesTest.java Log Message: Added getTableWithID Index: HtmlTablesTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HtmlTablesTest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- HtmlTablesTest.java 2000/10/31 19:54:15 1.10 +++ HtmlTablesTest.java 2000/12/13 21:55:16 1.11 @@ -186,10 +186,10 @@ public void testInnerTableSeek() throws Exception { defineWebPage( "Default", "<h2>Interesting data</h2>" + - "<table summary=\"outer one\">" + + "<table id=you summary=\"outer one\">" + "<tr><td>Here we are</td><td>" + "Inner Table<br>" + - "<table summary=\"inner one\">" + + "<table id=me summary=\"inner one\">" + " <tr><td colspan=2> </td></tr>" + " <tr><td>Red</td><td>1</td></tr>" + " <tr><td>Blue</td><td>2</td></tr>" + @@ -212,7 +212,14 @@ assertEquals( "cell at 1,0", "Blue", cells[1][0] ); wt = page.getTableWithSummary( "Inner One" ); - assertNotNull( "Did not find table starting with summary 'Inner One'", wt ); + assertNotNull( "Did not find table with summary 'Inner One'", wt ); + cells = wt.asText(); + assertEquals( "Total rows", 3, cells.length ); + assertEquals( "Total columns", 2, cells[0].length ); + assertEquals( "cell at 2,0", "Blue", cells[2][0] ); + + wt = page.getTableWithID( "me" ); + assertNotNull( "Did not find table with id 'me'", wt ); cells = wt.asText(); assertEquals( "Total rows", 3, cells.length ); assertEquals( "Total columns", 2, cells[0].length ); |
From: Russell G. <rus...@us...> - 2000-11-21 22:18:29
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv18213/src/com/meterware/servletunit Modified Files: ServletUnitHttpRequest.java ServletUnitHttpResponse.java ServletUnitHttpSession.java Log Message: support JSDK 2.2 Index: ServletUnitHttpRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ServletUnitHttpRequest.java 2000/11/21 20:44:59 1.1 +++ ServletUnitHttpRequest.java 2000/11/21 22:18:19 1.2 @@ -261,7 +261,7 @@ } -//--------------------------------- Servlet methods ---------------------------------------------------- +//--------------------------------- ServletRequest methods ---------------------------------------------------- /** @@ -469,6 +469,105 @@ } +//--------------------------------- methods added to ServletRequest in JSDK 2.2 ------------------------------------------------ + + + /** + * Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS. + **/ + public boolean isSecure() { + throw new RuntimeException( "isSecure not implemented" ); + } + + + /** + * Returns the preferred Locale that the client will accept content in, based on the Accept-Language header. + * If the client request doesn't provide an Accept-Language header, this method returns the default locale for the server. + **/ + public java.util.Locale getLocale() { + throw new RuntimeException( "getLocale not implemented" ); + } + + + /** + * Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, + * the locales that are acceptable to the client based on the Accept-Language header. + * If the client request doesn't provide an Accept-Language header, this + * method returns an Enumeration containing one Locale, the default locale for the server. + **/ + public java.util.Enumeration getLocales() { + throw new RuntimeException( "getLocales not implemented" ); + } + + + /** + * Removes an attribute from this request. This method is not generally needed + * as attributes only persist as long as the request is being handled. + **/ + public void removeAttribute( String name ) { + _attributes.remove( name ); + } + + + /** + * Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. + * A RequestDispatcher object can be used to forward a request to the resource or to include the + * resource in a response. The resource can be dynamic or static. + * + * The pathname specified may be relative, although it cannot extend outside the current servlet + * context. If the path begins with a "/" it is interpreted as relative to the current context root. + * This method returns null if the servlet container cannot return a RequestDispatcher. + * + * The difference between this method and ServletContext.getRequestDispatcher(java.lang.String) + * is that this method can take a relative path. + **/ + public RequestDispatcher getRequestDispatcher( String path ) { + throw new RuntimeException( "getRequestDispatcher not implemented" ); + } + + + +//--------------------------------- methods added to HttpServletRequest in JSDK 2.2 ------------------------------------------------ + + + /** + * Returns a java.security.Principal object containing the name of the current authenticated user. + * If the user has not been authenticated, the method returns null. + **/ + public java.security.Principal getUserPrincipal() { + return null; + } + + + /** + * Returns a boolean indicating whether the authenticated user is included in the specified + * logical "role". Roles and role membership can be defined using deployment descriptors. + * If the user has not been authenticated, the method returns false. + **/ + public boolean isUserInRole( String role ) { + return false; + } + + + /** + * Returns all the values of the specified request header as an Enumeration of String objects. + **/ + public java.util.Enumeration getHeaders( String name ) { + throw new RuntimeException( "getHeaders not implemented" ); + } + + + /** + * Returns the portion of the request URI that indicates the context of the request. + * The context path always comes first in a request URI. The path starts with a "/" character + * but does not end with a "/" character. For servlets in the default (root) context, + * this method returns "". + **/ + public java.lang.String getContextPath() { + throw new RuntimeException( "getContextPath not implemented" ); + } + + //--------------------------------------------- package members ---------------------------------------------- Index: ServletUnitHttpResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpResponse.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ServletUnitHttpResponse.java 2000/11/21 20:44:59 1.1 +++ ServletUnitHttpResponse.java 2000/11/21 22:18:19 1.2 @@ -24,6 +24,7 @@ import java.util.Enumeration; import java.util.Hashtable; +import java.util.Locale; import java.util.Vector; import javax.servlet.*; @@ -280,6 +281,97 @@ } +//------------------------------- the following methods are new in JSDK 2.2 ---------------------- + + + /** + * Adds a response header with the given name and value. This method allows response headers to have multiple values. + **/ + public void addHeader( String name, String value ) { + throw new RuntimeException( "addHeader not implemented" ); + } + + + /** + * Adds a response header with the given name and value. This method allows response headers to have multiple values. + **/ + public void addIntHeader( String name, int value ) { + throw new RuntimeException( "addIntHeader not implemented" ); + } + + + /** + * Adds a response header with the given name and value. This method allows response headers to have multiple values. + **/ + public void addDateHeader( String name, long value ) { + throw new RuntimeException( "addDateHeader not implemented" ); + } + + + /** + * Sets the preferred buffer size for the body of the response. The servlet container + * will use a buffer at least as large as the size requested. The actual buffer size + * used can be found using getBufferSize. + **/ + public void setBufferSize( int size ) { // XXX throw IllegalStateException if anything has been written + throw new RuntimeException( "setBufferSize not implemented" ); + } + + + /** + * Returns the actual buffer size used for the response. If no buffering is used, this method returns 0. + **/ + public int getBufferSize() { + return 0; + } + + + /** + * Returns a boolean indicating if the response has been committed. A commited response has + * already had its status code and headers written. + **/ + public boolean isCommitted() { + return false; // XXX set true if flushBuffer has been called + } + + + /** + * Forces any content in the buffer to be written to the client. A call to this method automatically + * commits the response, meaning the status code and headers will be written. + **/ + public void flushBuffer() throws IOException { + throw new RuntimeException( "flushBuffer not implemented" ); + } + + + /** + * Clears any data that exists in the buffer as well as the status code and headers. + * If the response has been committed, this method throws an IllegalStateException. + **/ + public void reset() { + throw new RuntimeException( "reset not implemented" ); + } + + + /** + * Sets the locale of the response, setting the headers (including the Content-Type's charset) + * as appropriate. This method should be called before a call to getWriter(). + * By default, the response locale is the default locale for the server. + **/ + public void setLocale( Locale locale ) { + throw new RuntimeException( "setLocale not implemented" ); + } + + + /** + * Returns the locale assigned to the response. + **/ + public Locale getLocale() { + throw new RuntimeException( "getLocale not implemented" ); + } + + + //---------------------------------------- package methods --------------------------------------- Index: ServletUnitHttpSession.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpSession.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ServletUnitHttpSession.java 2000/11/21 20:44:59 1.1 +++ ServletUnitHttpSession.java 2000/11/21 22:18:19 1.2 @@ -24,6 +24,7 @@ import java.net.HttpURLConnection; import java.util.Date; +import java.util.Enumeration; import java.util.Hashtable; import javax.servlet.ServletException; @@ -125,9 +126,42 @@ /** - * Returns the object bound with the specified name in this session or null if no object of that name exists. + * @deprecated as of JSDK 2.2, use getAttribute **/ public Object getValue( String name ) { + return getAttribute( name ); + } + + + /** + * @deprecated as of JSDK 2.2, use setAttribute + **/ + public void putValue( String name, Object value ) { + setAttribute( name, value ); + } + + + /** + * @deprecated as of JSDK 2.2, use removeAttribute + **/ + public void removeValue( String name ) { + removeAttribute( name ); + } + + + /** + * @deprecated as of JSDK 2.2, use getAttributeNames. + **/ + public String[] getValueNames() { + if (_isInvalid) throw new IllegalStateException(); + throw new RuntimeException( "getValueNames not implemented" ); + } + + + /** + * Returns the object bound with the specified name in this session or null if no object of that name exists. + **/ + public Object getAttribute( String name ) { if (_isInvalid) throw new IllegalStateException(); return _values.get( name ); } @@ -137,7 +171,7 @@ * Binds an object to this session, using the name specified. If an object of the same name * is already bound to the session, the object is replaced. **/ - public void putValue( String name, Object value ) { + public void setAttribute( String name, Object value ) { if (_isInvalid) throw new IllegalStateException(); _values.put( name, value ); } @@ -147,7 +181,7 @@ * Removes the object bound with the specified name from this session. If the session does not * have an object bound with the specified name, this method does nothing. **/ - public void removeValue( String name ) { + public void removeAttribute( String name ) { if (_isInvalid) throw new IllegalStateException(); _values.remove( name ); } @@ -157,7 +191,7 @@ * Returns an array containing the names of all the objects bound to this session. * This method is useful, for example, when you want to delete all the objects bound to this session. **/ - public String[] getValueNames() { + public Enumeration getAttributeNames() { if (_isInvalid) throw new IllegalStateException(); throw new RuntimeException( "getValueNames not implemented" ); } |
From: Russell G. <rus...@us...> - 2000-11-21 20:56:32
|
Update of /cvsroot/httpunit/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv8051 Modified Files: build.xml Log Message: Make servletunit build conditional Index: build.xml =================================================================== RCS file: /cvsroot/httpunit/httpunit/build.xml,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- build.xml 2000/11/16 21:42:17 1.15 +++ build.xml 2000/11/21 20:56:29 1.16 @@ -24,6 +24,14 @@ <property name="test.class" value="com.meterware.httpunit.HttpUnitSuite" /> +<!-- =================================================================== --> +<!-- Check to see what optional dependencies are available --> +<!-- =================================================================== --> +<target name="check_for_optional_packages"> + <available property="jsdk.present" classname="javax.servlet.http.HttpServlet" /> +</target> + + <!-- =================================================================== --> <!-- Prepares the build directory --> <!-- =================================================================== --> @@ -35,10 +43,11 @@ <!-- =================================================================== --> <!-- Compiles the source code --> <!-- =================================================================== --> -<target name="compile" depends="prepare"> +<target name="compile" depends="prepare,check_for_optional_packages"> <mkdir dir="${build.classes}" /> <javac srcdir="${src.dir}" destdir="${build.classes}" classpath="${classpath}" debug="on" deprecation="on" optimize="off"> + <exclude name="**/servletunit/*" unless="jsdk.present" /> </javac> </target> @@ -46,9 +55,10 @@ <!-- =================================================================== --> <!-- Compiles the test code --> <!-- =================================================================== --> -<target name="testcompile" depends="compile"> +<target name="testcompile" depends="compile,check_for_optional_packages"> <javac srcdir="${tstsrc.dir}" destdir="${build.classes}" classpath="${classpath}" debug="on" deprecation="on" optimize="off"> + <exclude name="**/servletunit/*" unless="jsdk.present" /> </javac> </target> |
From: Russell G. <rus...@us...> - 2000-11-21 20:45:02
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv6274/test/com/meterware/servletunit Added Files: HttpServletRequestTest.java HttpServletResponseTest.java ServletUnitSuite.java ServletUnitTest.java SessionTest.java StatefulTest.java StatelessTest.java Log Message: Initial servletunit release ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') |
From: Russell G. <rus...@us...> - 2000-11-21 20:45:02
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv6274/test/com/meterware/httpunit Modified Files: PseudoServer.java PseudoServerTest.java WebFormTest.java WebPageTest.java Log Message: Initial servletunit release Index: PseudoServer.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- PseudoServer.java 2000/11/10 18:48:37 1.2 +++ PseudoServer.java 2000/11/21 20:44:59 1.3 @@ -142,10 +142,10 @@ } sendLine( ps, "" ); sendText( ps, resource.getContents() ); - ps.close(); } } + ps.close(); socket.close(); } Index: PseudoServerTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServerTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- PseudoServerTest.java 2000/11/10 18:48:37 1.3 +++ PseudoServerTest.java 2000/11/21 20:44:59 1.4 @@ -51,12 +51,14 @@ int port = ps.getConnectedPort(); WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + "/nothing" ); + WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + "/nothing.htm" ); try { WebResponse response = wc.getResponse( request ); fail( "Should have rejected the request" ); } catch (HttpNotFoundException e) { assertEquals( "Response code", HttpURLConnection.HTTP_NOT_FOUND, e.getResponseCode() ); + } finally { + ps.shutDown(); } } @@ -69,11 +71,15 @@ ps.setResource( resourceName, resourceValue ); int port = ps.getConnectedPort(); - WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + resourceName ); - WebResponse response = wc.getResponse( request ); - assertEquals( "requested resource", resourceValue, response.toString() ); - assertEquals( "content type", "text/html", response.getContentType() ); + try { + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + resourceName ); + WebResponse response = wc.getResponse( request ); + assertEquals( "requested resource", resourceValue, response.toString() ); + assertEquals( "content type", "text/html", response.getContentType() ); + } finally { + ps.shutDown(); + } } @@ -89,12 +95,43 @@ ps.setResource( resourceName, resourceValue ); ps.setResource( redirectName, "" ); ps.addResourceHeader( redirectName, "Location: http://localhost:" + port + '/' + resourceName ); + + try { + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + redirectName ); + WebResponse response = wc.getResponse( request ); + assertEquals( "requested resource", resourceValue, response.toString() ); + assertEquals( "content type", "text/html", response.getContentType() ); + } finally { + ps.shutDown(); + } + } + + - WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + redirectName ); - WebResponse response = wc.getResponse( request ); - assertEquals( "requested resource", resourceValue, response.toString() ); - assertEquals( "content type", "text/html", response.getContentType() ); + public void testCookies() throws Exception { + String resourceName = "something/interesting"; + String resourceValue = "the desired content\r\n"; + + PseudoServer ps = new PseudoServer(); + int port = ps.getConnectedPort(); + ps.setResource( resourceName, resourceValue ); + ps.addResourceHeader( resourceName, "Set-Cookie: age=12, name=george" ); + ps.addResourceHeader( resourceName, "Set-Cookie: type=short" ); + + try { + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + resourceName ); + WebResponse response = wc.getResponse( request ); + assertEquals( "requested resource", resourceValue, response.toString() ); + assertEquals( "content type", "text/html", response.getContentType() ); + assertEquals( "number of cookies", 3, 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" ) ); + } finally { + ps.shutDown(); + } } } Index: WebFormTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- WebFormTest.java 2000/10/31 19:54:15 1.8 +++ WebFormTest.java 2000/11/21 20:44:59 1.9 @@ -61,6 +61,20 @@ } + public void testFindFormByName() throws Exception { + defineWebPage( "Default", "<form name=oneForm method=POST action = \"/servlet/Login\">" + + "<Input name=\"secret\" type=\"hidden\" value=\"surprise\">" + + "<br><Input name=typeless value=nothing>" + + "<B>Enter the name 'master': <Input type=TEXT Name=name></B>" + + "<br><Input type=submit value = \"Log in\">" + + "</form>" ); + + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + assertNull( "Found nonexistent form", page.getFormWithName( "nobody" ) ); + assertNotNull( "Did not find named form", page.getFormWithName( "oneform" ) ); + } + + public void testFormParameters() throws Exception { WebForm form = _wc.getResponse( getHostPath() + "/OneForm.html" ).getForms()[0]; String[] parameters = form.getParameterNames(); Index: WebPageTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebPageTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- WebPageTest.java 2000/11/10 18:48:37 1.3 +++ WebPageTest.java 2000/11/21 20:44:59 1.4 @@ -114,5 +114,20 @@ } + public void testNoLocalFile() throws Exception { + File file = new File( "temp.html" ); + file.delete(); + + try { + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( "file:" + file.getAbsolutePath() ); + WebResponse simplePage = wc.getResponse( request ); + fail( "Should have complained about missing file" ); + } catch (java.io.FileNotFoundException e) { + } + + } + + } |
From: Russell G. <rus...@us...> - 2000-11-21 20:45:02
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv6274/src/com/meterware/servletunit Added Files: ServletRunner.java ServletUnitContext.java ServletUnitHttpRequest.java ServletUnitHttpResponse.java ServletUnitHttpSession.java ServletUnitWebResponse.java Log Message: Initial servletunit release ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') |
From: Russell G. <rus...@us...> - 2000-11-21 20:45:02
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv6274/src/com/meterware/httpunit Modified Files: GetMethodWebRequest.java HttpException.java HttpInternalErrorException.java HttpNotFoundException.java ParsedHTML.java PostMethodWebRequest.java WebConversation.java WebForm.java WebRequest.java WebResponse.java Added Files: HttpWebResponse.java WebClient.java Log Message: Initial servletunit release ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') Index: GetMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/GetMethodWebRequest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- GetMethodWebRequest.java 2000/10/31 19:54:15 1.6 +++ GetMethodWebRequest.java 2000/11/21 20:44:58 1.7 @@ -44,6 +44,14 @@ } + /** + * Returns the HTTP method defined for this request. + **/ + public String getMethod() { + return "GET"; + } + + //--------------------------------------- package members --------------------------------------------- Index: HttpException.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpException.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- HttpException.java 2000/10/12 16:16:35 1.1 +++ HttpException.java 2000/11/21 20:44:58 1.2 @@ -37,17 +37,31 @@ HttpException( int responseCode, String reason ) { - super( reason ); + _reason = reason; _responseCode = responseCode; } + public String getMessage() { + StringBuffer sb = new StringBuffer( "Error on HTTP request: " ); + sb.append( _responseCode ); + if (_reason != null) { + sb.append( " [" ); + sb.append( _reason ); + sb.append( " ]" ); + } + return sb.toString(); + } + + public int getResponseCode() { return _responseCode; } private int _responseCode; + + private String _reason; } Index: HttpInternalErrorException.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpInternalErrorException.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- HttpInternalErrorException.java 2000/10/12 16:16:35 1.2 +++ HttpInternalErrorException.java 2000/11/21 20:44:58 1.3 @@ -29,7 +29,7 @@ public class HttpInternalErrorException extends HttpException { - HttpInternalErrorException( String url ) { + public HttpInternalErrorException( String url ) { super( HttpURLConnection.HTTP_INTERNAL_ERROR, url ); } Index: HttpNotFoundException.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpNotFoundException.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- HttpNotFoundException.java 2000/10/12 16:16:35 1.2 +++ HttpNotFoundException.java 2000/11/21 20:44:58 1.3 @@ -30,7 +30,7 @@ public class HttpNotFoundException extends HttpException { - HttpNotFoundException( String url ) { + public HttpNotFoundException( String url ) { super( HttpURLConnection.HTTP_NOT_FOUND, url ); } Index: ParsedHTML.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ParsedHTML.java 2000/10/31 19:54:15 1.10 +++ ParsedHTML.java 2000/11/21 20:44:58 1.11 @@ -52,6 +52,19 @@ /** + * Returns the form found in the page with the specified name. + * @exception SAXException thrown if there is an error parsing the response. + **/ + public WebForm getFormWithName( String name ) { + WebForm[] forms = getForms(); + for (int i = 0; i < forms.length; i++) { + if (forms[i].getName().equalsIgnoreCase( name )) return forms[i]; + } + return null; + } + + + /** * Returns the links found in the page in the order in which they appear. **/ public WebLink[] getLinks() { Index: PostMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/PostMethodWebRequest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- PostMethodWebRequest.java 2000/10/31 19:54:15 1.7 +++ PostMethodWebRequest.java 2000/11/21 20:44:58 1.8 @@ -40,6 +40,14 @@ } + /** + * Returns the HTTP method defined for this request. + **/ + public String getMethod() { + return "POST"; + } + + //---------------------------------- WebRequest methods -------------------------------- Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- WebConversation.java 2000/11/10 18:48:37 1.17 +++ WebConversation.java 2000/11/21 20:44:58 1.18 @@ -19,22 +19,25 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ -import java.io.*; -import java.net.*; -import java.util.*; -import org.xml.sax.*; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.Dictionary; +import java.util.Enumeration; + + /** * The context for a series of HTTP requests. This class manages cookies used to maintain * session context, computes relative URLs, and generally emulates the browser behavior * needed to build an automated test of a web site. * * @author Russell Gold - * @author Jan Ohrstrom - * @author Seth Ladd **/ -public class WebConversation { +public class WebConversation extends WebClient { /** @@ -44,261 +47,40 @@ } - /** - * Returns the name of the currently active frames. - **/ - public String[] getFrameNames() { - Vector names = new Vector(); - for (Enumeration e = _frameContents.keys(); e.hasMoreElements();) { - names.addElement( e.nextElement() ); - } - - String[] result = new String[ names.size() ]; - names.copyInto( result ); - return result; - } +//---------------------------------- protected members -------------------------------- /** - * Returns the response associated with the specified frame name. + * Creates a web response object which represents the response to the specified web request. **/ - public WebResponse getFrameContents( String frameName ) { - WebResponse response = (WebResponse) _frameContents.get( frameName ); - if (response == null) throw new NoSuchFrameException( frameName ); - return response; - } - - - /** - * Submits a GET method request and returns a response. - **/ - public WebResponse getResponse( String urlString ) throws MalformedURLException, IOException, SAXException { - return getResponse( new GetMethodWebRequest( urlString ) ); - } - - - /** - * Submits a web request and returns a response, using all state developed so far as stored in - * cookies as requested by the server. - **/ - public WebResponse getResponse( WebRequest request ) throws MalformedURLException, IOException, SAXException { + protected WebResponse newResponse( WebRequest request ) throws MalformedURLException, IOException { URLConnection connection = openConnection( request.getURL() ); request.completeRequest( connection ); - updateCookies( connection ); - - if (connection.getHeaderField( "Location" ) != null) { - delay( HttpUnitOptions.getRedirectDelay() ); - return getResponse( new RedirectWebRequest( request, connection.getHeaderField( "Location" ) ) ); - } else { - if (connection instanceof HttpURLConnection) validateHeaders( request, (HttpURLConnection) connection ); - WebResponse result = new WebResponse( this, request.getTarget(), request.getURL(), connection ); - if (result.isHTML()) { - removeSubFrames( request.getTarget() ); - _frameContents.put( request.getTarget(), result ); - createSubFrames( request.getTarget(), result.getFrameNames() ); - WebRequest[] requests = result.getFrameRequests(); - for (int i = 0; i < requests.length; i++) getResponse( requests[i] ); - } - return result; - } - } - - - private void validateHeaders( WebRequest request, HttpURLConnection connection ) throws HttpException, IOException { - if (connection.getHeaderField( "WWW-Authenticate" ) != null) { - throw new AuthorizationRequiredException( connection.getHeaderField( "WWW-Authenticate" ) ); - } else if (connection.getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR) { - throw new HttpInternalErrorException( request.getURLString() ); - } else if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { - throw new HttpNotFoundException( request.getURLString() ); - } else if (connection.getResponseCode() >= HttpURLConnection.HTTP_BAD_REQUEST) { - throw new HttpException( connection.getResponseCode(), request.getURLString() ); - } - } - - - private void delay( int numMilliseconds ) { - if (numMilliseconds == 0) return; - try { - Thread.sleep( numMilliseconds ); - } catch (InterruptedException e) { - // ignore the exception - } + return new HttpWebResponse( request.getTarget(), request.getURL(), connection ); } - private void createSubFrames( String targetName, String[] frameNames ) { - _subFrames.put( targetName, frameNames ); - for (int i = 0; i < frameNames.length; i++) { - _frameContents.put( frameNames[i], WebResponse.BLANK_RESPONSE ); - } - } - - - private void removeSubFrames( String targetName ) { - String[] names = (String[]) _subFrames.get( targetName ); - if (names == null) return; - for (int i = 0; i < names.length; i++) { - removeSubFrames( names[i] ); - _frameContents.remove( names[i] ); - _subFrames.remove( names[i] ); - } - } - - - /** - * Defines a cookie to be sent to the server on every request. - **/ - public void addCookie(String name, String value) { - _cookies.put( name, value ); - } - - - /** - * Returns the name of all the active cookies which will be sent to the server. - **/ - public String[] getCookieNames() { - String[] names = new String[ _cookies.size() ]; - int i = 0; - for (Enumeration e = _cookies.keys(); e.hasMoreElements();) { - names[i++] = (String) e.nextElement(); - } - return names; - } - - - /** - * Returns the value of the specified cookie. - **/ - public String getCookieValue( String name ) { - return (String) _cookies.get( name ); - } - - - /** - * Specifies the user agent identification. Used to trigger browser-specific server behavior. - **/ - public void setUserAgent(String userAgent) { - _userAgent = userAgent; - } - - - /** - * Returns the current user agent setting. - **/ - public String getUserAgent() { - return _userAgent; - } - - - /** - * Sets a username and password for a basic authentication scheme. - **/ - public void setAuthorization( String userName, String password ) { - _authorization = "Basic " + Base64.encode( userName + ':' + password ); - } - - //---------------------------------- private members -------------------------------- - /** The currently defined cookies. **/ - private Hashtable _cookies = new Hashtable(); - - - /** The current user agent. **/ - private String _userAgent; - - - /** The authorization header value. **/ - private String _authorization; - - - /** A map of frame names to current contents. **/ - private Hashtable _frameContents = new Hashtable(); - - - /** A map of frame names to frames nested within them. **/ - private Hashtable _subFrames = new Hashtable(); - - static { HttpURLConnection.setFollowRedirects( false ); } + private URLConnection openConnection( URL url ) throws MalformedURLException, IOException { URLConnection connection = url.openConnection(); connection.setUseCaches( false ); - sendAuthorization( connection ); - sendUserAgent( connection ); - sendCookies( connection ); + sendHeaders( connection ); return connection; } - private void sendAuthorization( URLConnection connection ) { - if (_authorization == null) return; - connection.setRequestProperty( "Authorization", _authorization ); - } - - - private void sendUserAgent ( URLConnection connection ) { - if (getUserAgent() == null) return; - connection.setRequestProperty( "User-Agent" , getUserAgent() ); - } - - - private void sendCookies( URLConnection connection ) { - if (_cookies.size() == 0) return; - - StringBuffer sb = new StringBuffer(); - for (Enumeration e = _cookies.keys(); e.hasMoreElements();) { - String name = (String) e.nextElement(); - sb.append( name ).append( '=' ).append( _cookies.get( name ) ); - if (e.hasMoreElements()) sb.append( ';' ); - } - connection.setRequestProperty( "Cookie", sb.toString() ); - } - - - private void updateCookies( URLConnection connection ) { - for (int i = 1; true; i++) { - String key = connection.getHeaderFieldKey( i ); - if (key == null) break; - if (HttpUnitOptions.isLoggingHttpHeaders()) { - System.out.println( "Header:: " + connection.getHeaderFieldKey( i ) + ": " + connection.getHeaderField(i) ); - } - if (!key.equalsIgnoreCase( "Set-Cookie" )) continue; - StringTokenizer st = new StringTokenizer( connection.getHeaderField( i ), "=;" ); - String name = st.nextToken(); - String value = st.nextToken(); - _cookies.put( name, value ); - }; - } -} - - - -class RedirectWebRequest extends WebRequest { - - RedirectWebRequest( WebRequest baseRequest, String relativeURL ) throws MalformedURLException { - super( baseRequest, relativeURL ); - } - -} - - - -class NoSuchFrameException extends RuntimeException { - - NoSuchFrameException( String frameName ) { - _frameName = frameName; - } - - - public String getMessage() { - return "No frame named " + _frameName + " is currently active"; + private void sendHeaders( URLConnection connection ) { + Dictionary headers = getHeaderFields(); + for (Enumeration e = headers.keys(); e.hasMoreElements();) { + String key = (String) e.nextElement(); + connection.setRequestProperty( key, (String) headers.get( key ) ); + } } - - private String _frameName; } Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- WebForm.java 2000/11/10 18:48:37 1.15 +++ WebForm.java 2000/11/21 20:44:58 1.16 @@ -34,7 +34,7 @@ /** - * Returns the target for this link. + * Returns the target for this form. **/ public String getTarget() { if (_node.getAttributes().getNamedItem( "target" ) == null) { @@ -42,6 +42,14 @@ } else { return getValue( _node.getAttributes().getNamedItem( "target" ) ); } + } + + + /** + * Returns the name of the form. + **/ + public String getName() { + return emptyIfNull( getValue( _node.getAttributes().getNamedItem( "name" ) ) ); } Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- WebRequest.java 2000/11/02 18:37:37 1.10 +++ WebRequest.java 2000/11/21 20:44:58 1.11 @@ -83,6 +83,26 @@ } + /** + * Returns the query string defined for this request. + **/ + public String getQueryString() { + return getParameterString(); + } + + + /** + * Returns the HTTP method defined for this request. + **/ + abstract + public String getMethod(); + + + public String toString() { + return getMethod() + " request for " + getURLString(); + } + + //------------------------------------- protected members ------------------------------------ Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- WebResponse.java 2000/11/10 18:48:37 1.22 +++ WebResponse.java 2000/11/21 20:44:58 1.23 @@ -20,17 +20,32 @@ * *******************************************************************************************************************/ -import java.io.*; -import java.net.*; -import java.util.*; -import org.xml.sax.*; -import org.w3c.dom.*; +import java.io.IOException; +import java.io.StringReader; -import java.lang.reflect.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import java.net.URL; +import java.net.HttpURLConnection; + +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Vector; +import java.util.StringTokenizer; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + /** - * A response from a web server to an Http request. + * A response from a web server to a web request. **/ +abstract public class WebResponse { @@ -38,30 +53,46 @@ * Returns true if the response is HTML. **/ public boolean isHTML() { - return _contentType.equals( HTML_CONTENT ); + return getContentType().equals( HTML_CONTENT ); } /** - * Returns the response code associated with this response. + * Returns the URL which invoked this response. **/ - public int getResponseCode() { - return _responseCode; + public URL getURL() { + return _url; } /** - * Returns the URL which invoked this response. + * Returns the title of the page. **/ - public URL getURL() { - return _url; + public String getTitle() throws SAXException { + return getReceivedPage().getTitle(); + } + + + /** + * Returns the target of the page. + **/ + public String getTarget() throws SAXException { + return _target; } /** + * Returns the response code associated with this response. + **/ + abstract + public int getResponseCode(); + + + /** * Returns the content type of this response. **/ public String getContentType() { + if (_contentType == null) readContentTypeHeader(); return _contentType; } @@ -70,27 +101,50 @@ * Returns the character set used in this response. **/ public String getCharacterSet() { + if (_characterSet == null) readContentTypeHeader(); return _characterSet; } /** - * Returns the title of the page. + * Returns a list of new cookie names defined as part of this response. **/ - public String getTitle() throws SAXException { - return getReceivedPage().getTitle(); + public String[] getNewCookieNames() { + String[] names = new String[ getNewCookies().size() ]; + int i = 0; + for (Enumeration e = getNewCookies().keys(); e.hasMoreElements(); i++ ) { + names[i] = (String) e.nextElement(); + } + return names; } /** - * Returns the target of the page. + * Returns the new cookie value defined as part of this response. **/ - public String getTarget() throws SAXException { - return _target; + public String getNewCookieValue( String name ) { + return (String) getNewCookies().get( name ); } + + /** + * Returns the value for the specified header field. If no such field is defined, will return null. + * No more than one header may be defined for each key. + **/ + abstract + public String getHeaderField( String fieldName ); + + /** + * Returns the text of the response (excluding headers) as a string. Use this method in preference to 'toString' + * which may be used to represent internal state of this object. + **/ + abstract + public String getText(); + + + /** * Returns the names of the frames found in the page in the order in which they appear. **/ public String[] getFrameNames() throws SAXException { @@ -114,6 +168,15 @@ /** + * Returns the form found in the page with the specified name. + * @exception SAXException thrown if there is an error parsing the response. + **/ + public WebForm getFormWithName( String name ) throws SAXException { + return getReceivedPage().getFormWithName( name ); + } + + + /** * Returns the links found in the page in the order in which they appear. * @exception SAXException thrown if there is an error parsing the response. **/ @@ -198,47 +261,31 @@ } - /** - * Returns the text of the response (excluding headers) as a string. Use this method in preference to 'toString' - * which may be used to represent internal state of this object. - **/ - public String getText() { - return _responseText; - } - - public String toString() { - return _responseText; + return getText(); } - -//---------------------------------- package members -------------------------------- +//----------------------------------------- protected members ----------------------------------------------- - final static WebResponse BLANK_RESPONSE = new WebResponse( "<html><head></head><body></body></html>" ); - /** - * Constructs a response object from an input stream. - * @param conversation the web conversation which received the response + * Constructs a response object. * @param url the url from which the response was received * @param inputStream the input stream from which the response can be read **/ - WebResponse( WebConversation conversation, String target, URL url, URLConnection connection ) { - this( conversation, target, url, getResponseText( url, connection ) ); - readHeaders( connection ); + protected WebResponse( String target, URL url ) { + _url = url; + _target = target; } - /** - * Returns the web conversation of which this response is a part, and which contains the session - * context information required for further requests. - **/ - WebConversation getWebConversation() { - return _conversation; - } +//------------------------------------------ package members ------------------------------------------------ + + final static WebResponse BLANK_RESPONSE = new DefaultWebResponse( "<html><head></head><body></body></html>" ); + /** * Returns the frames found in the page in the order in which they appear. **/ @@ -259,72 +306,62 @@ //--------------------------------- private members -------------------------------------- - - final private static String endOfLine = System.getProperty( "line.separator" ); + final private static String DEFAULT_CONTENT_HEADER = "text/plain; charset=us-ascii"; - final private static String HTML_CONTENT = "text/html"; private WebFrame[] _frames; private ReceivedPage _page; - private String _responseText; + private String _contentType; - private String _contentType = "text/plain"; + private String _characterSet; - private String _characterSet = "us-ascii"; + private Hashtable _newCookies; - private int _responseCode; - // the following variables are essentially final; however, the JDK 1.1 compiler does not handle final variables properly with // multiple constructors that call each other, so the final qualifiers have been removed. private URL _url; - private WebConversation _conversation; - private String _target; - /** - * Constructs a response object from a text response. - **/ - private WebResponse( String responseText ) { - this( null, "", null, responseText ); - _contentType = HTML_CONTENT; + private Hashtable getNewCookies() { + if (_newCookies == null) { + _newCookies = new Hashtable(); + String cookieHeader = getHeaderField( "Set-Cookie" ); + if (cookieHeader != null) { + StringTokenizer st = new StringTokenizer( cookieHeader, "," ); + while (st.hasMoreTokens()) recognizeOneCookie( st.nextToken() ); + } + } + return _newCookies; } - /** - * Constructs a response object. - * @param conversation the web conversation which received the response - * @param url the url from which the response was received - * @param inputStream the input stream from which the response can be read - **/ - private WebResponse( WebConversation conversation, String target, URL url, String responseText ) { - _conversation = conversation; - _url = url; - _target = target; - _responseText = responseText; + private void recognizeOneCookie( String cookieSpec ) { + StringTokenizer st = new StringTokenizer( cookieSpec, "=;" ); + String name = st.nextToken().trim(); + String value = st.nextToken().trim(); + _newCookies.put( name, value ); } - - private static String getResponseText( URL url, URLConnection connection ) { - StringBuffer sb = new StringBuffer(); - try { - BufferedReader input = new BufferedReader( new InputStreamReader( connection.getInputStream() ) ); - String str; - while (null != ((str = input.readLine()))) { - sb.append( str ).append( endOfLine ); + private void readContentTypeHeader() { + String contentHeader = getHeaderField( "Content-type" ); + if (contentHeader == null) contentHeader = DEFAULT_CONTENT_HEADER; + StringTokenizer st = new StringTokenizer( contentHeader, ";=" ); + _contentType = st.nextToken(); + while (st.hasMoreTokens()) { + String parameter = st.nextToken(); + if (st.hasMoreTokens()) { + String value = st.nextToken(); + if (parameter.equalsIgnoreCase( "charset" )) _characterSet = value; } - input.close (); - return sb.toString(); - } catch (IOException e) { - throw new RuntimeException( "Unable to retrieve data from URL: " + url.toExternalForm() + " (" + e + ")" ); } } @@ -348,7 +385,7 @@ private ReceivedPage getReceivedPage() throws SAXException { if (_page == null) { if (!isHTML()) throw new RuntimeException( "Response is not HTML" ); - _page = new ReceivedPage( _url, _target, _responseText ); + _page = new ReceivedPage( _url, _target, getText() ); } return _page; } @@ -363,7 +400,7 @@ Object parser = constructor.newInstance( null ); Class[] parseMethodArgTypes = { InputSource.class }; - Object[] parseMethodArgs = { new InputSource( new StringReader( _responseText ) ) }; + Object[] parseMethodArgs = { new InputSource( new StringReader( getText() ) ) }; Method parseMethod = parserClass.getMethod( "parse", parseMethodArgTypes ); parseMethod.invoke( parser, parseMethodArgs ); @@ -392,33 +429,48 @@ } - private void readHeaders( URLConnection connection ) { - readContentTypeHeader( connection ); - try { - if (connection instanceof HttpURLConnection) { - _responseCode = ((HttpURLConnection) connection).getResponseCode(); - } else { - _responseCode = HttpURLConnection.HTTP_OK; - } - } catch (IOException e) { - } +} + + + +class DefaultWebResponse extends WebResponse { + + + DefaultWebResponse( String text ) { + super( "", null ); + _responseText = text; } - private void readContentTypeHeader( URLConnection connection ) { - String contentHeader = connection.getContentType(); - if (contentHeader != null) { - StringTokenizer st = new StringTokenizer( contentHeader, ";=" ); - _contentType = st.nextToken(); - while (st.hasMoreTokens()) { - String parameter = st.nextToken(); - if (st.hasMoreTokens()) { - String value = st.nextToken(); - if (parameter.equalsIgnoreCase( "charset" )) _characterSet = value; - } - } - } + /** + * Returns the response code associated with this response. + **/ + public int getResponseCode() { + return HttpURLConnection.HTTP_OK; } + + /** + * Returns the value for the specified header field. If no such field is defined, will return null. + **/ + public String getHeaderField( String fieldName ) { + if (fieldName.equals( "Content-type" )) { + return "text/html; charset=us-ascii"; + } else { + return null; + } + } + + + /** + * Returns the text of the response (excluding headers) as a string. Use this method in preference to 'toString' + * which may be used to represent internal state of this object. + **/ + public String getText() { + return _responseText; + } + + + private String _responseText; } |