httpunit-commit Mailing List for httpunit (Page 62)
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...> - 2002-05-20 16:00:46
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv31967/src/com/meterware/servletunit Modified Files: ServletRunner.java Log Message: Removed unused fields, methods, and imports Index: ServletRunner.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletRunner.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- ServletRunner.java 8 May 2002 19:20:59 -0000 1.14 +++ ServletRunner.java 20 May 2002 16:00:44 -0000 1.15 @@ -19,15 +19,9 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ -import com.meterware.httpunit.WebResponse; -import com.meterware.httpunit.WebRequest; -import com.meterware.httpunit.HttpNotFoundException; -import com.meterware.httpunit.HttpInternalErrorException; -import com.meterware.httpunit.HttpUnitUtils; - import java.io.File; -import java.io.InputStream; import java.io.IOException; +import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.Dictionary; @@ -36,9 +30,12 @@ import javax.servlet.ServletException; import javax.servlet.http.Cookie; -import org.xml.sax.SAXException; +import com.meterware.httpunit.HttpUnitUtils; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + import org.xml.sax.InputSource; -import org.w3c.dom.Document; +import org.xml.sax.SAXException; /** |
From: Russell G. <rus...@us...> - 2002-05-20 16:00:17
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv31693/doc Modified Files: release_notes.txt Log Message: Implemented access to request message body Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.108 retrieving revision 1.109 diff -u -r1.108 -r1.109 --- release_notes.txt 16 May 2002 19:04:12 -0000 1.108 +++ release_notes.txt 20 May 2002 16:00:14 -0000 1.109 @@ -11,10 +11,13 @@ Revision History: +20-May-2002 +Additions: + 1. ServletUnitHttpRequest now implements getInputStream and getContentType. + 16-May-2002 Acknowledgements: - Thanks to James Murty for adding caching of servlet instances, a default mapping for servlet classes, and some XML - parsing cleanup. + Thanks to James Murty for adding caching of servlet instances and some XML parsing cleanup. Additions: 1. ServletUnit now caches its servlet instances so that multiple invocations can use the same instance. This more |
From: Russell G. <rus...@us...> - 2002-05-20 16:00:17
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv31693/test/com/meterware/servletunit Modified Files: HttpServletRequestTest.java Log Message: Implemented access to request message body Index: HttpServletRequestTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/HttpServletRequestTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- HttpServletRequestTest.java 3 Mar 2002 23:00:00 -0000 1.5 +++ HttpServletRequestTest.java 20 May 2002 16:00:13 -0000 1.6 @@ -20,18 +20,18 @@ * *******************************************************************************************************************/ import java.util.Enumeration; -import java.util.Vector; import java.util.Hashtable; -import javax.servlet.ServletException; -import javax.servlet.http.*; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import com.meterware.httpunit.GetMethodWebRequest; +import com.meterware.httpunit.WebRequest; import junit.framework.Test; -import junit.framework.TestCase; import junit.framework.TestSuite; -import com.meterware.httpunit.*; - /** * Tests the ServletUnitHttpRequest class. **/ @@ -58,6 +58,7 @@ assertNull( "Authorization incorrectly specified", request.getAuthType() ); assertNull( "Character encoding incorrectly specified", request.getCharacterEncoding() ); assertEquals( "Parameters unexpectedly specified", "", request.getQueryString() ); + assertNotNull( "No input stream available", request.getInputStream() ); } |
From: Russell G. <rus...@us...> - 2002-05-20 16:00:16
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv31693/src/com/meterware/servletunit Modified Files: ServletUnitHttpRequest.java Added Files: ServletInputStreamImpl.java Log Message: Implemented access to request message body ***** Error reading new file[Errno 2] No such file or directory: 'ServletInputStreamImpl.java' Index: ServletUnitHttpRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ServletUnitHttpRequest.java 1 Mar 2002 06:08:24 -0000 1.10 +++ ServletUnitHttpRequest.java 20 May 2002 16:00:13 -0000 1.11 @@ -50,6 +50,9 @@ **/ class ServletUnitHttpRequest implements HttpServletRequest { + private ServletInputStreamImpl _inputStream; + private String _contentType; + /** * Constructs a ServletUnitHttpRequest from a WebRequest object. @@ -61,14 +64,14 @@ _headers.addEntries( clientHeaders ); _headers.addEntries( request.getHeaders() ); _messageBody = messageBody; + readContentTypeHeader(); if (context == null) throw new IllegalArgumentException( "Context must not be null" ); String file = request.getURL().getFile(); if (file.indexOf( '?' ) >= 0) { loadParameters( file.substring( file.indexOf( '?' )+1 ) ); } else { - final Object contentType = _headers.get( "Content-Type" ); - if (contentType == null || contentType.toString().indexOf( "x-www-form-urlencoded" ) >= 0 ) { + if (_contentType == null || _contentType.indexOf( "x-www-form-urlencoded" ) >= 0 ) { loadParameters( request.getQueryString() ); loadParameters( new String( _messageBody ) ); } @@ -76,6 +79,14 @@ } + private void readContentTypeHeader() { + _contentType = (String) _headers.get( "Content-Type" ); + if (_contentType != null && _contentType.indexOf( ';' ) >= 0) { + _contentType = _contentType.substring( 0, _contentType.indexOf( ';' ) ); + } + } + + //----------------------------------------- HttpServletRequest methods -------------------------- @@ -333,8 +344,10 @@ * */ public ServletInputStream getInputStream() throws IOException { - throwNotImplementedYet(); - return null; + if (_inputStream == null) { + _inputStream = new ServletInputStreamImpl( _messageBody ); + } + return _inputStream; } @@ -369,7 +382,7 @@ * of the CGI variable CONTENT_TYPE. **/ public String getContentType() { - return null; + return _contentType; } |
From: Russell G. <rus...@us...> - 2002-05-16 19:31:51
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv6000/src/com/meterware/servletunit Modified Files: WebApplication.java Log Message: Support servlet class name as URL Index: WebApplication.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/WebApplication.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- WebApplication.java 16 May 2002 17:44:20 -0000 1.7 +++ WebApplication.java 16 May 2002 19:04:13 -0000 1.8 @@ -51,6 +51,7 @@ * application. It is usually extracted from web.xml. * * @author <a href="mailto:rus...@ac...">Russell Gold</a> + * @author <a href="ba...@we...">Donald Ball</a> **/ class WebApplication { @@ -487,9 +488,6 @@ /** * A utility class for mapping servlets to url patterns. This implements the * matching algorithm documented in section 10 of the JSDK-2.2 reference. - * - * @author <a href="ba...@we...">Donald Ball</a> - * @version $Revision$ */ class ServletMapping { @@ -522,31 +520,45 @@ ServletConfiguration get( String url ) { - if (_exactMatches.containsKey( url )) { - return (ServletConfiguration) _exactMatches.get( url ); + if (_exactMatches.containsKey( url )) return (ServletConfiguration) _exactMatches.get( url ); + + Map context = getContextForLongestPathPrefix( url ); + if (context.containsKey( "*" )) return (ServletConfiguration) context.get( "*" ); + + if (_extensions.containsKey( getExtension( url ))) return (ServletConfiguration) _extensions.get( getExtension( url ) ); + + if (_urlTree.containsKey( "/" )) return (ServletConfiguration) _urlTree.get( "/" ); + + String className = url.substring( 1 ); + try { + Class.forName( className ); + return new ServletConfiguration( className ); + } catch (ClassNotFoundException e) { + return null; } - ParsedPath path = new ParsedPath( url ); + } + + + private Map getContextForLongestPathPrefix( String url ) { Map context = _urlTree; + + ParsedPath path = new ParsedPath( url ); while (path.hasNext()) { String part = path.next(); - if (!context.containsKey( part )) { - if (context.containsKey( "*" )) { - return (ServletConfiguration) context.get( "*" ); - } else { - int index = url.lastIndexOf( '.' ); - if (index == -1 || index == url.length() - 1) { - return null; - } else { - return (ServletConfiguration) _extensions.get( url.substring( index + 1 ) ); - } - } - } + if (!context.containsKey( part )) break; context = (Map) context.get( part ); } - if (context.containsKey( "*" )) { - return (ServletConfiguration) context.get( "*" ); + return context; + } + + + private String getExtension( String url ) { + int index = url.lastIndexOf( '.' ); + if (index == -1 || index >= url.length() - 1) { + return ""; + } else { + return url.substring( index + 1 ); } - return (ServletConfiguration) context.get( "/" ); } } |
From: Russell G. <rus...@us...> - 2002-05-16 19:31:51
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv6000/doc Modified Files: release_notes.txt Log Message: Support servlet class name as URL Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.107 retrieving revision 1.108 diff -u -r1.107 -r1.108 --- release_notes.txt 16 May 2002 17:44:17 -0000 1.107 +++ release_notes.txt 16 May 2002 19:04:12 -0000 1.108 @@ -20,6 +20,9 @@ 1. ServletUnit now caches its servlet instances so that multiple invocations can use the same instance. This more closely matches the servlet spec. 2. Leading and trailing spaces in web.xml text nodes are now ignored. + 3. If no other mapping matches a servlet name in a URL, ServletUnit will try to treat it as a servlet class name. + This means that you can use something like http://localhost/com.nowhere.MyServlet to access your servlet without + explicitly registering it. 14-May-2002 Additions: |
From: Russell G. <rus...@us...> - 2002-05-16 19:31:51
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv6000/test/com/meterware/servletunit Modified Files: StatelessTest.java WebXMLTest.java Log Message: Support servlet class name as URL Index: StatelessTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/StatelessTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- StatelessTest.java 16 May 2002 17:44:20 -0000 1.5 +++ StatelessTest.java 16 May 2002 19:04:13 -0000 1.6 @@ -4,12 +4,12 @@ * * Copyright (c) 2000-2001, Russell Gold * -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -* documentation files (the "Software"), to deal in the Software without restriction, including without limitation +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +* documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * -* The above copyright notice and this permission notice shall be included in all copies or substantial portions +* The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO @@ -38,8 +38,8 @@ public static void main(String args[]) { junit.textui.TestRunner.run( suite() ); } - - + + public static Test suite() { return new TestSuite( StatelessTest.class ); } @@ -72,6 +72,17 @@ WebRequest request = new GetMethodWebRequest( "http://localhost/" + resourceName ); assertEquals( "First reply", "1", sr.getResponse( request ).getText().trim() ); assertEquals( "Second reply", "2", sr.getResponse( request ).getText().trim() ); + } + + + public void testServletAccessByClassName() throws Exception { + ServletRunner sr = new ServletRunner(); + + WebRequest request = new GetMethodWebRequest( "http://localhost/" + SimpleGetServlet.class.getName() ); + WebResponse response = sr.getResponse( request ); + assertNotNull( "No response received", response ); + assertEquals( "content type", "text/html", response.getContentType() ); + assertEquals( "requested resource", SimpleGetServlet.RESPONSE_TEXT, response.getText() ); } Index: WebXMLTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/WebXMLTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- WebXMLTest.java 3 Mar 2002 23:00:00 -0000 1.7 +++ WebXMLTest.java 16 May 2002 19:04:13 -0000 1.8 @@ -31,7 +31,6 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.servlet.Servlet; import javax.servlet.ServletException; import org.xml.sax.SAXException; @@ -165,9 +164,8 @@ ServletRunner sr = new ServletRunner( toInputStream( wxs.asText() ) ); ServletUnitClient wc = sr.newClient(); - WebResponse response = null; try { - response = wc.getResponse( "http://localhost/SimpleServlet" ); + wc.getResponse( "http://localhost/SimpleServlet" ); fail( "Did not insist on validation for access to servlet" ); } catch (AuthorizationRequiredException e) { assertEquals( "Realm", "Sample Realm", e.getAuthenticationParameter( "realm" ) ); @@ -251,7 +249,7 @@ try { ic = wc.newInvocation( "http://localhost/SimpleServlet" ); - Servlet servlet = ic.getServlet(); + ic.getServlet(); fail("Attempt to access url outside of the webapp context path should have thrown a 404"); } catch (com.meterware.httpunit.HttpNotFoundException e) {} } @@ -277,7 +275,7 @@ assertTrue(ic.getServlet() instanceof Servlet3); try { ic = wc.newInvocation("http://localhost/catalog/index.html"); - Servlet servlet = ic.getServlet(); + ic.getServlet(); fail("Should have gotten a 404"); } catch (HttpNotFoundException e) {} ic = wc.newInvocation("http://localhost/catalog/racecar.bop"); @@ -286,9 +284,6 @@ assertTrue(ic.getServlet() instanceof Servlet4); } - private final static String DOCTYPE = "<!DOCTYPE web-app PUBLIC " + - " \"-//Sun Microsystems, Inc.//DTD WebApplication 2.2//EN\" " + - " \"http://java.sun/com/j2ee/dtds/web-app_2_2.dtd\">"; //=============================================================================================================== @@ -343,6 +338,7 @@ static class Servlet2 extends SimpleGetServlet {} static class Servlet3 extends SimpleGetServlet {} static class Servlet4 extends SimpleGetServlet {} + static class Servlet5 extends SimpleGetServlet {} } |
From: Russell G. <rus...@us...> - 2002-05-16 17:44:23
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv9233/test/com/meterware/servletunit Modified Files: StatelessTest.java Log Message: from James Murty: support servlet caching, XML parsing cleanup Index: StatelessTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/StatelessTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- StatelessTest.java 26 Nov 2001 14:20:13 -0000 1.4 +++ StatelessTest.java 16 May 2002 17:44:20 -0000 1.5 @@ -55,7 +55,7 @@ WebRequest request = new GetMethodWebRequest( "http://localhost/nothing" ); try { - WebResponse response = sr.getResponse( request ); + sr.getResponse( request ); fail( "Should have rejected the request" ); } catch (HttpNotFoundException e) { assertEquals( "Response code", HttpURLConnection.HTTP_NOT_FOUND, e.getResponseCode() ); @@ -63,6 +63,17 @@ } + public void testServletCaching() throws Exception { + final String resourceName = "something/interesting"; + + ServletRunner sr = new ServletRunner(); + sr.registerServlet( resourceName, AccessCountServlet.class.getName() ); + + WebRequest request = new GetMethodWebRequest( "http://localhost/" + resourceName ); + assertEquals( "First reply", "1", sr.getResponse( request ).getText().trim() ); + assertEquals( "Second reply", "2", sr.getResponse( request ).getText().trim() ); + } + public void testSimpleGet() throws Exception { final String resourceName = "something/interesting"; @@ -137,8 +148,6 @@ - - static class SimpleGetServlet extends HttpServlet { static String RESPONSE_TEXT = "the desired content\r\n"; @@ -146,6 +155,18 @@ resp.setContentType( "text/html" ); PrintWriter pw = resp.getWriter(); pw.print( RESPONSE_TEXT ); + pw.close(); + } + } + + + static class AccessCountServlet extends HttpServlet { + private int _numAccesses; + + protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException,IOException { + resp.setContentType( "text/plain" ); + PrintWriter pw = resp.getWriter(); + pw.print( String.valueOf( ++_numAccesses ) ); pw.close(); } } |
From: Russell G. <rus...@us...> - 2002-05-16 17:44:23
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv9233/src/com/meterware/servletunit Modified Files: WebApplication.java Log Message: from James Murty: support servlet caching, XML parsing cleanup Index: WebApplication.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/WebApplication.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- WebApplication.java 8 May 2002 19:20:59 -0000 1.6 +++ WebApplication.java 16 May 2002 17:44:20 -0000 1.7 @@ -119,16 +119,20 @@ } - Servlet getServlet( URL url ) throws ServletException { + synchronized Servlet getServlet( URL url ) throws ServletException { final ServletConfiguration configuration = getServletConfiguration( url ); if (configuration == null) throw new HttpNotFoundException( url ); try { Class servletClass = Class.forName( configuration.getClassName() ); - if (!Servlet.class.isAssignableFrom( servletClass )) throw new HttpInternalErrorException( url ); - Servlet servlet = (Servlet) servletClass.newInstance(); // XXX cache instances - by class? + Servlet cachedServlet = (Servlet)_cachedServlets.get(servletClass); + if (cachedServlet != null) return cachedServlet; + + if (!Servlet.class.isAssignableFrom( servletClass )) throw new HttpInternalErrorException( url ); + Servlet servlet = (Servlet) servletClass.newInstance(); servlet.init( new ServletUnitServletConfig( servlet, this, configuration.getInitParams(), _contextParameters, _contextDir ) ); + _cachedServlets.put( servletClass, servlet ); return servlet; } catch (ClassNotFoundException e) { throw new HttpNotFoundException( url, e ); @@ -198,7 +202,7 @@ /** * Returns true if the specified path may only be accesses by an authorized user. - * @param urlPath the application-relative path of the URL + * @param url the application-relative path of the URL */ boolean requiresAuthorization( URL url ) { return getControllingConstraint( getURLPath( url ) ) != NULL_SECURITY_CONSTRAINT; @@ -247,6 +251,8 @@ private String _contextPath = null; + private HashMap _cachedServlets = new HashMap(); + final static private SecurityConstraint NULL_SECURITY_CONSTRAINT = new NullSecurityConstraint(); @@ -309,7 +315,7 @@ private static String getChildNodeValue( Element root, String childNodeName, String defaultValue ) throws SAXException { NodeList nl = root.getElementsByTagName( childNodeName ); if (nl.getLength() == 1) { - return getTextValue( nl.item( 0 ) ); + return getTextValue( nl.item( 0 ) ).trim(); } else if (defaultValue == null) { throw new SAXException( "Node <" + root.getNodeName() + "> has no child named <" + childNodeName + ">" ); } else { @@ -320,7 +326,7 @@ private static String getTextValue( Node node ) throws SAXException { Node textNode = node.getFirstChild(); - if (textNode == null) throw new SAXException( "No value specified for <" + node.getNodeName() + "> node" ); + if (textNode == null) return ""; if (textNode.getNodeType() != Node.TEXT_NODE) throw new SAXException( "No text value found for <" + node.getNodeName() + "> node" ); return textNode.getNodeValue(); } @@ -331,15 +337,6 @@ } - private String asResourceName( String rawName ) { // XXX remove me - if (rawName.startsWith( "/" )) { - return rawName; - } else { - return "/" + rawName; - } - } - - private String getServletName( String urlFile ) { if (urlFile.indexOf( '?' ) < 0) { return urlFile; @@ -496,19 +493,18 @@ */ class ServletMapping { - private final Map exactMatches = new HashMap(); - private final Map extensions = new HashMap(); - private final Map urlTree = new HashMap(); - + private final Map _exactMatches = new HashMap(); + private final Map _extensions = new HashMap(); + private final Map _urlTree = new HashMap(); void put( String mapping, ServletConfiguration servletConfiguration ) { if (mapping.indexOf( '*' ) == -1) { - exactMatches.put( mapping, servletConfiguration ); + _exactMatches.put( mapping, servletConfiguration ); } else if (mapping.startsWith( "*." )) { - extensions.put( mapping.substring( 2 ), servletConfiguration ); + _extensions.put( mapping.substring( 2 ), servletConfiguration ); } else { ParsedPath path = new ParsedPath( mapping ); - Map context = urlTree; + Map context = _urlTree; while (path.hasNext()) { String part = path.next(); if (part.equals( "*" )) { @@ -526,11 +522,11 @@ ServletConfiguration get( String url ) { - if (exactMatches.containsKey( url )) { - return (ServletConfiguration) exactMatches.get( url ); + if (_exactMatches.containsKey( url )) { + return (ServletConfiguration) _exactMatches.get( url ); } ParsedPath path = new ParsedPath( url ); - Map context = urlTree; + Map context = _urlTree; while (path.hasNext()) { String part = path.next(); if (!context.containsKey( part )) { @@ -541,7 +537,7 @@ if (index == -1 || index == url.length() - 1) { return null; } else { - return (ServletConfiguration) extensions.get( url.substring( index + 1 ) ); + return (ServletConfiguration) _extensions.get( url.substring( index + 1 ) ); } } } |
From: Russell G. <rus...@us...> - 2002-05-16 17:44:23
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv9233/src/com/meterware/httpunit Modified Files: WebResponse.java Added Files: NotHTMLException.java Log Message: from James Murty: support servlet caching, XML parsing cleanup ***** Error reading new file[Errno 2] No such file or directory: 'NotHTMLException.java' Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.64 retrieving revision 1.65 diff -u -r1.64 -r1.65 --- WebResponse.java 6 Mar 2002 04:59:52 -0000 1.64 +++ WebResponse.java 16 May 2002 17:44:20 -0000 1.65 @@ -20,17 +20,16 @@ * *******************************************************************************************************************/ -import java.io.*; - - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StreamTokenizer; +import java.io.StringReader; +import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; - import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; @@ -39,7 +38,6 @@ 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; @@ -95,7 +93,6 @@ * </code> * will return "/mystyle.css". * @exception SAXException thrown if there is an error parsing this response - * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a> **/ public String getExternalStyleSheet() throws SAXException { return getReceivedPage().getExternalStyleSheet(); @@ -655,7 +652,7 @@ * This method does not parse path,domain,expires or secure information * about the cookie.</p> * - * @returns Hashtable a <code>Hashtable</code> of where the name of the + * @return Hashtable a <code>Hashtable</code> of where the name of the * cookie is the key and the value of the cookie is * the value */ @@ -1033,24 +1030,5 @@ private String _responseText; -} - - -//================================================================================================== - - -class NotHTMLException extends RuntimeException { - - NotHTMLException( String contentType ) { - _contentType = contentType; - } - - - public String getMessage() { - return "The content type of the response is '" + _contentType + "': it must be 'text/html' in order to be recognized as HTML"; - } - - - private String _contentType; } |
From: Russell G. <rus...@us...> - 2002-05-16 17:44:22
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv9233/doc Modified Files: release_notes.txt Log Message: from James Murty: support servlet caching, XML parsing cleanup Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.106 retrieving revision 1.107 diff -u -r1.106 -r1.107 --- release_notes.txt 14 May 2002 19:31:04 -0000 1.106 +++ release_notes.txt 16 May 2002 17:44:17 -0000 1.107 @@ -11,6 +11,16 @@ Revision History: +16-May-2002 +Acknowledgements: + Thanks to James Murty for adding caching of servlet instances, a default mapping for servlet classes, and some XML + parsing cleanup. + +Additions: + 1. ServletUnit now caches its servlet instances so that multiple invocations can use the same instance. This more + closely matches the servlet spec. + 2. Leading and trailing spaces in web.xml text nodes are now ignored. + 14-May-2002 Additions: 1. A <select> control with a size attribute may now have its value undefined. The specification does not require |
From: Russell G. <rus...@us...> - 2002-05-14 19:31:07
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv32042/src/com/meterware/httpunit Modified Files: ParsedHTML.java WebClient.java Log Message: Cache computed WebForm array Index: ParsedHTML.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- ParsedHTML.java 27 Nov 2001 19:51:27 -0000 1.19 +++ ParsedHTML.java 14 May 2002 19:31:04 -0000 1.20 @@ -31,6 +31,8 @@ **/ class ParsedHTML { + private WebForm[] _forms; + ParsedHTML( URL baseURL, String baseTarget, Node rootNode, String characterSet ) { _baseURL = baseURL; @@ -44,13 +46,15 @@ * Returns the forms found in the page in the order in which they appear. **/ public WebForm[] getForms() { - NodeList forms = NodeUtils.getElementsByTagName( _rootNode, "form" ); - WebForm[] result = new WebForm[ forms.getLength() ]; - for (int i = 0; i < result.length; i++) { - result[i] = new WebForm( _baseURL, _baseTarget, forms.item( i ), _characterSet ); - } + if (_forms == null) { + NodeList forms = NodeUtils.getElementsByTagName( _rootNode, "form" ); - return result; + _forms = new WebForm[ forms.getLength() ]; + for (int i = 0; i < _forms.length; i++) { + _forms[i] = new WebForm( _baseURL, _baseTarget, forms.item( i ), _characterSet ); + } + } + return _forms; } Index: WebClient.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- WebClient.java 11 Mar 2002 12:34:31 -0000 1.22 +++ WebClient.java 14 May 2002 19:31:04 -0000 1.23 @@ -59,6 +59,14 @@ /** + * Submits a web request and returns a response. This is an alternate name for the getResponse method. + */ + public WebResponse sendRequest( WebRequest request ) throws MalformedURLException, IOException, SAXException { + return getResponse( request ); + } + + + /** * Submits a web request and returns a response, using all state developed so far as stored in * cookies as requested by the server. * @exception SAXException thrown if there is an error parsing the retrieved page |
From: Russell G. <rus...@us...> - 2002-05-14 19:31:07
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv32042/doc Modified Files: release_notes.txt Log Message: Cache computed WebForm array Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.105 retrieving revision 1.106 diff -u -r1.105 -r1.106 --- release_notes.txt 14 May 2002 18:38:54 -0000 1.105 +++ release_notes.txt 14 May 2002 19:31:04 -0000 1.106 @@ -12,9 +12,11 @@ Revision History: 14-May-2002 -Problems fixed: +Additions: 1. A <select> control with a size attribute may now have its value undefined. The specification does not require this behavior, but both IE 5.5 and Netscape 6.2 do this. + 2. WebResponse.getForms now caches its result so that multiple calls will return the same set of objects. + 3. WebClient.sendRequest is now available as an alias for WebRequest.getResponse 9-May-2002 Acknowledgements: |
From: Russell G. <rus...@us...> - 2002-05-14 18:38:57
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv13154/test/com/meterware/httpunit Modified Files: WebFormTest.java Log Message: Allowed sized selects to have no selected value Index: WebFormTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- WebFormTest.java 6 Feb 2002 18:38:13 -0000 1.20 +++ WebFormTest.java 14 May 2002 18:38:54 -0000 1.21 @@ -263,6 +263,20 @@ } + public void testSizedSelect() throws Exception { + defineWebPage( "Default", "<form method=POST action = '/servlet/Login'>" + + "<Select name=poems><Option>limerick<Option>haiku</select>" + + "<Select name=songs size=2><Option>aria<Option>folk</select>" + + "<Input type=submit></form>" ); + + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + + WebForm form = page.getForms()[0]; + assertEquals( "Default poem", "limerick", form.getParameterValue( "poems" ) ); + assertNull( "Default song should be null", form.getParameterValue( "songs" ) ); + } + + public void testMultiSelect() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Select multiple size=4 name=colors>" + |
From: Russell G. <rus...@us...> - 2002-05-14 18:38:57
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv13154/doc Modified Files: release_notes.txt Log Message: Allowed sized selects to have no selected value Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.104 retrieving revision 1.105 diff -u -r1.104 -r1.105 --- release_notes.txt 9 May 2002 20:02:46 -0000 1.104 +++ release_notes.txt 14 May 2002 18:38:54 -0000 1.105 @@ -11,7 +11,12 @@ Revision History: - 9-Apr-2002 +14-May-2002 +Problems fixed: + 1. A <select> control with a size attribute may now have its value undefined. The specification does not require + this behavior, but both IE 5.5 and Netscape 6.2 do this. + + 9-May-2002 Acknowledgements: Thanks to Yassen Damyanov for fixing a bug in the handling response headers |
From: Russell G. <rus...@us...> - 2002-05-14 18:38:57
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv13154/src/com/meterware/httpunit Modified Files: FormControl.java Log Message: Allowed sized selects to have no selected value Index: FormControl.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- FormControl.java 8 Apr 2002 18:40:23 -0000 1.10 +++ FormControl.java 14 May 2002 18:38:54 -0000 1.11 @@ -656,6 +656,7 @@ class SelectionFormControl extends FormControl { private final boolean _multiSelect; + private final boolean _listBox; private final String[] _optionValues; private final String[] _displayedOptions; @@ -669,6 +670,7 @@ if (!node.getNodeName().equalsIgnoreCase( "select" )) throw new RuntimeException( "Not a select element" ); _multiSelect = NodeUtils.isNodeAttributePresent( node, "multiple" ); + _listBox = _multiSelect || NodeUtils.isNodeAttributePresent( node, "size" ); _optionValues = getInitialOptionValues( node ); _displayedOptions = getInitialDisplayedOptions( node ); @@ -724,7 +726,7 @@ } } - if (!_multiSelect) { + if (!_listBox) { if (numMatches == 0) throw new IllegalParameterValueException( getName(), (String) values.get(0), getOptionValues() ); } @@ -765,7 +767,7 @@ } } - if (!isMultiValued() && noneSelected && isSelected.length > 0) { + if (!_listBox && noneSelected && isSelected.length > 0) { isSelected[0] = true; } return isSelected; |
From: Russell G. <rus...@us...> - 2002-05-09 20:02:49
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv8798/src/com/meterware/httpunit Modified Files: HttpWebResponse.java Log Message: from Yassen Damyanov: fixed response header handling Index: HttpWebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- HttpWebResponse.java 6 Mar 2002 04:59:52 -0000 1.21 +++ HttpWebResponse.java 9 May 2002 20:02:46 -0000 1.22 @@ -129,11 +129,20 @@ _responseMessage = "OK"; } else try { _responseCode = Integer.parseInt( st.nextToken() ); - _responseMessage = st.hasMoreTokens() ? st.nextToken() : ""; + _responseMessage = getRemainingTokens( st ); } catch (NumberFormatException e) { _responseCode = HttpURLConnection.HTTP_INTERNAL_ERROR; _responseMessage = "Cannot parse response header"; } + } + + + private String getRemainingTokens( StringTokenizer st ) { + StringBuffer messageBuffer = new StringBuffer( st.hasMoreTokens() ? st.nextToken() : "" ); + while (st.hasMoreTokens()) { + messageBuffer.append( ' ' ).append( st.nextToken() ); + } + return messageBuffer.toString(); } |
From: Russell G. <rus...@us...> - 2002-05-09 20:02:49
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv8798/doc Modified Files: release_notes.txt Log Message: from Yassen Damyanov: fixed response header handling Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.103 retrieving revision 1.104 diff -u -r1.103 -r1.104 --- release_notes.txt 8 Apr 2002 18:40:22 -0000 1.103 +++ release_notes.txt 9 May 2002 20:02:46 -0000 1.104 @@ -11,6 +11,14 @@ Revision History: + 9-Apr-2002 +Acknowledgements: + Thanks to Yassen Damyanov for fixing a bug in the handling response headers + +Problems fixed: + 1. Response headers were truncated to the first word only + 2. The servletunit tutorial failed with a NullPointerException in the first step. + 8-Apr-2002 Additions: 1. It is now possible to set the value of a hidden field in a form using a mechanism which will support scripting in the future: |
From: Russell G. <rus...@us...> - 2002-05-08 20:08:11
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv15716/src/com/meterware/servletunit Modified Files: ServletRunner.java WebApplication.java Log Message: Remove superfluous setting of context directory Index: ServletRunner.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletRunner.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- ServletRunner.java 1 Mar 2002 06:08:24 -0000 1.13 +++ ServletRunner.java 8 May 2002 19:20:59 -0000 1.14 @@ -60,10 +60,12 @@ * * @param webXMLFileSpec the full path to the web.xml file */ - public ServletRunner( String webXMLFileSpec) throws IOException, SAXException { - this(webXMLFileSpec, null); + public ServletRunner( String webXMLFileSpec ) throws IOException, SAXException { + _context = new ServletUnitContext(); + _application = new WebApplication( HttpUnitUtils.newParser().parse( webXMLFileSpec ) ); } + /** * Constructor which expects the full path to the web.xml for the * application and a context path under which to mount it. @@ -72,10 +74,11 @@ * @param contextPath the context path */ public ServletRunner( String webXMLFileSpec, String contextPath ) throws IOException, SAXException { - _context = new ServletUnitContext(contextPath); - File webXMLFile = new File(webXMLFileSpec); - _application = new WebApplication(HttpUnitUtils.newParser().parse( webXMLFileSpec ), webXMLFile.getParentFile().getParentFile(), _context.getContextPath()); + _context = new ServletUnitContext( contextPath ); + File webXMLFile = new File( webXMLFileSpec ); + _application = new WebApplication( HttpUnitUtils.newParser().parse( webXMLFileSpec ), webXMLFile.getParentFile().getParentFile(), _context.getContextPath() ); } + /** * Constructor which expects an input stream containing the web.xml for the application. Index: WebApplication.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/WebApplication.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- WebApplication.java 1 Mar 2002 06:08:24 -0000 1.5 +++ WebApplication.java 8 May 2002 19:20:59 -0000 1.6 @@ -24,11 +24,8 @@ import java.io.File; import java.io.IOException; -import java.io.PrintWriter; - -import java.net.URL; import java.net.MalformedURLException; - +import java.net.URL; import java.util.ArrayList; import java.util.Dictionary; import java.util.HashMap; @@ -50,14 +47,13 @@ /** - * This class represents the information recorded about a single web + * This class represents the information recorded about a single web * application. It is usually extracted from web.xml. * * @author <a href="mailto:rus...@ac...">Russell Gold</a> **/ class WebApplication { - /** * Constructs a default application spec with no information. */ @@ -65,42 +61,44 @@ _contextPath = ""; } - /** - * Constructs an application spec from an XML document. - */ - WebApplication(Document document) throws MalformedURLException,SAXException { - this(document, null, ""); - } /** * Constructs an application spec from an XML document. */ - WebApplication(Document document, String contextPath) throws MalformedURLException,SAXException { - this(document, null, contextPath); + WebApplication( Document document ) throws MalformedURLException, SAXException { + this( document, null, "" ); } + /** * Constructs an application spec from an XML document. */ - WebApplication(Document document, File file) throws MalformedURLException,SAXException { - this(document, null, ""); + WebApplication( Document document, String contextPath ) throws MalformedURLException, SAXException { + this( document, null, contextPath ); } + /** * Constructs an application spec from an XML document. */ - WebApplication(Document document, File file, String contextPath) throws MalformedURLException,SAXException { + WebApplication( Document document, File file, String contextPath ) throws MalformedURLException, SAXException { _contextDir = file; _contextPath = contextPath; registerServlets( document ); + extractSecurityConstraints( document ); + extractContextParameters( document ); + extractLoginConfiguration( document ); + } + + + private void extractSecurityConstraints( Document document ) throws SAXException { NodeList nl = document.getElementsByTagName( "security-constraint" ); for (int i = 0; i < nl.getLength(); i++) { - _securityConstraints.add( new SecurityConstraintImpl( (Element) nl.item(i) ) ); + _securityConstraints.add( new SecurityConstraintImpl( (Element) nl.item( i ) ) ); } - extractContextParameters( document ); - extractLoginConfiguration( document ); } + /** * Registers a servlet class to be run. **/ @@ -114,10 +112,10 @@ **/ void registerServlet( String resourceName, ServletConfiguration servletConfiguration ) { // FIXME - shouldn't everything start with one or the other? - if (!resourceName.startsWith("/") && !resourceName.startsWith("*")) { - resourceName = "/"+resourceName; + if (!resourceName.startsWith( "/" ) && !resourceName.startsWith( "*" )) { + resourceName = "/" + resourceName; } - _servletMapping.put( resourceName, servletConfiguration); + _servletMapping.put( resourceName, servletConfiguration ); } @@ -142,8 +140,8 @@ } - private ServletConfiguration getServletConfiguration(URL url) { - if (!url.getFile().startsWith(_contextPath)) { + private ServletConfiguration getServletConfiguration( URL url ) { + if (!url.getFile().startsWith( _contextPath )) { return null; } String servletName = getServletName( getURLPath( url ) ); @@ -157,10 +155,10 @@ private String getURLPath( URL url ) { String file = url.getFile(); - if (_contextPath.equals("")) { + if (_contextPath.equals( "" )) { return file; - } else if (file.startsWith(_contextPath)) { - return file.substring(_contextPath.length()); + } else if (file.startsWith( _contextPath )) { + return file.substring( _contextPath.length() ); } else { return null; } @@ -252,11 +250,10 @@ final static private SecurityConstraint NULL_SECURITY_CONSTRAINT = new NullSecurityConstraint(); - - private void extractLoginConfiguration( Document document ) throws MalformedURLException,SAXException { + private void extractLoginConfiguration( Document document ) throws MalformedURLException, SAXException { NodeList nl = document.getElementsByTagName( "login-config" ); if (nl.getLength() == 1) { - final Element loginConfigElement = (Element) nl.item(0); + final Element loginConfigElement = (Element) nl.item( 0 ); String authenticationMethod = getChildNodeValue( loginConfigElement, "auth-method", "BASIC" ); _authenticationRealm = getChildNodeValue( loginConfigElement, "realm-name", "" ); if (authenticationMethod.equalsIgnoreCase( "BASIC" )) { @@ -275,9 +272,9 @@ private void registerServlets( Document document ) throws SAXException { Hashtable nameToClass = new Hashtable(); NodeList nl = document.getElementsByTagName( "servlet" ); - for (int i = 0; i < nl.getLength(); i++) registerServletClass( nameToClass, (Element) nl.item(i) ); + for (int i = 0; i < nl.getLength(); i++) registerServletClass( nameToClass, (Element) nl.item( i ) ); nl = document.getElementsByTagName( "servlet-mapping" ); - for (int i = 0; i < nl.getLength(); i++) registerServlet( nameToClass, (Element) nl.item(i) ); + for (int i = 0; i < nl.getLength(); i++) registerServlet( nameToClass, (Element) nl.item( i ) ); } @@ -294,13 +291,13 @@ private void extractContextParameters( Document document ) throws SAXException { - NodeList nl = document.getElementsByTagName( "context-param" ); - for (int i = 0; i < nl.getLength(); i++) { - Element param = (Element)nl.item(i); - String name = getChildNodeValue(param, "param-name"); - String value = getChildNodeValue(param, "param-value"); - _contextParameters.put(name, value); - } + NodeList nl = document.getElementsByTagName( "context-param" ); + for (int i = 0; i < nl.getLength(); i++) { + Element param = (Element) nl.item( i ); + String name = getChildNodeValue( param, "param-name" ); + String value = getChildNodeValue( param, "param-value" ); + _contextParameters.put( name, value ); + } } @@ -312,7 +309,7 @@ private static String getChildNodeValue( Element root, String childNodeName, String defaultValue ) throws SAXException { NodeList nl = root.getElementsByTagName( childNodeName ); if (nl.getLength() == 1) { - return getTextValue( nl.item(0) ); + return getTextValue( nl.item( 0 ) ); } else if (defaultValue == null) { throw new SAXException( "Node <" + root.getNodeName() + "> has no child named <" + childNodeName + ">" ); } else { @@ -355,6 +352,7 @@ //============================================= SecurityCheckServlet class ============================================= static class SecurityCheckServlet extends HttpServlet { + protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException { handleLogin( (ServletUnitHttpRequest) req, resp ); } @@ -386,9 +384,9 @@ ServletConfiguration( Element servletElement ) throws SAXException { this( getChildNodeValue( servletElement, "servlet-class" ) ); final NodeList initParams = servletElement.getElementsByTagName( "init-param" ); - for (int i = initParams.getLength()-1; i >= 0; i--) { - _initParams.put( getChildNodeValue( (Element) initParams.item(i), "param-name" ), - getChildNodeValue( (Element) initParams.item(i), "param-value" ) ); + for (int i = initParams.getLength() - 1; i >= 0; i--) { + _initParams.put( getChildNodeValue( (Element) initParams.item( i ), "param-name" ), + getChildNodeValue( (Element) initParams.item( i ), "param-value" ) ); } } @@ -403,7 +401,7 @@ } - private String _className; + private String _className; private Hashtable _initParams = new Hashtable(); } @@ -412,37 +410,52 @@ interface SecurityConstraint { + boolean controlsPath( String urlPath ); + + boolean hasRole( String roleName ); } static class NullSecurityConstraint implements SecurityConstraint { - public boolean controlsPath( String urlPath ) { return false; } - public boolean hasRole( String roleName ) { return true; } + + public boolean controlsPath( String urlPath ) { + return false; + } + + + public boolean hasRole( String roleName ) { + return true; + } } static class SecurityConstraintImpl implements SecurityConstraint { + SecurityConstraintImpl( Element root ) throws SAXException { final NodeList roleNames = root.getElementsByTagName( "role-name" ); - for (int i = 0; i < roleNames.getLength(); i++) _roles.add( getTextValue( (Element) roleNames.item(i) ) ); + for (int i = 0; i < roleNames.getLength(); i++) _roles.add( getTextValue( (Element) roleNames.item( i ) ) ); final NodeList resources = root.getElementsByTagName( "web-resource-collection" ); - for (int i = 0; i < resources.getLength(); i++) _resources.add( new WebResourceCollection( (Element) resources.item(i) ) ); + for (int i = 0; i < resources.getLength(); i++) _resources.add( new WebResourceCollection( (Element) resources.item( i ) ) ); } + public boolean controlsPath( String urlPath ) { return getMatchingCollection( urlPath ) != null; } + public boolean hasRole( String roleName ) { return _roles.contains( roleName ); } - private ArrayList _roles = new ArrayList(); + + private ArrayList _roles = new ArrayList(); private ArrayList _resources = new ArrayList(); + public WebResourceCollection getMatchingCollection( String urlPath ) { for (Iterator i = _resources.iterator(); i.hasNext();) { WebResourceCollection wrc = (WebResourceCollection) i.next(); @@ -451,12 +464,15 @@ return null; } + class WebResourceCollection { + WebResourceCollection( Element root ) throws SAXException { final NodeList urlPatterns = root.getElementsByTagName( "url-pattern" ); - for (int i = 0; i < urlPatterns.getLength(); i++) _urlPatterns.add( getTextValue( (Element) urlPatterns.item(i) ) ); + for (int i = 0; i < urlPatterns.getLength(); i++) _urlPatterns.add( getTextValue( (Element) urlPatterns.item( i ) ) ); } + boolean controlsPath( String urlPath ) { for (Iterator i = _urlPatterns.iterator(); i.hasNext();) { String pattern = (String) i.next(); @@ -465,10 +481,12 @@ return false; } - private ArrayList _urlPatterns = new ArrayList(); + + private ArrayList _urlPatterns = new ArrayList(); } } + /** * A utility class for mapping servlets to url patterns. This implements the * matching algorithm documented in section 10 of the JSDK-2.2 reference. @@ -477,66 +495,69 @@ * @version $Revision$ */ class ServletMapping { - + private final Map exactMatches = new HashMap(); private final Map extensions = new HashMap(); private final Map urlTree = new HashMap(); - - void put(String mapping, ServletConfiguration servletConfiguration) { - if (mapping.indexOf('*') == -1) { - exactMatches.put(mapping, servletConfiguration); - } else if (mapping.startsWith("*.")) { - extensions.put(mapping.substring(2), servletConfiguration); + + + void put( String mapping, ServletConfiguration servletConfiguration ) { + if (mapping.indexOf( '*' ) == -1) { + exactMatches.put( mapping, servletConfiguration ); + } else if (mapping.startsWith( "*." )) { + extensions.put( mapping.substring( 2 ), servletConfiguration ); } else { - ParsedPath path = new ParsedPath(mapping); + ParsedPath path = new ParsedPath( mapping ); Map context = urlTree; while (path.hasNext()) { String part = path.next(); - if (part.equals("*")) { - context.put("*", servletConfiguration); + if (part.equals( "*" )) { + context.put( "*", servletConfiguration ); return; } - if (!context.containsKey(part)) { - context.put(part, new HashMap()); + if (!context.containsKey( part )) { + context.put( part, new HashMap() ); } - context = (Map)context.get(part); + context = (Map) context.get( part ); } - context.put("/", servletConfiguration); + context.put( "/", servletConfiguration ); } } - - ServletConfiguration get(String url) { - if (exactMatches.containsKey(url)) { - return (ServletConfiguration)exactMatches.get(url); + + + ServletConfiguration get( String url ) { + if (exactMatches.containsKey( url )) { + return (ServletConfiguration) exactMatches.get( url ); } - ParsedPath path = new ParsedPath(url); + ParsedPath path = new ParsedPath( url ); Map context = urlTree; while (path.hasNext()) { String part = path.next(); - if (!context.containsKey(part)) { - if (context.containsKey("*")) { - return (ServletConfiguration)context.get("*"); + if (!context.containsKey( part )) { + if (context.containsKey( "*" )) { + return (ServletConfiguration) context.get( "*" ); } else { - int index = url.lastIndexOf('.'); - if (index == -1 || index == url.length()-1) { + int index = url.lastIndexOf( '.' ); + if (index == -1 || index == url.length() - 1) { return null; } else { - return (ServletConfiguration)extensions.get(url.substring(index+1)); + return (ServletConfiguration) extensions.get( url.substring( index + 1 ) ); } } } - context = (Map)context.get(part); + context = (Map) context.get( part ); } - if (context.containsKey("*")) { - return (ServletConfiguration)context.get("*"); + if (context.containsKey( "*" )) { + return (ServletConfiguration) context.get( "*" ); } - return (ServletConfiguration)context.get("/"); + return (ServletConfiguration) context.get( "/" ); } - + } } + /** * A utility class for parsing URLs into paths * @@ -548,18 +569,20 @@ private int position = 0; static final char seperator_char = '/'; + /** * Creates a new parsed path for the given path value * * @param path the path */ - ParsedPath(String path) { - if (path.charAt(0) != seperator_char) { - throw new IllegalArgumentException("Illegal path '"+path+"', does not begin with "+seperator_char); + ParsedPath( String path ) { + if (path.charAt( 0 ) != seperator_char) { + throw new IllegalArgumentException( "Illegal path '" + path + "', does not begin with " + seperator_char ); } this.path = path; } + /** * Returns true if there are more parts left, otherwise false */ @@ -567,15 +590,16 @@ return (position < path.length()); } + /** * Returns the next part in the path */ public final String next() { - int offset = position+1; - while (offset < path.length() && path.charAt(offset) != seperator_char) { + int offset = position + 1; + while (offset < path.length() && path.charAt( offset ) != seperator_char) { offset++; } - String result = path.substring(position+1, offset); + String result = path.substring( position + 1, offset ); position = offset; return result; } |
From: Russell G. <rus...@us...> - 2002-04-08 18:40:30
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv5794/src/com/meterware/httpunit Modified Files: FormControl.java WebForm.java Added Files: ScriptableObject.java Log Message: Added hidden field scriptability ***** Error reading new file[Errno 2] No such file or directory: 'ScriptableObject.java' Index: FormControl.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- FormControl.java 15 Mar 2002 17:23:25 -0000 1.9 +++ FormControl.java 8 Apr 2002 18:40:23 -0000 1.10 @@ -77,6 +77,14 @@ /** + * Returns a scriptable object which can act as a proxy for this control. + */ + public ScriptableObject getScriptableObject() { + return new Scriptable(); + } + + + /** * Returns the values permitted in this control. Does not apply to text or file controls. **/ public String[] getOptionValues() { @@ -231,6 +239,19 @@ } } + + class Scriptable implements ScriptableObject { + + public Object get( String propertyName ) { + throw new RuntimeException( "Unknown property: " + propertyName ); + } + + + public void set( String propertyName, Object value ) { + throw new RuntimeException( "Unknown property: " + propertyName ); + } + } + } @@ -495,6 +516,11 @@ } + public ScriptableObject getScriptableObject() { + return new Scriptable(); + } + + void addValues( ParameterProcessor processor, String characterSet ) throws IOException { if (getName().length() > 0) processor.addParameter( getName(), getValues()[0], characterSet ); } @@ -523,6 +549,17 @@ protected void claimValueIsRequired( List values ) { claimValueIsRequired( values, _defaultValue[0] ); + } + + class Scriptable extends FormControl.Scriptable { + + public void set( String propertyName, Object value ) { + if (propertyName.equalsIgnoreCase( "value" )) { + _value[0] =_defaultValue[0] = value.toString(); + } else { + super.set( propertyName, value ); + } + } } } Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.48 retrieving revision 1.49 diff -u -r1.48 -r1.49 --- WebForm.java 14 Mar 2002 22:18:26 -0000 1.48 +++ WebForm.java 8 Apr 2002 18:40:23 -0000 1.49 @@ -276,8 +276,8 @@ /** * Returns an object which provides scripting access to this form. **/ - public ScriptableObject getScriptableObject() { - return new ScriptableObject(); + public Scriptable getScriptableObject() { + return new Scriptable(); } //---------------------------------- WebRequestSource methods -------------------------------- @@ -400,9 +400,17 @@ } - public class ScriptableObject { + public class Scriptable implements ScriptableObject { public String getAction() { return WebForm.this.getAction(); } public void setAction( String newAction ) { _action = newAction; } + + public void setParameterValue( String name, String value ) { + getParameter( name ).getScriptableObject().set( "value", value ); + } + + + public void set( String propertyName, Object value ) {} + public Object get( String propertyName ) { return null; } } @@ -442,6 +450,11 @@ private String _action; + private Object getObject( String name ) { + return getParameter( name ).getScriptableObject(); + } + + private SubmitButton getDefaultButton() { if (getSubmitButtons().length == 1) { return getSubmitButtons()[0]; @@ -562,6 +575,11 @@ private FormControl[] getControls() { if (_controls == null) _controls = (FormControl[]) _controlList.toArray( new FormControl[ _controlList.size() ] ); return _controls; + } + + + ScriptableObject getScriptableObject() { + return getControls()[0].getScriptableObject(); } |
From: Russell G. <rus...@us...> - 2002-04-08 18:40:28
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv5794/test/com/meterware/httpunit Modified Files: FormParametersTest.java Log Message: Added hidden field scriptability Index: FormParametersTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormParametersTest.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- FormParametersTest.java 15 Mar 2002 17:23:25 -0000 1.11 +++ FormParametersTest.java 8 Apr 2002 18:40:23 -0000 1.12 @@ -133,6 +133,21 @@ validateSetParameterRejected( request, "secret", new String[] { "red", "pink" }, "setting hidden field to multiple values" ); } + + public void testHiddenParameters() throws Exception { + defineWebPage( "Default", "<form method=GET action = '/ask'>" + + "<Input type=hidden name=secret value=value>" + + "<Input type=submit></form>" ); + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + WebRequest request = page.getForms()[0].getRequest(); + HttpUnitOptions.setParameterValuesValidated( true ); + validateSetParameterRejected( request, "secret", new String[] { "red" }, "setting hidden field to wrong value" ); + + WebForm form = page.getForms()[0]; + form.getScriptableObject().setParameterValue( "secret", "new" ); + assertEquals( "New hidden value", "new", form.getParameterValue( "secret" ) ); + } + public void testMultipleTextParameterValidation() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=color>" + |
From: Russell G. <rus...@us...> - 2002-04-08 18:40:27
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv5794/doc Modified Files: release_notes.txt Log Message: Added hidden field scriptability Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.102 retrieving revision 1.103 diff -u -r1.102 -r1.103 --- release_notes.txt 25 Mar 2002 05:07:28 -0000 1.102 +++ release_notes.txt 8 Apr 2002 18:40:22 -0000 1.103 @@ -11,6 +11,11 @@ Revision History: + 8-Apr-2002 +Additions: + 1. It is now possible to set the value of a hidden field in a form using a mechanism which will support scripting in the future: + form.getScriptableObject().setParameterValue( fieldName, newValue ) + 25-Mar-2002 Problems fixed: 1. Parameters were not being submitted for image buttons with no specified value |
From: Russell G. <rus...@us...> - 2002-03-25 05:07:31
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv8353/src/com/meterware/httpunit Modified Files: SubmitButton.java Log Message: Send position of image button even with no value specified Index: SubmitButton.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/SubmitButton.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- SubmitButton.java 14 Jan 2002 18:13:45 -0000 1.8 +++ SubmitButton.java 25 Mar 2002 05:07:29 -0000 1.9 @@ -4,12 +4,12 @@ * * Copyright (c) 2000-2002, Russell Gold * -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -* documentation files (the "Software"), to deal in the Software without restriction, including without limitation +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +* documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * -* The above copyright notice and this permission notice shall be included in all copies or substantial portions +* The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO @@ -67,8 +67,10 @@ void addValues( ParameterProcessor processor, String characterSet ) throws IOException { - if (_pressed && !isDisabled() && getName().length() > 0 && getValueAttribute().length() > 0) { - processor.addParameter( getName(), getValueAttribute(), characterSet ); + if (_pressed && !isDisabled() && getName().length() > 0) { + if (getValueAttribute().length() > 0) { + processor.addParameter( getName(), getValueAttribute(), characterSet ); + } if (_isImageButton) { processor.addParameter( getName() + ".x", Integer.toString( _x ), characterSet ); processor.addParameter( getName() + ".y", Integer.toString( _y ), characterSet ); |
From: Russell G. <rus...@us...> - 2002-03-25 05:07:31
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv8353/doc Modified Files: release_notes.txt Log Message: Send position of image button even with no value specified Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.101 retrieving revision 1.102 diff -u -r1.101 -r1.102 --- release_notes.txt 21 Mar 2002 15:44:03 -0000 1.101 +++ release_notes.txt 25 Mar 2002 05:07:28 -0000 1.102 @@ -11,6 +11,10 @@ Revision History: +25-Mar-2002 +Problems fixed: + 1. Parameters were not being submitted for image buttons with no specified value + 21-Mar-2002 Acknowledgements: Thanks to Frank Carver for extending base 64 encoding to handle character values > 127. |
From: Russell G. <rus...@us...> - 2002-03-25 05:07:31
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv8353/test/com/meterware/httpunit Modified Files: FormSubmitTest.java Log Message: Send position of image button even with no value specified Index: FormSubmitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormSubmitTest.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- FormSubmitTest.java 14 Mar 2002 22:18:26 -0000 1.16 +++ FormSubmitTest.java 25 Mar 2002 05:07:29 -0000 1.17 @@ -28,6 +28,7 @@ import java.util.Enumeration; import java.util.StringTokenizer; import java.util.Vector; +import java.io.ByteArrayOutputStream; /** @@ -206,6 +207,19 @@ WebForm form = page.getForms()[0]; WebRequest request = form.getRequest(); assertEquals( "Query", getHostPath() + "/ask?age=12&update=name&update.x=0&update.y=0", request.getURL().toExternalForm() ); + } + + + public void testImageButtonNoValue() throws Exception { + defineWebPage( "Default", "<form name='login' method='get' action='ask'>" + + "<input type='text' name='email' value='bread'>" + + "<input type='image' name='login' src='../../se/images/buttons/login.gif'" + + " Alt='OK' border='0'>" + + "</form>" ); + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + WebForm form = page.getForms()[0]; + WebRequest request = form.getRequest(); + assertEquals( "Query", getHostPath() + "/ask?email=bread&login.x=0&login.y=0", request.getURL().toExternalForm() ); } |