httpunit-commit Mailing List for httpunit (Page 36)
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...> - 2003-02-20 20:51:25
|
Update of /cvsroot/httpunit/httpunit/doc/manual In directory sc8-pr-cvs1:/tmp/cvs-serv21599/doc/manual Modified Files: manual.css toc.html Added Files: retrieving.html Log Message: Initial documentation of retrieving a URL --- NEW FILE --- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>HttpUnit Manual - Retrieving Web Pages</title> <LINK REL="stylesheet" HREF="manual.css" TYPE="text/css"> </head> <body> <h1>Retrieving Web Pages</h1> <h2>Explicit Specification of a Page URL</h2> <p>The very first step in any interaction with a web site is to obtain a start page. To do this, we create a <a href="../api/com/meterware/httpunit/WebConversation.html"><span class="code">WebConversation</span></a> object to play the role of the web browser. This object will store browser state such a cookies, windows, and so on. We then ask for the page by specifying the desired URL:</p> <pre class="code-example"> WebConversation wc = <b>new</b> WebConversation(); WebResponse wr = wc.getResponse( "http://www.meterware.com" ); System.out.println( wr.getText() ); </pre> This example will simply print out the text of the retrieved page. Obviously, given this text, it is easy to search for particular strings on the page, if that is desired. Index: manual.css =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/manual/manual.css,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- manual.css 26 Nov 2002 13:00:57 -0000 1.1 +++ manual.css 20 Feb 2003 20:51:19 -0000 1.2 @@ -4,3 +4,14 @@ H2 { padding-left: .5em; padding-top: .5em; padding-bottom: .5 em; margin-bottom: 1em; background-color: #e3e3e3; border-color: #000000; border-width: 2; border-style: solid } + +SPAN.code { font-family: courier, monospaced, sans-serif } + +PRE { font-family: "courier new", courier; font-size: 8pt; + margin-left: 2%; margin-right: 2%; + padding-top: .5em; padding-bottom: .5em; padding-right: .5em; padding-left: .5em; + border-color: black; border-width: 2; border-style: solid } + +PRE.code-examples { background-color: #cccccc } + + Index: toc.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/manual/toc.html,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- toc.html 4 Dec 2002 02:51:05 -0000 1.1 +++ toc.html 20 Feb 2003 20:51:19 -0000 1.2 @@ -11,7 +11,7 @@ <h3>1. Getting Started</h3> <a href="introduction.html">Introduction</a><br> <a href="installing.html">Installing HttpUnit</a><br> -<a href="retrieving.html">Retrieving a page from a URL</a><br> +<a href="retrieving.html">Retrieving Web Pages</a><br> <br><a href="section2.html" class="toc-section">Working with Links and Forms</a><br> <br><a href="section3.html" class="toc-section">Deciphering Tables</a><br> <br><a href="section4.html" class="toc-section">Handling Frame structure</a><br> |
|
From: Russell G. <rus...@us...> - 2003-02-19 19:18:32
|
Update of /cvsroot/httpunit/httpunit/doc
In directory sc8-pr-cvs1:/tmp/cvs-serv2393/doc
Modified Files:
release_notes.txt
Log Message:
Share ServletContext, autoload servlets as required
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.256
retrieving revision 1.257
diff -u -r1.256 -r1.257
--- release_notes.txt 17 Feb 2003 23:54:39 -0000 1.256
+++ release_notes.txt 19 Feb 2003 19:17:56 -0000 1.257
@@ -48,6 +48,8 @@
12. Included and forwarded servlets now inherit parameters from their calling servlet.
13. Included servlets now have access to their path information as attributes, as per the spec.
14. Forwarded servlets now have access to their path information from the standard request methods, as required.
+ 15. All servlets within a web application now share the same instance of ServletContext, permitting attributes
+ set by one servlet to be visible to other servlets.
Additions:
Content and Parsing
@@ -75,6 +77,7 @@
14. InvocationContext now supports include and forwarded servlets: calling pushIncludeRequest or pushForwardRequest
updates the servlet, request, and response properties of the context so that subsequent calls can be done from
the dispatched servlet. Calling popRequest reverts to the dispatching servlet.
+ 15. ServletUnit now loads and initializes servlets specified with the <load-on-startup> element.
Notes:
1. Upgraded NekoHTML to 0.7.2 which no longer generates superfluous <form> tags.
|
|
From: Russell G. <rus...@us...> - 2003-02-19 19:18:07
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit
In directory sc8-pr-cvs1:/tmp/cvs-serv2393/test/com/meterware/servletunit
Modified Files:
ConfigTest.java JUnitServletTest.java WebXMLString.java
WebXMLTest.java
Log Message:
Share ServletContext, autoload servlets as required
Index: ConfigTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/ConfigTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ConfigTest.java 20 May 2002 16:00:44 -0000 1.3
+++ ConfigTest.java 19 Feb 2003 19:17:59 -0000 1.4
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2001,2003, 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
@@ -27,6 +27,7 @@
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
+import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -65,6 +66,24 @@
assertNotNull( "No response received", response );
assertEquals( "content type", "text/plain", response.getContentType() );
assertEquals( "servlet name is " + ConfigServlet.class.getName(), response.getText() );
+ }
+
+
+ public void testContextAttributes() throws Exception {
+ final String servlet1Name = "something/interesting";
+ final String servlet2Name = "something/else";
+
+ ServletRunner sr = new ServletRunner();
+ sr.registerServlet( servlet1Name, ConfigServlet.class.getName() );
+ sr.registerServlet( servlet2Name, ConfigServlet.class.getName() );
+ ServletUnitClient wc = sr.newClient();
+ InvocationContext ic1 = wc.newInvocation( "http://localhost/" + servlet1Name );
+ ServletContext sc1 = ic1.getServlet().getServletConfig().getServletContext();
+ sc1.setAttribute( "sample", "found me" );
+
+ InvocationContext ic2 = wc.newInvocation( "http://localhost/" + servlet2Name );
+ ServletContext sc2 = ic2.getServlet().getServletConfig().getServletContext();
+ assertEquals( "attribute 'sample'", "found me", sc2.getAttribute( "sample") );
}
Index: JUnitServletTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/JUnitServletTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JUnitServletTest.java 17 Oct 2002 23:50:51 -0000 1.4
+++ JUnitServletTest.java 19 Feb 2003 19:18:00 -0000 1.5
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2001-2002, Russell Gold
+ * Copyright (c) 2001-2003, 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
@@ -129,7 +129,7 @@
Properties params = new Properties();
params.setProperty( "color", "red" );
params.setProperty( "age", "12" );
- wxs.addServlet( "/SimpleServlet", SimpleGetServlet.class, params );
+ wxs.addServlet( "simple", "/SimpleServlet", SimpleGetServlet.class, params );
wxs.addServlet( "/JUnit", TestRunnerServlet.class );
MyFactory._runner = _runner = new ServletRunner( wxs.asInputStream() );
Index: WebXMLString.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/WebXMLString.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WebXMLString.java 30 Jan 2002 21:21:11 -0000 1.2
+++ WebXMLString.java 19 Feb 2003 19:18:00 -0000 1.3
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2001, Russell Gold
+ * Copyright (c) 2001-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -31,10 +31,20 @@
/**
* A class which allows dynamic creation of Servlet configuration XML
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
class WebXMLString {
+ private ArrayList _servlets = new ArrayList();
+ private ArrayList _mappings = new ArrayList();
+ private ArrayList _servletNames = new ArrayList();
+
+ private String _loginConfig = "";
+ private Hashtable _resources = new Hashtable();
+ private Hashtable _initParams = new Hashtable();
+ private Hashtable _contextParams = new Hashtable();
+ private Hashtable _loadOnStartup = new Hashtable();
+
ByteArrayInputStream asInputStream() throws UnsupportedEncodingException {
return new ByteArrayInputStream( asText().getBytes( "UTF-8" ) );
}
@@ -49,13 +59,15 @@
result.append( "</param-name>\n <param-value>" ).append( entry.getValue() ).append( "</param-value>\n </context-param>\n" );
}
for (int i = _servlets.size() - 1; i >= 0; i--) {
- result.append( " <servlet>\n <servlet-name>servlet_" ).append( i ).append( "</servlet-name>\n" );
+ Object name = _servletNames.get( i );
+ result.append( " <servlet>\n <servlet-name>" ).append( name ).append( "</servlet-name>\n" );
result.append( " <servlet-class>" ).append( ((Class) _servlets.get( i )).getName() ).append( "</servlet-class>\n" );
- appendParams( result, "init-param", (Hashtable) _initParams.get( new Integer( i ) ) );
+ appendParams( result, "init-param", (Hashtable) _initParams.get( name ) );
+ appendLoadOnStartup( result, _loadOnStartup.get( name ) );
result.append( " </servlet>\n" );
}
for (int i = _mappings.size() - 1; i >= 0; i--) {
- result.append( " <servlet-mapping>\n <servlet-name>servlet_" ).append( i ).append( "</servlet-name>\n" );
+ result.append( " <servlet-mapping>\n <servlet-name>" ).append( _servletNames.get( i ) ).append( "</servlet-name>\n" );
result.append( " <url-pattern>" ).append( _mappings.get( i ) ).append( "</url-pattern>\n </servlet-mapping>\n" );
}
for (Enumeration e = _resources.elements(); e.hasMoreElements();) {
@@ -67,6 +79,14 @@
}
+ private void appendLoadOnStartup( StringBuffer result, Object startupOrder ) {
+ if (startupOrder == null) return;
+ result.append( " <load-on-startup" );
+ if (startupOrder instanceof Number) result.append( ">" ).append( startupOrder ).append( "</load-on-startup>\n" );
+ else result.append( "/>\n" );
+ }
+
+
private void appendParams( StringBuffer result, String tagName, Hashtable params ) {
if (params == null) return;
for (Iterator it = params.entrySet().iterator(); it.hasNext();) {
@@ -84,14 +104,30 @@
void addServlet( String urlPattern, Class servletClass ) {
+ addServlet( "servlet_" + _servlets.size(), urlPattern, servletClass );
+ }
+
+
+ void addServlet( String name, String urlPattern, Class servletClass ) {
_servlets.add( servletClass );
_mappings.add( urlPattern );
+ _servletNames.add( name );
}
- void addServlet( String urlPattern, Class servletClass, Properties initParams ) {
- _initParams.put( new Integer( _servlets.size() ), initParams );
- addServlet( urlPattern, servletClass );
+ void addServlet( String name, String urlPattern, Class servletClass, Properties initParams ) {
+ _initParams.put( name, initParams );
+ addServlet( name, urlPattern, servletClass );
+ }
+
+
+ void setLoadOnStartup( String servletName ) {
+ _loadOnStartup.put( servletName, Boolean.TRUE );
+ }
+
+
+ void setLoadOnStartup( String servletName, int i ) {
+ _loadOnStartup.put( servletName, new Integer(i) );
}
@@ -131,14 +167,6 @@
void addAuthorizedRole( String resourceName, String roleName ) {
getWebResource( resourceName ).addAuthorizedRole( roleName );
}
-
-
- private ArrayList _servlets = new ArrayList();
- private ArrayList _mappings = new ArrayList();
- private String _loginConfig = "";
- private Hashtable _resources = new Hashtable();
- private Hashtable _initParams = new Hashtable();
- private Hashtable _contextParams = new Hashtable();
private WebResourceSpec getWebResource( String resourceName ) {
Index: WebXMLTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/WebXMLTest.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- WebXMLTest.java 13 Feb 2003 20:25:56 -0000 1.14
+++ WebXMLTest.java 19 Feb 2003 19:18:00 -0000 1.15
@@ -31,6 +31,7 @@
import java.util.Arrays;
import javax.servlet.ServletException;
+import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -117,12 +118,13 @@
Properties params = new Properties();
params.setProperty( "color", "red" );
params.setProperty( "age", "12" );
- wxs.addServlet( "/SimpleServlet", SimpleGetServlet.class, params );
+ wxs.addServlet( "simple", "/SimpleServlet", SimpleGetServlet.class, params );
ServletRunner sr = new ServletRunner( toInputStream( wxs.asText() ) );
ServletUnitClient client = sr.newClient();
InvocationContext ic = client.newInvocation( "http://localhost/SimpleServlet" );
- assertNull( "init parameter 'gender' should be null", ic.getServlet().getServletConfig().getInitParameter( "gender" ) );
+ ServletConfig servletConfig = ic.getServlet().getServletConfig();
+ assertNull( "init parameter 'gender' should be null", servletConfig.getInitParameter( "gender" ) );
assertEquals( "init parameter via config", "red", ic.getServlet().getServletConfig().getInitParameter( "color" ) );
assertEquals( "init parameter directly", "12", ((HttpServlet) ic.getServlet()).getInitParameter( "age" ) );
}
@@ -288,6 +290,44 @@
}
+ /**
+ * Verifies that only those servlets designated will pre-load when the application is initialized.
+ * SimpleGetServlet and each of its subclasses adds its classname to the 'initialized' context attribute.
+ */
+ public void testLoadOnStartup() throws Exception {
+ WebXMLString wxs = new WebXMLString();
+ wxs.addServlet( "servlet1", "one", Servlet1.class );
+ wxs.setLoadOnStartup( "servlet1" );
+ wxs.addServlet( "servlet2", "two", Servlet2.class );
+ wxs.addServlet( "servlet3", "three", Servlet3.class );
+
+ ServletRunner sr = new ServletRunner( toInputStream( wxs.asText() ) );
+ ServletUnitClient wc = sr.newClient();
+ InvocationContext ic = wc.newInvocation( "http://localhost/three" );
+ assertEquals( "Initialized servlets", "Servlet1,Servlet3", ic.getServlet().getServletConfig().getServletContext().getAttribute( "initialized" ) );
+ }
+
+
+ /**
+ * Verifies that servlets pre-load in the order specified.
+ * SimpleGetServlet and each of its subclasses adds its classname to the 'initialized' context attribute.
+ */
+ public void testLoadOrder() throws Exception {
+ WebXMLString wxs = new WebXMLString();
+ wxs.addServlet( "servlet1", "one", Servlet1.class );
+ wxs.setLoadOnStartup( "servlet1", 2 );
+ wxs.addServlet( "servlet2", "two", Servlet2.class );
+ wxs.setLoadOnStartup( "servlet2", 3 );
+ wxs.addServlet( "servlet3", "three", Servlet3.class );
+ wxs.setLoadOnStartup( "servlet3", 1 );
+
+ ServletRunner sr = new ServletRunner( toInputStream( wxs.asText() ) );
+ ServletUnitClient wc = sr.newClient();
+ InvocationContext ic = wc.newInvocation( "http://localhost/two" );
+ assertEquals( "Initialized servlets", "Servlet3,Servlet1,Servlet2", ic.getServlet().getServletConfig().getServletContext().getAttribute( "initialized" ) );
+ }
+
+
//===============================================================================================================
@@ -329,6 +369,21 @@
static class SimpleGetServlet extends HttpServlet {
static String RESPONSE_TEXT = "the desired content\r\n";
+
+ public void init() throws ServletException {
+ ServletConfig servletConfig = getServletConfig();
+ String initialized = (String) servletConfig.getServletContext().getAttribute( "initialized" );
+ if (initialized == null) initialized = getLocalName();
+ else initialized = initialized + "," + getLocalName();
+ servletConfig.getServletContext().setAttribute( "initialized", initialized );
+ }
+
+ private String getLocalName() {
+ String className = getClass().getName();
+ int dollarIndex = className.indexOf( '$' );
+ if (dollarIndex < 0) return className;
+ return className.substring( dollarIndex+1 );
+ }
protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException {
resp.setContentType( "text/html" );
|
|
From: Russell G. <rus...@us...> - 2003-02-19 19:18:05
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit
In directory sc8-pr-cvs1:/tmp/cvs-serv2393/src/com/meterware/servletunit
Modified Files:
ServletUnitServletConfig.java WebApplication.java
Log Message:
Share ServletContext, autoload servlets as required
Index: ServletUnitServletConfig.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitServletConfig.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ServletUnitServletConfig.java 19 Jun 2002 13:47:19 -0000 1.6
+++ ServletUnitServletConfig.java 19 Feb 2003 19:17:57 -0000 1.7
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2002, Russell Gold
+* Copyright (c) 2000-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -19,7 +19,6 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
-import java.io.File;
import java.util.Enumeration;
import java.util.Hashtable;
@@ -37,7 +36,7 @@
ServletUnitServletConfig( Servlet servlet, WebApplication application, Hashtable initParams ) {
_name = servlet.getClass().getName();
_initParameters = initParams;
- _context = new ServletUnitServletContext( application );
+ _context = application.getServletContext();
}
Index: WebApplication.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/WebApplication.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- WebApplication.java 13 Feb 2003 20:25:56 -0000 1.17
+++ WebApplication.java 19 Feb 2003 19:17:58 -0000 1.18
@@ -30,6 +30,7 @@
import javax.servlet.Servlet;
import javax.servlet.ServletException;
+import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -50,6 +51,35 @@
**/
class WebApplication {
+ private final static SecurityConstraint NULL_SECURITY_CONSTRAINT = new NullSecurityConstraint();
+
+ private final ServletConfiguration SECURITY_CHECK_CONFIGURATION = new ServletConfiguration( SecurityCheckServlet.class.getName() );
+
+ private final ServletMapping SECURITY_CHECK_MAPPING = new ServletMapping( SECURITY_CHECK_CONFIGURATION );
+
+ /** A mapping of resource names to servlet class names. **/
+ private ServletMap _servletMapping = new ServletMap();
+
+ private ArrayList _securityConstraints = new ArrayList();
+
+ private boolean _useBasicAuthentication;
+
+ private boolean _useFormAuthentication;
+
+ private String _authenticationRealm = "";
+
+ private URL _loginURL;
+
+ private URL _errorURL;
+
+ private Hashtable _contextParameters = new Hashtable();
+
+ private File _contextDir = null;
+
+ private String _contextPath = null;
+
+ private ServletUnitServletContext _servletContext;
+
/**
* Constructs a default application spec with no information.
@@ -85,6 +115,7 @@
extractSecurityConstraints( document );
extractContextParameters( document );
extractLoginConfiguration( document );
+ _servletMapping.autoLoadServlets();
}
@@ -101,6 +132,14 @@
}
+ ServletContext getServletContext() {
+ if (_servletContext == null) {
+ _servletContext = new ServletUnitServletContext( this );
+ }
+ return _servletContext;
+ }
+
+
/**
* Registers a servlet class to be run.
**/
@@ -226,34 +265,6 @@
//------------------------------------------------ private members ---------------------------------------------
- private final static SecurityConstraint NULL_SECURITY_CONSTRAINT = new NullSecurityConstraint();
-
- private final ServletConfiguration SECURITY_CHECK_CONFIGURATION = new ServletConfiguration( SecurityCheckServlet.class.getName() );
-
- private final ServletMapping SECURITY_CHECK_MAPPING = new ServletMapping( SECURITY_CHECK_CONFIGURATION );
-
- /** A mapping of resource names to servlet class names. **/
- private ServletMap _servletMapping = new ServletMap();
-
- private ArrayList _securityConstraints = new ArrayList();
-
- private boolean _useBasicAuthentication;
-
- private boolean _useFormAuthentication;
-
- private String _authenticationRealm = "";
-
- private URL _loginURL;
-
- private URL _errorURL;
-
- private Hashtable _contextParameters = new Hashtable();
-
- private File _contextDir = null;
-
- private String _contextPath = null;
-
-
private void extractLoginConfiguration( Document document ) throws MalformedURLException, SAXException {
NodeList nl = document.getElementsByTagName( "login-config" );
if (nl.getLength() == 1) {
@@ -360,9 +371,16 @@
}
//============================================= ServletConfiguration class =============================================
+ final static int DONT_AUTOLOAD = Integer.MIN_VALUE;
+ final static int ANY_LOAD_ORDER = Integer.MAX_VALUE;
class ServletConfiguration {
+ private Servlet _servlet;
+ private String _className;
+ private Hashtable _initParams = new Hashtable();
+ private int _loadOrder = DONT_AUTOLOAD;
+
ServletConfiguration( String className ) {
_className = className;
}
@@ -381,6 +399,15 @@
_initParams.put( getChildNodeValue( (Element) initParams.item( i ), "param-name" ),
getChildNodeValue( (Element) initParams.item( i ), "param-value" ) );
}
+ final NodeList loadOrder = servletElement.getElementsByTagName( "load-on-startup" );
+ for (int i = 0; i < loadOrder.getLength(); i++) {
+ String order = getTextValue( loadOrder.item(i) );
+ try {
+ _loadOrder = Integer.parseInt( order );
+ } catch (NumberFormatException e) {
+ _loadOrder = ANY_LOAD_ORDER;
+ }
+ }
}
@@ -410,9 +437,14 @@
}
- private Servlet _servlet;
- private String _className;
- private Hashtable _initParams = new Hashtable();
+ boolean isLoadOnStartup() {
+ return _loadOrder != DONT_AUTOLOAD;
+ }
+
+
+ public int getLoadOrder() {
+ return _loadOrder;
+ }
}
@@ -674,10 +706,55 @@
}
- private void destroyServlets( Map exactMatches ) {
- for (Iterator iterator = exactMatches.values().iterator(); iterator.hasNext();) {
- ServletMapping servletMapping = (ServletMapping) iterator.next();
- servletMapping.destroyServlet();
+ private void destroyServlets( Map map ) {
+ for (Iterator iterator = map.values().iterator(); iterator.hasNext();) {
+ Object o = iterator.next();
+ if (o instanceof ServletMapping) {
+ ServletMapping servletMapping = (ServletMapping) o;
+ servletMapping.destroyServlet();
+ } else {
+ destroyServlets( (Map) o );
+ }
+ }
+ }
+
+
+ void autoLoadServlets() {
+ ArrayList autoLoadable = new ArrayList();
+ if (_defaultMapping != null && _defaultMapping.getConfiguration().isLoadOnStartup()) autoLoadable.add( _defaultMapping.getConfiguration() );
+ collectAutoLoadableServlets( autoLoadable, _exactMatches );
+ collectAutoLoadableServlets( autoLoadable, _extensions );
+ collectAutoLoadableServlets( autoLoadable, _urlTree );
+ if (autoLoadable.isEmpty()) return;
+
+ Collections.sort( autoLoadable, new Comparator() {
+ public int compare( Object o1, Object o2 ) {
+ ServletConfiguration sc1 = (ServletConfiguration) o1;
+ ServletConfiguration sc2 = (ServletConfiguration) o2;
+ return (sc1.getLoadOrder() <= sc2.getLoadOrder()) ? -1 : +1;
+ }
+ });
+ for (Iterator iterator = autoLoadable.iterator(); iterator.hasNext();) {
+ ServletConfiguration servletConfiguration = (ServletConfiguration) iterator.next();
+ try {
+ servletConfiguration.getServlet();
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException( "Unable to autoload servlet: " + servletConfiguration.getClassName() + ": " + e );
+ }
+ }
+ }
+
+
+ private void collectAutoLoadableServlets( Collection collection, Map map ) {
+ for (Iterator iterator = map.values().iterator(); iterator.hasNext();) {
+ Object o = iterator.next();
+ if (o instanceof ServletMapping) {
+ ServletMapping servletMapping = (ServletMapping) o;
+ if (servletMapping.getConfiguration().isLoadOnStartup()) collection.add( servletMapping.getConfiguration() );
+ } else {
+ collectAutoLoadableServlets( collection, (Map) o );
+ }
}
}
|
|
From: Russell G. <rus...@us...> - 2003-02-17 23:55:16
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv28955/src/com/meterware/httpunit
Modified Files:
Button.java FormControl.java ResetButton.java
SubmitButton.java WebForm.java
Log Message:
#680695: Support form control ids and Button.click()
Index: Button.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/Button.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Button.java 26 Dec 2002 18:55:18 -0000 1.4
+++ Button.java 17 Feb 2003 23:54:40 -0000 1.5
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2002, Russell Gold
+ * Copyright (c) 2002-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -19,6 +19,8 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
+import com.meterware.httpunit.scripting.ScriptableDelegate;
+
import java.io.IOException;
import org.w3c.dom.Node;
@@ -27,7 +29,7 @@
/**
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
public class Button extends FormControl {
@@ -54,11 +56,11 @@
/**
- * Performs the action associated with clicking this button. For a submit button this typically
- * submits the form.
+ * Performs the action associated with clicking this button after running any 'onClick' script.
+ * For a submit button this typically submits the form.
*/
- public void click() throws IOException, SAXException {
- doOnClickEvent();
+ public void click() throws IOException, SAXException {
+ if (doOnClickEvent()) doButtonAction();
}
@@ -68,6 +70,12 @@
}
+ /**
+ * Perform the normal action of this button.
+ */
+ protected void doButtonAction() throws IOException, SAXException {}
+
+
//-------------------------------------------------- FormControl methods -----------------------------------------------
@@ -79,4 +87,16 @@
void addValues( ParameterProcessor processor, String characterSet ) throws IOException {
}
+
+ protected ScriptableDelegate newScriptable() {
+ return new Scriptable();
+ }
+
+
+ class Scriptable extends FormControl.Scriptable {
+
+ public void click() throws IOException, SAXException {
+ doButtonAction();
+ }
+ }
}
Index: FormControl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- FormControl.java 6 Feb 2003 02:55:58 -0000 1.35
+++ FormControl.java 17 Feb 2003 23:54:40 -0000 1.36
@@ -25,6 +25,7 @@
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
import java.util.Hashtable;
import java.util.ArrayList;
@@ -315,6 +316,11 @@
}
+ public Scriptable() {
+ super( FormControl.this );
+ }
+
+
public Object get( String propertyName ) {
if (propertyName.equalsIgnoreCase( "name" )) {
return FormControl.this.getName();
@@ -333,8 +339,7 @@
}
- public Scriptable() {
- super( FormControl.this );
+ public void click() throws IOException, SAXException {
}
}
Index: ResetButton.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ResetButton.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ResetButton.java 26 Dec 2002 18:55:18 -0000 1.2
+++ ResetButton.java 17 Feb 2003 23:54:41 -0000 1.3
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2002, Russell Gold
+ * Copyright (c) 2002-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -19,10 +19,7 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
-import java.io.IOException;
-
import org.w3c.dom.Node;
-import org.xml.sax.SAXException;
/**
@@ -38,11 +35,7 @@
}
- /**
- * Performs the action associated with clicking this button. For a submit button this typically
- * submits the form.
- */
- public void click() throws IOException, SAXException {
- if (doOnClickEvent()) getForm().reset();
+ protected void doButtonAction() {
+ getForm().reset();
}
}
Index: SubmitButton.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/SubmitButton.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- SubmitButton.java 17 Feb 2003 03:17:05 -0000 1.14
+++ SubmitButton.java 17 Feb 2003 23:54:41 -0000 1.15
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2002, Russell Gold
+* Copyright (c) 2000-2003, 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
@@ -37,14 +37,13 @@
}
-//--------------------------------- FormButton methods ----------------------------------------------
+//--------------------------------- Button methods ----------------------------------------------
/**
- * Performs the action associated with clicking this button. For a submit button this typically
- * submits the form.
+ * Perform the normal action of this button.
*/
- public void click() throws IOException, SAXException {
+ protected void doButtonAction() throws IOException, SAXException {
getForm().submit( this );
}
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -r1.77 -r1.78
--- WebForm.java 17 Feb 2003 03:17:05 -0000 1.77
+++ WebForm.java 17 Feb 2003 23:54:41 -0000 1.78
@@ -56,14 +56,13 @@
/**
* Submits this form using the web client from which it was originally obtained.
- * Will usually return the result of that submission; however, if a scripted event is triggered which
- * inhibits the submission, will return the updated contents of the frame containing this form.
+ * Will usually return the result of that submission; however, if the 'onsubmit' event is triggered and
+ * inhibits the submission, will return the updated contents of the frame containing this form. Note that
+ * this will not run any event associated with the specified submit button. Use SubmitButton#click for that.
**/
public WebResponse submit( SubmitButton button ) throws IOException, SAXException {
- if (button.doOnClickEvent()) {
- String event = getAttribute( "onsubmit" );
- if (event.length() == 0 || getScriptableObject().doEvent( event )) return submitRequest( getRequest( button ) );
- }
+ String event = getAttribute( "onsubmit" );
+ if (event.length() == 0 || getScriptableObject().doEvent( event )) return submitRequest( getRequest( button ) );
return getBaseResponse().getWindow().getFrameContents( getTarget() );
}
@@ -546,7 +545,9 @@
return getTarget();
} else {
final FormParameter parameter = getParameter( propertyName );
- return parameter == UNKNOWN_PARAMETER ? super.get( propertyName ) : parameter.getScriptableObject();
+ if (parameter != UNKNOWN_PARAMETER) return parameter.getScriptableObject();
+ FormControl control = getControlWithID( propertyName );
+ return control == null ? super.get( propertyName ) : control.getScriptableDelegate();
}
}
@@ -599,6 +600,19 @@
WebForm( WebResponse response, URL baseURL, String frameName, Node node, String characterSet ) {
super( response, node, baseURL, NodeUtils.getNodeAttribute( node, "action" ), frameName );
_characterSet = characterSet;
+ }
+
+
+ /**
+ * Returns the form control which is part of this form with the specified ID.
+ */
+ FormControl getControlWithID( String id ) {
+ FormControl[] controls = getFormControls();
+ for (int i = 0; i < controls.length; i++) {
+ FormControl control = controls[i];
+ if (control.getID().equals(id)) return control;
+ }
+ return null;
}
|
|
From: Russell G. <rus...@us...> - 2003-02-17 23:55:16
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript
In directory sc8-pr-cvs1:/tmp/cvs-serv28955/src/com/meterware/httpunit/javascript
Modified Files:
JavaScript.java
Log Message:
#680695: Support form control ids and Button.click()
Index: JavaScript.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- JavaScript.java 5 Feb 2003 16:07:39 -0000 1.45
+++ JavaScript.java 17 Feb 2003 23:54:42 -0000 1.46
@@ -179,9 +179,9 @@
private void handleScriptException( Exception e, String badScript ) {
final String errorMessage = badScript + " failed: " + e;
if (!(e instanceof EcmaError) && !(e instanceof EvaluatorException)) {
- e.printStackTrace();
throw new RuntimeException( errorMessage );
} else if (isThrowExceptionsOnError()) {
+ e.printStackTrace();
throw new ScriptException( errorMessage );
} else {
_errorMessages.add( errorMessage );
@@ -941,7 +941,18 @@
public void jsFunction_focus() {}
+
public void jsFunction_select() {}
+
+
+ public void jsFunction_click() throws IOException, SAXException {
+ getDelegate().click();
+ }
+
+
+ private Input getDelegate() {
+ return (Input) _scriptable;
+ }
void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable )
|
|
From: Russell G. <rus...@us...> - 2003-02-17 23:55:16
|
Update of /cvsroot/httpunit/httpunit/doc
In directory sc8-pr-cvs1:/tmp/cvs-serv28955/doc
Modified Files:
release_notes.txt
Log Message:
#680695: Support form control ids and Button.click()
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.255
retrieving revision 1.256
diff -u -r1.255 -r1.256
--- release_notes.txt 17 Feb 2003 03:17:05 -0000 1.255
+++ release_notes.txt 17 Feb 2003 23:54:39 -0000 1.256
@@ -3,6 +3,8 @@
Known problems:
1. The "accept-charset" attribute for forms is ignored; the page content character set is used to encode any response.
This behavior matches that currently used by IE and Navigator.
+ 2. Defining a form parameter with the same name or ID as a JavaScript Form function will cause that function not to
+ be callable.
Limitations:
1. JDK 1.3.1 or higher is required
@@ -35,17 +37,17 @@
JavaScript
5. Scripts marked as something besides JavaScript are now ignored.
6. Opening a non-HTML window via Javascript no longer raises a NotHTMLException.
- 7. Bug #682518: Calling WebForm.submit( button ) now runs the onClick event of the submit button before trying to
- submit the form.
+ 7. Bug #680695: Button.click() is now supported.
+ 8. Bug #680695: Form control ids are now usable to locate components.
ServletUnit
- 8. ServletUnit now creates a new session if the requested session exists but is marked invalid
- 9. ServletUnit was interpreting the getRequestDispatcher path as an absolute path. It now correctly treats it
+ 9. ServletUnit now creates a new session if the requested session exists but is marked invalid
+ 10. ServletUnit was interpreting the getRequestDispatcher path as an absolute path. It now correctly treats it
as relative to the context root.
- 10. Calling HttpServletRequest.setAttribute in ServletUnit no longer throws an IllegalStateException if the value
+ 11. Calling HttpServletRequest.setAttribute in ServletUnit no longer throws an IllegalStateException if the value
had previously been defined.
- 11. Included and forwarded servlets now inherit parameters from their calling servlet.
- 12. Included servlets now have access to their path information as attributes, as per the spec.
- 13. Forwarded servlets now have access to their path information from the standard request methods, as required.
+ 12. Included and forwarded servlets now inherit parameters from their calling servlet.
+ 13. Included servlets now have access to their path information as attributes, as per the spec.
+ 14. Forwarded servlets now have access to their path information from the standard request methods, as required.
Additions:
Content and Parsing
|
|
From: Russell G. <rus...@us...> - 2003-02-17 23:55:16
|
Update of /cvsroot/httpunit/httpunit/jars
In directory sc8-pr-cvs1:/tmp/cvs-serv28955/jars
Modified Files:
jars.txt js.jar rhino-patch.txt
Log Message:
#680695: Support form control ids and Button.click()
Index: jars.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/jars/jars.txt,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- jars.txt 13 Jan 2003 21:57:34 -0000 1.9
+++ jars.txt 17 Feb 2003 23:54:40 -0000 1.10
@@ -5,7 +5,7 @@
servlet 2.3
xerces 2.2
jtidy 04aug2000r7
-rhino 1.5preR4 (patched)
+rhino 1.5R4+ (patched)
NekoHTML 0.7.2
(for testing HttpUnit only)
Index: js.jar
===================================================================
RCS file: /cvsroot/httpunit/httpunit/jars/js.jar,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
Binary files /tmp/cvsChtcMX and /tmp/cvsO85UhQ differ
Index: rhino-patch.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/jars/rhino-patch.txt,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- rhino-patch.txt 22 Dec 2002 14:06:51 -0000 1.1
+++ rhino-patch.txt 17 Feb 2003 23:54:40 -0000 1.2
@@ -1,13 +1,24 @@
Index: js/rhino/src/org/mozilla/javascript/Interpreter.java
===================================================================
RCS file: /cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/Interpreter.java,v
-retrieving revision 1.113
-diff -r1.113 Interpreter.java
-2029a2030,2036
-> else if (lhs == undefined) {
-> // special code for better error message for get property from undefined
->
-> int i = getShort(iCode, pc-6);
-> if (i != -1) lhs=strings[i];
-> throw NativeGlobal.typeError1( "msg.is.not.defined", ScriptRuntime.toString(lhs),scope );
-> }
+retrieving revision 1.130
+diff -u -r1.130 Interpreter.java
+--- js/rhino/src/org/mozilla/javascript/Interpreter.java 17 Feb 2003 08:50:55 -0000 1.130
++++ js/rhino/src/org/mozilla/javascript/Interpreter.java 17 Feb 2003 15:43:53 -0000
+@@ -2032,6 +2032,16 @@
+ --stackTop;
+ Object lhs = stack[stackTop];
+ if (lhs == DBL_MRK) lhs = doubleWrap(sDbl[stackTop]);
++ else if (lhs == undefined) {
++ // special code for better error message for get property from undefined
++ int j = pc-6;
++ while (j > 0 && iCode[j] != 0) j--;
++ int i = getShort(iCode, j);
++ if (i >= 0 && i < strings.length) {
++ lhs=strings[i];
++ throw NativeGlobal.typeError1( "msg.is.not.defined", ScriptRuntime.toString(lhs),scope );
++ }
++ }
+ stack[stackTop] = ScriptRuntime.getProp(lhs, name, scope);
+ break;
+ }
\ No newline at end of file
|
|
From: Russell G. <rus...@us...> - 2003-02-17 23:54:47
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript
In directory sc8-pr-cvs1:/tmp/cvs-serv28955/test/com/meterware/httpunit/javascript
Modified Files:
FormScriptingTest.java
Log Message:
#680695: Support form control ids and Button.click()
Index: FormScriptingTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- FormScriptingTest.java 17 Feb 2003 03:17:05 -0000 1.17
+++ FormScriptingTest.java 17 Feb 2003 23:54:42 -0000 1.18
@@ -203,7 +203,7 @@
"<body>" +
"<form name=spectrum action='DoIt' onsubmit='return false;'>" +
" <input type=text name=color value=green>" +
- " <input type=button id=submit value=submit onClick='this.form.submit();'>" +
+ " <input type=button id=submitButton value=submit onClick='this.form.submit();'>" +
"</form>" +
"<a href='#' onClick='document.spectrum.submit(); return false;'>" +
"</body></html>" );
@@ -232,7 +232,7 @@
}
- public void testSubmitButtonScript() throws Exception {
+ public void donttestSubmitButtonScript() throws Exception { // XXX not sure this is the desired behavior
defineResource( "DoIt?color=green", "You made it!" );
defineResource( "OnCommand.html", "<html><head></head>" +
"<body>" +
@@ -713,6 +713,18 @@
WebConversation wc = new WebConversation();
WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" );
assertEquals( "Form parameter value", "new", response.getForms()[0].getParameterValue( "testfield") );
+ }
+
+
+ public void testSubmitFromJavaScriptLink() throws Exception {
+ defineResource( "test2.txt?Submit=Submit", "You made it!", "text/plain" );
+ defineWebPage( "OnCommand", "<form name='myform' action='test2.txt'>" +
+ " <input type='submit' id='btn' name='Submit' value='Submit'/>" +
+ " <a href='javascript:document.myform.btn.click();'>Link</a>" +
+ "</form>" );
+ WebConversation wc = new WebConversation();
+ WebResponse wr = wc.getResponse( getHostPath() + "/OnCommand.html" );
+ wr.getLinkWith( "Link" ).click();
}
|
|
From: Russell G. <rus...@us...> - 2003-02-17 23:54:47
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting
In directory sc8-pr-cvs1:/tmp/cvs-serv28955/src/com/meterware/httpunit/scripting
Modified Files:
Input.java
Log Message:
#680695: Support form control ids and Button.click()
Index: Input.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting/Input.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Input.java 13 Oct 2002 23:53:48 -0000 1.1
+++ Input.java 17 Feb 2003 23:54:42 -0000 1.2
@@ -1,4 +1,8 @@
package com.meterware.httpunit.scripting;
+import java.io.IOException;
+
+import org.xml.sax.SAXException;
+
/********************************************************************************************************************
* $Id$
*
@@ -33,5 +37,8 @@
void set( String propertyName, Object value );
+
+
+ void click() throws IOException, SAXException;
}
|
|
From: Russell G. <rus...@us...> - 2003-02-17 03:17:09
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript
In directory sc8-pr-cvs1:/tmp/cvs-serv17624/test/com/meterware/httpunit/javascript
Modified Files:
FormScriptingTest.java
Log Message:
#682518: now run onClick script when WebForm.submit(button) is called
Index: FormScriptingTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- FormScriptingTest.java 27 Dec 2002 05:09:38 -0000 1.16
+++ FormScriptingTest.java 17 Feb 2003 03:17:05 -0000 1.17
@@ -232,6 +232,23 @@
}
+ public void testSubmitButtonScript() throws Exception {
+ defineResource( "DoIt?color=green", "You made it!" );
+ defineResource( "OnCommand.html", "<html><head></head>" +
+ "<body>" +
+ "<form name=spectrum action='DoIt'>" +
+ " <input type=text name=color value=red>" +
+ " <input type=submit onClick='form.color.value=\"green\";'>" +
+ "</form>" +
+ "</body></html>" );
+ WebConversation wc = new WebConversation();
+ WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" );
+
+ response.getFormWithName( "spectrum" ).submit();
+ assertEquals( "Result of submit", "You made it!", wc.getCurrentPage().getText() );
+ }
+
+
public void testSetFormTextValue() throws Exception {
defineResource( "OnCommand.html", "<html><head></head>" +
"<body onLoad=\"document.realform.color.value='green'\">" +
|
|
From: Russell G. <rus...@us...> - 2003-02-17 03:17:09
|
Update of /cvsroot/httpunit/httpunit/doc
In directory sc8-pr-cvs1:/tmp/cvs-serv17624/doc
Modified Files:
release_notes.txt
Log Message:
#682518: now run onClick script when WebForm.submit(button) is called
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.254
retrieving revision 1.255
diff -u -r1.254 -r1.255
--- release_notes.txt 14 Feb 2003 19:04:24 -0000 1.254
+++ release_notes.txt 17 Feb 2003 03:17:05 -0000 1.255
@@ -35,15 +35,17 @@
JavaScript
5. Scripts marked as something besides JavaScript are now ignored.
6. Opening a non-HTML window via Javascript no longer raises a NotHTMLException.
+ 7. Bug #682518: Calling WebForm.submit( button ) now runs the onClick event of the submit button before trying to
+ submit the form.
ServletUnit
- 7. ServletUnit now creates a new session if the requested session exists but is marked invalid
- 8. ServletUnit was interpreting the getRequestDispatcher path as an absolute path. It now correctly treats it
+ 8. ServletUnit now creates a new session if the requested session exists but is marked invalid
+ 9. ServletUnit was interpreting the getRequestDispatcher path as an absolute path. It now correctly treats it
as relative to the context root.
- 9. Calling HttpServletRequest.setAttribute in ServletUnit no longer throws an IllegalStateException if the value
+ 10. Calling HttpServletRequest.setAttribute in ServletUnit no longer throws an IllegalStateException if the value
had previously been defined.
- 10. Included and forwarded servlets now inherit parameters from their calling servlet.
- 11. Included servlets now have access to their path information as attributes, as per the spec.
- 12. Forwarded servlets now have access to their path information from the standard request methods, as required.
+ 11. Included and forwarded servlets now inherit parameters from their calling servlet.
+ 12. Included servlets now have access to their path information as attributes, as per the spec.
+ 13. Forwarded servlets now have access to their path information from the standard request methods, as required.
Additions:
Content and Parsing
|
|
From: Russell G. <rus...@us...> - 2003-02-17 03:17:09
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv17624/src/com/meterware/httpunit
Modified Files:
SubmitButton.java WebForm.java
Log Message:
#682518: now run onClick script when WebForm.submit(button) is called
Index: SubmitButton.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/SubmitButton.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- SubmitButton.java 13 Oct 2002 23:53:48 -0000 1.13
+++ SubmitButton.java 17 Feb 2003 03:17:05 -0000 1.14
@@ -45,7 +45,7 @@
* submits the form.
*/
public void click() throws IOException, SAXException {
- if (doOnClickEvent()) getForm().submit( this );
+ getForm().submit( this );
}
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -r1.76 -r1.77
--- WebForm.java 6 Feb 2003 02:55:58 -0000 1.76
+++ WebForm.java 17 Feb 2003 03:17:05 -0000 1.77
@@ -60,8 +60,10 @@
* inhibits the submission, will return the updated contents of the frame containing this form.
**/
public WebResponse submit( SubmitButton button ) throws IOException, SAXException {
- String event = getAttribute( "onsubmit" );
- if (event.length() == 0 || getScriptableObject().doEvent( event )) return submitRequest( getRequest( button ) );
+ if (button.doOnClickEvent()) {
+ String event = getAttribute( "onsubmit" );
+ if (event.length() == 0 || getScriptableObject().doEvent( event )) return submitRequest( getRequest( button ) );
+ }
return getBaseResponse().getWindow().getFrameContents( getTarget() );
}
|
|
From: Russell G. <rus...@us...> - 2003-02-14 19:04:27
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv4945/src/com/meterware/httpunit
Modified Files:
MessageBody.java WebRequest.java WebResponse.java
WebTable.java
Log Message:
Prepare for 1.5.2 release
Index: MessageBody.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/MessageBody.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MessageBody.java 6 Jun 2001 13:25:33 -0000 1.3
+++ MessageBody.java 14 Feb 2003 19:04:24 -0000 1.4
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000, Russell Gold
+* Copyright (c) 2000-2001, 2003 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
@@ -22,9 +22,6 @@
import java.io.IOException;
import java.io.OutputStream;
-import java.net.URLConnection;
-
-
/**
* An abstract class representing the body of a web request.
**/
@@ -43,15 +40,6 @@
**/
abstract
String getContentType();
-
-
- /**
- * Updates the headers for this request as needed.
- * @deprecated use getContentType
- **/
- final
- void updateHeaders( URLConnection connection ) throws IOException {
- }
/**
Index: WebRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- WebRequest.java 4 Feb 2003 19:17:30 -0000 1.53
+++ WebRequest.java 14 Feb 2003 19:04:24 -0000 1.54
@@ -191,15 +191,6 @@
/**
- * Returns an enumeration of all parameters in this web request. May include some parameters that will not be sent.
- * @deprecated use getRequestParameterNames instead
- **/
- public Enumeration getParameterNames() {
- return new Vector( Arrays.asList( _parameterHolder.getParameterNames() ) ).elements();
- }
-
-
- /**
* Returns an array of all parameter names defined as part of this web request.
* @since 1.3.1
**/
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.108
retrieving revision 1.109
diff -u -r1.108 -r1.109
--- WebResponse.java 5 Feb 2003 16:07:39 -0000 1.108
+++ WebResponse.java 14 Feb 2003 19:04:24 -0000 1.109
@@ -120,15 +120,6 @@
/**
- * Returns the target of the page.
- * @deprecated use getFrameName
- **/
- public String getTarget() {
- return getFrameName();
- }
-
-
- /**
* Returns the name of the frame containing this page.
**/
public String getFrameName() {
@@ -511,23 +502,6 @@
//---------------------------------------- JavaScript methods ----------------------------------------
-
- /**
- * Returns the next javascript alert without removing it from the queue.
- * @deprecated use WebClient#getNextAlert. Will be removed in next release.
- */
- public String getNextAlert() {
- return _client.getNextAlert();
- }
-
-
- /**
- * Returns the next javascript alert and removes it from the queue.
- * @deprecated use WebClient#popNextAlert. Will be removed in next release.
- */
- public String popNextAlert() {
- return _client.popNextAlert();
- }
public Scriptable getScriptableObject() {
Index: WebTable.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebTable.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- WebTable.java 4 Feb 2003 05:32:03 -0000 1.25
+++ WebTable.java 14 Feb 2003 19:04:24 -0000 1.26
@@ -76,17 +76,6 @@
* Returns the contents of the specified table cell as text.
* The row and column numbers are zero-based.
* @throws IndexOutOfBoundsException if the specified cell numbers are not valid
- * @deprecated use #getCellAsText
- **/
- public String getCell( int row, int column ) {
- return getCellAsText( row, column );
- }
-
-
- /**
- * Returns the contents of the specified table cell as text.
- * The row and column numbers are zero-based.
- * @throws IndexOutOfBoundsException if the specified cell numbers are not valid
**/
public String getCellAsText( int row, int column ) {
TableCell cell = getTableCell( row, column );
|
|
From: Russell G. <rus...@us...> - 2003-02-14 19:04:27
|
Update of /cvsroot/httpunit/httpunit/doc
In directory sc8-pr-cvs1:/tmp/cvs-serv4945/doc
Modified Files:
release_notes.txt
Log Message:
Prepare for 1.5.2 release
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.253
retrieving revision 1.254
diff -u -r1.253 -r1.254
--- release_notes.txt 13 Feb 2003 20:25:54 -0000 1.253
+++ release_notes.txt 14 Feb 2003 19:04:24 -0000 1.254
@@ -11,117 +11,71 @@
Revision History:
- 13-Feb-2003
-Acknowledgements:
- Thanks to Ron Hanson for catching the obsolete behavior of HttpServletRequest.setAttribute.
- Thanks to Ron Hanson and also to Daniel Sheppard for help in adding capabilities to the RequestDispatcher implementation.
-
-Problems Fixed:
- 1. Calling HttpServletRequest.setAttribute in ServletUnit no longer throws an IllegalStateException if the value
- had previously been defined.
- 2. Included and forwarded servlets now inherit parameters from their calling servlet.
- 3. Included servlets now have access to their path information as attributes, as per the spec.
- 4. Forwarded servlets now have access to their path information from the standard request methods, as required.
-
-Additions:
- 1. InvocationContext now supports include and forwarded servlets: calling pushIncludeRequest or pushForwardRequest
- updates the servlet, request, and response properties of the context so that subsequent calls can be done from
- the dispatched servlet. Calling popRequest reverts to the dispatching servlet.
-
- 5-Feb-2003
+ 14-Feb-2003 1.5.2 release candidate
Acknowledgements:
+ Thanks to John Sinclair for noting the lack of line breaks in manifest.mf and proposing a fix
+ Thanks to Bernhard Wagner for simplifying some string comparison code in ParsedHTML and WebTable
+ Thanks to Bernhard Wagner for adding some parser customization code.
+ Thanks to James Howe for noting the mispelling of the getElementById method
+ Thanks to Alex Beggs for noting the mishandling of non-JavaScript scripts and providing a test case.
Thanks to Navid Vahdat for ServletUnit fixes for invalid session handling and request dispatcher paths
+ Thanks to Daniel Sheppard for identifying a problem with meta refresh tags.
Thanks to Daniel Sheppard for correcting the return status for HttpServletResponse.sendRedirect
-
-Additions:
- 1. ServletUnit now supports HttpServletResponse.flushBuffer()
- 2. WebForm.isHiddenParameter returns true if all parameters with the specified name are hidden
+ Thanks to Daniel Sheppard, Navid Vahdat, and Ron Hanson for help in adding capabilities to the RequestDispatcher implementation.
+ Thanks to Ron Hanson for catching the obsolete behavior of HttpServletRequest.setAttribute.
Problems Fixed:
- 1. Opening a non-HTML window via Javascript no longer raises a NotHTMLException.
- 2. ServletUnit now creates a new session if the requested session exists but is marked invalid
- 3. ServletUnit was interpreting the getRequestDispatcher path as an absolute path. It now correctly treats it
- as relative to the context root.
-
- 4-Feb-2003
-Acknowledgements:
- Thanks to Daniel Sheppard for identifying a problem with meta refresh tags.
-
-Additions:
- 1. Added support for <iframe> tag. IFrames work just like regular frames, except that they are embedded in a response
- without a <frameset> tag. IFrame support is controlled by the ClientProperties.iframeSupported property.
- 2. ServletUnit now handles https requests, marking them as "secure."
-
-Problems fixed:
- 1. Quotes in refresh URL meta tags are now recognized and stripped.
-
-13-Jan-2003
- Notes: upgraded NekoHTML to 0.7.2 which no longer generates superfluous <form> tags.
-
-10-Jan-2003
- Thanks to Alex Beggs for noting the mishandling of non-JavaScript scripts and providing a test case.
+ Packaging
+ 1. The manifest.mf file now has line breaks between properties
+ Content and Parsing
+ 2. get...WithID was incorrectly doing case insensitive matches. It is now case-sensitive, since that is the way
+ the ID attribute is defined.
+ 3. Forms prematurely closed because of improper nesting will now contain any controls defined before the next form.
+ 4. Quotes in refresh URL meta tags are now recognized and stripped.
+ JavaScript
+ 5. Scripts marked as something besides JavaScript are now ignored.
+ 6. Opening a non-HTML window via Javascript no longer raises a NotHTMLException.
+ ServletUnit
+ 7. ServletUnit now creates a new session if the requested session exists but is marked invalid
+ 8. ServletUnit was interpreting the getRequestDispatcher path as an absolute path. It now correctly treats it
+ as relative to the context root.
+ 9. Calling HttpServletRequest.setAttribute in ServletUnit no longer throws an IllegalStateException if the value
+ had previously been defined.
+ 10. Included and forwarded servlets now inherit parameters from their calling servlet.
+ 11. Included servlets now have access to their path information as attributes, as per the spec.
+ 12. Forwarded servlets now have access to their path information from the standard request methods, as required.
+
+Additions:
+ Content and Parsing
+ 1. You may call HTMLParserFactory.setPreserveTagCase and setReturnHTMLDocument to control whether the parser coerces
+ the case of tags and attributes or returns a HTMLDocument object, respectively.
+ 2. HTMLParserFactory now supports methods to explicitly select the parser without playing with the class path.
+ This includes support for additional parsers not bundled with HttpUnit.
+ 3. WebResponse and TableCell now support the getElementWithID method, which returns any supported HTMLElement,
+ given its ID. Supported HTMLElement objects include WebForm, WebLink, WebTable, WebImage, WebApplet,
+ FormControl, TableCell, and TableRow.
+ 4. Added getFragmentIdentifier() to WebRequestSource (parent of WebLink, WebForm, and WebImage)
+ 5. Added support for <iframe> tag. IFrames work just like regular frames, except that they are embedded in a response
+ without a <frameset> tag. IFrame support is controlled by the ClientProperties.iframeSupported property.
+ 6. WebForm.isHiddenParameter returns true if all parameters with the specified name are hidden
+ JavaScript
+ 7. The Form.target property is now supported
+ 8. Added support for document.getElementById
+ 9. All HTML elements with id attributes are now accessible
+ ServletUnit
+ 10. ServletRunner.shutDown() will invoke the destroy() methods of any servlets which have been invoked
+ through that servlet runner.
+ 11. ServletUnit now supports HttpServletRequest.getHeaderNames
+ 12. ServletUnit now handles https requests, marking them as "secure."
+ 13. ServletUnit now supports HttpServletResponse.flushBuffer()
+ 14. InvocationContext now supports include and forwarded servlets: calling pushIncludeRequest or pushForwardRequest
+ updates the servlet, request, and response properties of the context so that subsequent calls can be done from
+ the dispatched servlet. Calling popRequest reverts to the dispatching servlet.
-Problems fixed:
- 1. Scripts marked as something besides JavaScript are now ignored.
-
- 9-Jan-2003
- Acknowledgements:
- Thanks to James Howe for noting the mispelling of the getElementById method
-
-Problems fixed:
- 1. Corrected spelling of getElementById
-
- 3-Jan-2003
-Additions:
- 1. ServletRunner.shutDown() will invoke the destroy() methods of any servlets which have been invoked
- through that servlet runner.
- 2. ServletUnit now supports HttpServletRequest.getHeaderNames
-
-30-Dec-2002
-Additions:
- 1. Added support for document.getElementByID
- 2. all HTML elements with id attributes are now accessible
-
-27-Dec-2002
-Additions:
- 1. Added getFragmentIdentifier() to WebRequestSource (parent of WebLink, WebForm, and WebImage)
-
-26-Dec-2002
-Additions:
- 1. WebResponse and TableCell now support the getElementWithID method, which returns any supported HTMLElement, given its ID.
- Supported HTMLElement objects include WebForm, WebLink, WebTable, WebImage, WebApplet, FormControl, TableCell, and TableRow.
- 2. The Form.target property is now supported
-
-Problems fixed:
- 1. Forms prematurely closed because of improper nesting will now contain any controls defined before the next form.
- At present, this only works with the JTidy parser.
-
-25-Dec-2002
Notes:
- 1. get...WithID was incorrectly doing case insensitive matches. It is now case-sensitive, since that is the way the
- ID attribute is defined.
-
-24-Dec-2002
-Additions:
- 1. HTMLParserFactory now supports methods to explicitly select the parser without playing with the class path.
- This includes support for additional parsers not bundled with HttpUnit.
-
-22-Dec-2002
- Thanks to John Sinclair for noting the lack of line breaks in manifest.mf and proposing a fix
-
-Problems fixed:
- 1. The manifest.mf file now has line breaks between properties
+ 1. Upgraded NekoHTML to 0.7.2 which no longer generates superfluous <form> tags.
+ 2. Removed a number of deprecated methods
-19-Dec-2002
- Thanks to Bernhard Wagner for adding some parser customization code.
-
-Additions:
- 1. You may call HTMLParserFactory.setPreserveTagCase and setReturnHTMLDocument to control whether the parser coerces
- the case of tags and attributes or returns a HTMLDocument object, respectively.
-
-18-Dec-2001
-Acknowledgements:
- Thanks to Bernhard Wagner for simplifying some string comparison code in ParsedHTML and WebTable
18-Dec-2002 1.5.1
|
|
From: Russell G. <rus...@us...> - 2003-02-14 19:04:27
|
Update of /cvsroot/httpunit/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv4945
Modified Files:
build.xml
Log Message:
Prepare for 1.5.2 release
Index: build.xml
===================================================================
RCS file: /cvsroot/httpunit/httpunit/build.xml,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -r1.62 -r1.63
--- build.xml 24 Dec 2002 17:17:02 -0000 1.62
+++ build.xml 14 Feb 2003 19:04:23 -0000 1.63
@@ -5,7 +5,7 @@
<project name="httpunit" default="jar" basedir=".">
<property name="name" value="httpunit" />
<property name="Name" value="HttpUnit" />
- <property name="version" value="1.5.1" />
+ <property name="version" value="1.5.2" />
<property name="debug" value="on" />
<property name="deprecation" value="off" />
@@ -191,7 +191,7 @@
<javadoc packagenames="${packages}" sourcepath="${basedir}/${src.dir}"
destdir="${javadoc.dir}" author="true" version="true"
windowtitle="${Name} ${version} API" doctitle="${Name}"
- footer="Copyright &copy; 2000-2002 Russell Gold. See <a href="http://www.httpunit.org/doc/license.html">license agreement</A> for rights granted." >
+ footer="Copyright &copy; 2000-2003 Russell Gold. See <a href="http://www.httpunit.org/doc/license.html">license agreement</A> for rights granted." >
<classpath refid="base.classpath"/>
</javadoc>
</target>
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit
In directory sc8-pr-cvs1:/tmp/cvs-serv7442/test/com/meterware/servletunit
Modified Files:
HttpServletRequestTest.java NavigationTest.java
RequestContextTest.java RequestDispatcherTest.java
WebXMLTest.java
Log Message:
Implemented request property changes for RequestDispatcher calls
Index: HttpServletRequestTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/HttpServletRequestTest.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- HttpServletRequestTest.java 13 Feb 2003 15:37:01 -0000 1.13
+++ HttpServletRequestTest.java 13 Feb 2003 20:25:56 -0000 1.14
@@ -339,7 +339,7 @@
private final static byte[] NO_MESSAGE_BODY = new byte[0];
- private final static ServletRequest NULL_SERVLET_REQUEST = new ServletRequest() {
+ private final static ServletMetaData NULL_SERVLET_REQUEST = new ServletMetaData() {
public Servlet getServlet() throws ServletException {
return null;
Index: NavigationTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/NavigationTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- NavigationTest.java 6 Feb 2003 01:33:11 -0000 1.4
+++ NavigationTest.java 13 Feb 2003 20:25:56 -0000 1.5
@@ -55,9 +55,9 @@
sr.registerServlet( "origin", OriginServlet.class.getName() );
WebClient wc = sr.newClient();
- WebResponse response = wc.getResponse( "http://localhost/origin" );
+ WebResponse response = wc.getResponse( "http://localhost/origin?color=green" );
assertNotNull( "No response received", response );
- assertEquals( "requested resource", TargetServlet.RESPONSE_TEXT, response.getText() );
+ assertEquals( "Expected response", "color=null: path=/target", response.getText() );
assertEquals( "Returned cookie count", 0, response.getNewCookieNames().length );
}
@@ -70,14 +70,26 @@
ServletRunner sr = new ServletRunner( wxs.asInputStream(), "/context" );
WebClient wc = sr.newClient();
- WebResponse response = wc.getResponse( "http://localhost/context/origin" );
+ WebResponse response = wc.getResponse( "http://localhost/context/origin?color=green" );
assertNotNull( "No response received", response );
- assertEquals( "requested resource", TargetServlet.RESPONSE_TEXT, response.getText() );
+ assertEquals( "Expected response", "color=green: path=/context/target", response.getText() );
assertEquals( "Returned cookie count", 0, response.getNewCookieNames().length );
}
+ public void testInclude() throws Exception {
+ WebXMLString wxs = new WebXMLString();
+ wxs.addServlet( "/target", TargetServlet.class );
+ wxs.addServlet( "/origin", IncluderServlet.class );
+ ServletRunner sr = new ServletRunner( wxs.asInputStream(), "/context" );
+
+ WebClient wc = sr.newClient();
+ WebResponse response = wc.getResponse( "http://localhost/context/origin?color=green" );
+ assertNotNull( "No response received", response );
+ assertEquals( "Expected response", "expecting: color=blue: path=/context/origin", response.getText() );
+ assertEquals( "Returned cookie count", 0, response.getNewCookieNames().length );
+ }
static class OriginServlet extends HttpServlet {
@@ -103,20 +115,19 @@
static final String PREFIX = "expecting: ";
protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException,IOException {
- resp.getOutputStream().print( PREFIX );
- getServletContext().getRequestDispatcher( "/target" ).include( req, resp );
+ resp.getWriter().print( PREFIX );
+ getServletContext().getRequestDispatcher( "/target?color=blue" ).include( req, resp );
}
}
static class TargetServlet extends HttpServlet {
- static String RESPONSE_TEXT = "the desired content\r\n";
-
protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException,IOException {
resp.setContentType( "text/plain" );
PrintWriter pw = resp.getWriter();
- pw.print( RESPONSE_TEXT );
+ pw.print( "color=" + req.getParameter( "color" ) );
+ pw.print( ": path=" + req.getRequestURI() );
pw.close();
}
Index: RequestContextTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/RequestContextTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RequestContextTest.java 12 Feb 2003 13:47:23 -0000 1.1
+++ RequestContextTest.java 13 Feb 2003 20:25:56 -0000 1.2
@@ -22,6 +22,19 @@
import com.meterware.httpunit.HttpUnitTest;
import java.net.URL;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.Locale;
+import java.security.Principal;
+import java.io.UnsupportedEncodingException;
+import java.io.IOException;
+import java.io.BufferedReader;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpSession;
+import javax.servlet.ServletInputStream;
+import javax.servlet.RequestDispatcher;
import junit.framework.TestSuite;
@@ -63,12 +76,270 @@
* Verify parsing of a query string.
*/
public void testParameterOverride() throws Exception {
- RequestContext rc1 = new RequestContext( new URL( "http://localhost/basic?param=red¶m1=old¶m=blue" ) );
- RequestContext rc2 = new RequestContext( new URL( "http://localhost/second?param=yellow¶m2=fast" ));
- rc2.setParentContext( rc1 );
- assertMatchingSet( "parameter names", new String[] { "param", "param1", "param2" }, rc2.getParameterNames() );
- assertMatchingSet( "param values", new String[] { "yellow" }, rc2.getParameterValues( "param" ) );
- assertEquals( "param1 value", "old", ((String[]) rc2.getParameterMap().get( "param1"))[0] );
+ HttpServletRequest request = new DummyHttpServletRequest( new URL( "http://localhost/basic?param=red¶m1=old¶m=blue" ) );
+ RequestContext context = new RequestContext( new URL( "http://localhost/second?param=yellow¶m2=fast" ));
+ context.setParentRequest( request );
+ assertMatchingSet( "parameter names", new String[] { "param", "param1", "param2" }, context.getParameterNames() );
+ assertMatchingSet( "param values", new String[] { "yellow" }, context.getParameterValues( "param" ) );
+ assertEquals( "param1 value", "old", ((String[]) context.getParameterMap().get( "param1"))[0] );
+ }
+
+
+ class DummyHttpServletRequest implements HttpServletRequest {
+
+ private RequestContext _requestContext;
+
+
+ public DummyHttpServletRequest( URL requestURL ) {
+ _requestContext = new RequestContext( requestURL );
+ }
+
+
+ public String getAuthType() {
+ return null;
+ }
+
+
+ public Cookie[] getCookies() {
+ return new Cookie[0];
+ }
+
+
+ public long getDateHeader( String s ) {
+ return 0;
+ }
+
+
+ public String getHeader( String s ) {
+ return null;
+ }
+
+
+ public Enumeration getHeaders( String s ) {
+ return null;
+ }
+
+
+ public Enumeration getHeaderNames() {
+ return null;
+ }
+
+
+ public int getIntHeader( String s ) {
+ return 0;
+ }
+
+
+ public String getMethod() {
+ return null;
+ }
+
+
+ public String getPathInfo() {
+ return null;
+ }
+
+
+ public String getPathTranslated() {
+ return null;
+ }
+
+
+ public String getContextPath() {
+ return null;
+ }
+
+
+ public String getQueryString() {
+ return null;
+ }
+
+
+ public String getRemoteUser() {
+ return null;
+ }
+
+
+ public boolean isUserInRole( String s ) {
+ return false;
+ }
+
+
+ public Principal getUserPrincipal() {
+ return null;
+ }
+
+
+ public String getRequestedSessionId() {
+ return null;
+ }
+
+
+ public String getRequestURI() {
+ return null;
+ }
+
+
+ public StringBuffer getRequestURL() {
+ return null;
+ }
+
+
+ public String getServletPath() {
+ return null;
+ }
+
+
+ public HttpSession getSession( boolean b ) {
+ return null;
+ }
+
+
+ public HttpSession getSession() {
+ return null;
+ }
+
+
+ public boolean isRequestedSessionIdValid() {
+ return false;
+ }
+
+
+ public boolean isRequestedSessionIdFromCookie() {
+ return false;
+ }
+
+
+ public boolean isRequestedSessionIdFromURL() {
+ return false;
+ }
+
+
+ public boolean isRequestedSessionIdFromUrl() {
+ return false;
+ }
+
+
+ public Object getAttribute( String s ) {
+ return null;
+ }
+
+
+ public Enumeration getAttributeNames() {
+ return null;
+ }
+
+
+ public String getCharacterEncoding() {
+ return null;
+ }
+
+
+ public void setCharacterEncoding( String s ) throws UnsupportedEncodingException {
+ }
+
+
+ public int getContentLength() {
+ return 0;
+ }
+
+
+ public String getContentType() {
+ return null;
+ }
+
+
+ public ServletInputStream getInputStream() throws IOException {
+ return null;
+ }
+
+
+ public String getParameter( String s ) {
+ return _requestContext.getParameter( s );
+ }
+
+
+ public Enumeration getParameterNames() {
+ return _requestContext.getParameterNames();
+ }
+
+
+ public String[] getParameterValues( String s ) {
+ return _requestContext.getParameterValues( s );
+ }
+
+
+ public Map getParameterMap() {
+ return _requestContext.getParameterMap();
+ }
+
+
+ public String getProtocol() {
+ return null;
+ }
+
+
+ public String getScheme() {
+ return null;
+ }
+
+
+ public String getServerName() {
+ return null;
+ }
+
+
+ public int getServerPort() {
+ return 0;
+ }
+
+
+ public BufferedReader getReader() throws IOException {
+ return null;
+ }
+
+
+ public String getRemoteAddr() {
+ return null;
+ }
+
+
+ public String getRemoteHost() {
+ return null;
+ }
+
+
+ public void setAttribute( String s, Object o ) {
+ }
+
+
+ public void removeAttribute( String s ) {
+ }
+
+
+ public Locale getLocale() {
+ return null;
+ }
+
+
+ public Enumeration getLocales() {
+ return null;
+ }
+
+
+ public boolean isSecure() {
+ return false;
+ }
+
+
+ public RequestDispatcher getRequestDispatcher( String s ) {
+ return null;
+ }
+
+
+ public String getRealPath( String s ) {
+ return null;
+ }
}
Index: RequestDispatcherTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/RequestDispatcherTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RequestDispatcherTest.java 12 Feb 2003 13:47:24 -0000 1.1
+++ RequestDispatcherTest.java 13 Feb 2003 20:25:56 -0000 1.2
@@ -1,10 +1,28 @@
package com.meterware.servletunit;
-
+/********************************************************************************************************************
+* $Id$
+*
+* Copyright (c) 2003, Russell Gold
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
+* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in all copies or substantial portions
+* of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+* DEALINGS IN THE SOFTWARE.
+*
+*******************************************************************************************************************/
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
-import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -14,10 +32,6 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-import com.meterware.httpunit.GetMethodWebRequest;
-import com.meterware.httpunit.WebRequest;
-import com.meterware.httpunit.WebResponse;
-
public class RequestDispatcherTest extends TestCase {
@@ -61,6 +75,7 @@
InvocationContext ic = _runner.newClient().newInvocation( "http://localhost/sample/" + outerServletName + "?param=original¶m1=first" );
final HttpServletRequest request = ic.getRequest();
+ final HttpServletResponse response = ic.getResponse();
RequestDispatcherServlet servlet = (RequestDispatcherServlet) ic.getServlet();
RequestDispatcher rd = servlet.getServletContext().getRequestDispatcher( "/" + innerServletName + "?param=revised¶m2=new" );
@@ -68,21 +83,26 @@
assertEquals( "param1", "first", request.getParameter( "param1" ) );
assertNull( "param2 should not be defined", request.getParameter( "param2" ) );
- ic.pushIncludedContext( rd );
+ ic.pushIncludeRequest( rd, request, response );
+
+ final HttpServletRequest innerRequest = ic.getRequest();
+ assertEquals( "param in included servlet", "revised", innerRequest.getParameter( "param" ) );
+ assertEquals( "param1 in included servlet", "first", innerRequest.getParameter( "param1" ) );
+ assertEquals( "param2 in included servlet", "new", innerRequest.getParameter( "param2" ) );
- assertEquals( "param in included servlet", "revised", request.getParameter( "param" ) );
- assertEquals( "param1 in included servlet", "first", request.getParameter( "param1" ) );
- assertEquals( "param2 in included servlet", "new", request.getParameter( "param2" ) );
+ assertEquals( "Included servlet class", IncludedServlet.class, ic.getServlet().getClass() );
- ic.popContext();
+ ic.popRequest();
- assertEquals( "reverted param", "original", request.getParameter( "param" ) );
- assertEquals( "reverted param1", "first", request.getParameter( "param1" ) );
- assertNull( "reverted param2 should not be defined", request.getParameter( "param2" ) );
+ final HttpServletRequest restoredRequest = ic.getRequest();
+ assertEquals( "reverted param", "original", restoredRequest.getParameter( "param" ) );
+ assertEquals( "reverted param1", "first", restoredRequest.getParameter( "param1" ) );
+ assertNull( "reverted param2 should not be defined", restoredRequest.getParameter( "param2" ) );
+ assertEquals( "Included servlet class", RequestDispatcherServlet.class, ic.getServlet().getClass() );
}
- public void notestRequestDispatcherIncludePaths() throws Exception {
+ public void testRequestDispatcherIncludePaths() throws Exception {
InvocationContext ic = _runner.newClient().newInvocation( "http://localhost/sample/" + outerServletName + "?param=original¶m1=first" );
final HttpServletRequest request = ic.getRequest();
@@ -95,51 +115,67 @@
assertNull( "path info not null attribute", request.getPathInfo() );
// assertEquals( "query string attribute", "param=original¶m1=first", request.getQueryString() ); TODO make this work
- ic.pushIncludedContext( rd );
+ final HttpServletResponse response = ic.getResponse();
+ ic.pushIncludeRequest( rd, request, response );
+
+ final HttpServletRequest innerRequest = ic.getRequest();
+ assertEquals( "request URI", "/sample/" + outerServletName, innerRequest.getRequestURI() );
+ assertEquals( "context path attribute", "/sample", innerRequest.getContextPath() );
+ assertEquals( "servlet path attribute", "/" + outerServletName, innerRequest.getServletPath() );
+ assertNull( "path info not null attribute", innerRequest.getPathInfo() );
+// assertEquals( "query string attribute", "param=original¶m1=first", innerRequest.getQueryString() );
+
+ assertEquals( "request URI attribute", "/sample/" + innerServletName, innerRequest.getAttribute( REQUEST_URI ) );
+ assertEquals( "context path attribute", "/sample", innerRequest.getAttribute( CONTEXT_PATH ) );
+ assertEquals( "servlet path attribute", "/" + innerServletName, innerRequest.getAttribute( SERVLET_PATH ) );
+ assertNull( "path info attribute not null", innerRequest.getAttribute( PATH_INFO ) );
+// assertEquals( "query string attribute", "param=revised¶m2=new", innerRequest.getAttribute( QUERY_STRING ) );
+
+ ic.popRequest();
+ final HttpServletRequest restoredRequest = ic.getRequest();
+
+ assertNull( "reverted URI attribute not null", restoredRequest.getAttribute( REQUEST_URI ) );
+ assertNull( "context path attribute not null", restoredRequest.getAttribute( CONTEXT_PATH ) );
+ assertNull( "servlet path attribute not null", restoredRequest.getAttribute( SERVLET_PATH ) );
+ assertNull( "path info attribute not null", restoredRequest.getAttribute( PATH_INFO ) );
+// assertNull( "query string attribute not null", "param=revised¶m2=new", restoredRequest.getAttribute( QUERY_STRING ) );
+ }
+
+
+
+
+ public void testRequestDispatcherForwardPaths() throws Exception {
+ InvocationContext ic = _runner.newClient().newInvocation( "http://localhost/sample/" + outerServletName + "?param=original¶m1=first" );
+
+ final HttpServletRequest request = ic.getRequest();
+ RequestDispatcherServlet servlet = (RequestDispatcherServlet) ic.getServlet();
+ RequestDispatcher rd = servlet.getServletContext().getRequestDispatcher( "/" + innerServletName + "?param=revised¶m2=new" );
assertEquals( "request URI", "/sample/" + outerServletName, request.getRequestURI() );
assertEquals( "context path attribute", "/sample", request.getContextPath() );
assertEquals( "servlet path attribute", "/" + outerServletName, request.getServletPath() );
assertNull( "path info not null attribute", request.getPathInfo() );
-// assertEquals( "query string attribute", "param=original¶m1=first", request.getQueryString() );
-
- assertEquals( "request URI attribute", "/sample/" + innerServletName, request.getAttribute( REQUEST_URI ) );
- assertEquals( "context path attribute", "/sample", request.getAttribute( CONTEXT_PATH ) );
- assertEquals( "servlet path attribute", "/" + innerServletName, request.getAttribute( SERVLET_PATH ) );
- assertNull( "path info attribute not null", request.getAttribute( PATH_INFO ) );
-// assertEquals( "query string attribute", "param=revised¶m2=new", request.getAttribute( QUERY_STRING ) );
-
- ic.popContext();
-
- assertNull( "reverted URI attribute not null", request.getAttribute( REQUEST_URI ) );
- assertNull( "context path attribute not null", request.getAttribute( CONTEXT_PATH ) );
- assertNull( "servlet path attribute not null", request.getAttribute( SERVLET_PATH ) );
- assertNull( "path info attribute not null", request.getAttribute( PATH_INFO ) );
-// assertNull( "query string attribute not null", "param=revised¶m2=new", request.getAttribute( QUERY_STRING ) );
- }
+// assertEquals( "query string attribute", "param=original¶m1=first", request.getQueryString() ); TODO make this work
+ final HttpServletResponse response = ic.getResponse();
+ ic.pushForwardRequest( rd, request, response );
- public void notestInitialAttributes() throws Exception {
-
- WebRequest request = new GetMethodWebRequest( "http://localhost/" + outerServletName );
- InvocationContext ic = _runner.newClient().newInvocation( request );
- HttpServletRequest servletRequest = ic.getRequest();
- servletRequest.setAttribute( REQUEST_URI, "r" );
- servletRequest.setAttribute( QUERY_STRING, "q" );
- servletRequest.setAttribute( SERVLET_PATH, "s" );
- Servlet servlet = ic.getServlet();
- servlet.service( ic.getRequest(), ic.getResponse() );
- WebResponse response = ic.getServletResponse();
-
- assertEquals( "Request URI", "r", servletRequest.getAttribute( REQUEST_URI ) );
- assertEquals( "Query String", "q", servletRequest.getAttribute( QUERY_STRING ) );
- assertEquals( "ServletPath", "s", servletRequest.getAttribute( SERVLET_PATH ) );
- assertNotNull( "No response received", response );
- assertEquals( "Response Code", 200, response.getResponseCode() );
- assertEquals( "content type", "text/plain", response.getContentType() );
- assertEquals( "requested resource", IncludedServlet.DESIRED_OUTPUT, response.getText() );
+ final HttpServletRequest innerRequest = ic.getRequest();
+ assertEquals( "request URI", "/sample/" + innerServletName, innerRequest.getRequestURI() );
+ assertEquals( "context path attribute", "/sample", innerRequest.getContextPath() );
+ assertEquals( "servlet path attribute", "/" + innerServletName, innerRequest.getServletPath() );
+ assertNull( "path info not null attribute", innerRequest.getPathInfo() );
+// assertEquals( "query string attribute", "param=original¶m1=first", innerRequest.getQueryString() );
+
+ ic.popRequest();
+ final HttpServletRequest restoredRequest = ic.getRequest();
+
+ assertNull( "reverted URI attribute not null", restoredRequest.getAttribute( REQUEST_URI ) );
+ assertNull( "context path attribute not null", restoredRequest.getAttribute( CONTEXT_PATH ) );
+ assertNull( "servlet path attribute not null", restoredRequest.getAttribute( SERVLET_PATH ) );
+ assertNull( "path info attribute not null", restoredRequest.getAttribute( PATH_INFO ) );
+// assertNull( "query string attribute not null", "param=revised¶m2=new", restoredRequest.getAttribute( QUERY_STRING ) );
}
-
static class RequestDispatcherServlet extends HttpServlet {
Index: WebXMLTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/WebXMLTest.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- WebXMLTest.java 9 Oct 2002 19:15:29 -0000 1.13
+++ WebXMLTest.java 13 Feb 2003 20:25:56 -0000 1.14
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2001-2002, Russell Gold
+* Copyright (c) 2001-2003, 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
@@ -27,6 +27,8 @@
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.Properties;
+import java.util.List;
+import java.util.Arrays;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@@ -103,8 +105,10 @@
WebApplication app = new WebApplication( newDocument( wxs.asText() ) );
assertTrue( "Did not require authorization", app.requiresAuthorization( new URL( "http://localhost/SimpleServlet" ) ) );
assertTrue( "Should not require authorization", !app.requiresAuthorization( new URL( "http://localhost/FreeServlet" ) ) );
- assertTrue( "Should have access", app.roleMayAccess( "supervisor", new URL( "http://localhost/SimpleServlet" ) ) );
- assertTrue( "Should not have access", !app.roleMayAccess( "peon", new URL( "http://localhost/SimpleServlet" ) ) );
+
+ List roles = Arrays.asList( app.getPermittedRoles( new URL( "http://localhost/SimpleServlet" ) ) );
+ assertTrue( "Should have access", roles.contains( "supervisor" ) );
+ assertTrue( "Should not have access", !roles.contains( "peon" ) );
}
|
|
From: Russell G. <rus...@us...> - 2003-02-13 20:25:59
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit
In directory sc8-pr-cvs1:/tmp/cvs-serv7442/src/com/meterware/servletunit
Modified Files:
InvocationContext.java InvocationContextImpl.java
RequestContext.java RequestDispatcherImpl.java
ServletUnitHttpRequest.java WebApplication.java
Added Files:
HttpServletRequestWrapper.java ServletMetaData.java
Removed Files:
ServletRequest.java
Log Message:
Implemented request property changes for RequestDispatcher calls
***** Error reading new file[Errno 2] No such file or directory: 'HttpServletRequestWrapper.java'
***** Error reading new file[Errno 2] No such file or directory: 'ServletMetaData.java'
Index: InvocationContext.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/InvocationContext.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- InvocationContext.java 11 Feb 2003 04:32:00 -0000 1.6
+++ InvocationContext.java 13 Feb 2003 20:25:55 -0000 1.7
@@ -1,9 +1,8 @@
package com.meterware.servletunit;
-
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2001-2002, Russell Gold
+ * Copyright (c) 2001-2003, 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
@@ -34,7 +33,7 @@
/**
* An interface which represents the invocation of a servlet.
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
public interface InvocationContext {
@@ -72,14 +71,20 @@
/**
- * Adds a request dispatcher to this context.
+ * Adds a request dispatcher to this context to simulate an include request.
+ */
+ void pushIncludeRequest( RequestDispatcher rd, HttpServletRequest request, HttpServletResponse response ) throws ServletException;
+
+
+ /**
+ * Adds a request dispatcher to this context to simulate a forward request.
*/
- void pushIncludedContext( RequestDispatcher rd );
+ void pushForwardRequest( RequestDispatcher rd, HttpServletRequest request, HttpServletResponse response ) throws ServletException;
/**
* Removes the top request dispatcher from this context.
*/
- void popContext();
+ void popRequest();
}
Index: InvocationContextImpl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/InvocationContextImpl.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- InvocationContextImpl.java 11 Feb 2003 04:32:00 -0000 1.10
+++ InvocationContextImpl.java 13 Feb 2003 20:25:55 -0000 1.11
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2001-2002, Russell Gold
+* Copyright (c) 2001-2003, 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
@@ -26,13 +26,9 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.Dictionary;
-import java.util.StringTokenizer;
-import java.util.Vector;
-
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
-import javax.servlet.RequestDispatcher;
+import java.util.*;
+
+import javax.servlet.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -110,20 +106,33 @@
}
- public void pushIncludedContext( RequestDispatcher rd ) {
- _request.pushRequestContext( (RequestContext) rd );
+ public void pushIncludeRequest( RequestDispatcher rd, HttpServletRequest request, HttpServletResponse response ) throws ServletException {
+ if (_servlet == null) throw new IllegalStateException( "Get the servlet for this context before pushing a request" );
+ _request = new IncludeRequestWrapper( request, rd );
+ _servletStack.push( _servlet );
+ _servlet = ((RequestDispatcherImpl) rd).getServletMetaData().getServlet();
+ }
+
+
+ public void pushForwardRequest( RequestDispatcher rd, HttpServletRequest request, HttpServletResponse response ) throws ServletException {
+ if (_servlet == null) throw new IllegalStateException( "Get the servlet for this context before pushing a request" );
+ _request = new ForwardRequestWrapper( request, rd );
+ _servletStack.push( _servlet );
+ _servlet = ((RequestDispatcherImpl) rd).getServletMetaData().getServlet();
}
- public void popContext() {
- _request.popRequestContext();
+ public void popRequest() {
+ if (!( _request instanceof HttpServletRequestWrapper)) throw new IllegalStateException( "May not pop the initial request" );
+ _request = ((HttpServletRequestWrapper) _request).getBaseRequest();
+ _servlet = (Servlet) _servletStack.pop();
}
private boolean userIsAuthorized() {
- final String[] roles = _request.getRoles();
+ String[] roles = _application.getPermittedRoles( _requestURL );
for (int i = 0; i < roles.length; i++) {
- if (_application.roleMayAccess( roles[i], _requestURL )) return true;
+ if (_request.isUserInRole( roles[i] )) return true;
}
return false;
}
@@ -149,13 +158,14 @@
_requestURL = request.getURL();
_target = request.getTarget();
- _request = new ServletUnitHttpRequest( _application.getServletRequest( _requestURL ), request, runner.getContext(),
- clientHeaders, messageBody );
+ final ServletUnitHttpRequest suhr = new ServletUnitHttpRequest( _application.getServletRequest( _requestURL ), request, runner.getContext(),
+ clientHeaders, messageBody );
+ _request = suhr;
Cookie[] cookies = getCookies( clientHeaders );
- for (int i = 0; i < cookies.length; i++) _request.addCookie( cookies[i] );
+ for (int i = 0; i < cookies.length; i++) suhr.addCookie( cookies[i] );
- if (_application.usesBasicAuthentication()) _request.readBasicAuthentication();
- else if (_application.usesFormAuthentication()) _request.readFormAuthentication();
+ if (_application.usesBasicAuthentication()) suhr.readBasicAuthentication();
+ else if (_application.usesFormAuthentication()) suhr.readFormAuthentication();
HttpSession session = _request.getSession( /* create */ false );
if (session != null) ((ServletUnitHttpSession) session).access();
@@ -171,9 +181,10 @@
private ServletUnitClient _client;
private WebApplication _application;
- private ServletUnitHttpRequest _request;
+ private HttpServletRequest _request;
private ServletUnitHttpResponse _response = new ServletUnitHttpResponse();
private URL _requestURL;
+ private Stack _servletStack = new Stack();
private String _target;
private Servlet _servlet;
@@ -196,6 +207,99 @@
Cookie[] results = new Cookie[ cookies.size() ];
cookies.copyInto( results );
return results;
+ }
+}
+
+
+class DispatchedRequestWrapper extends HttpServletRequestWrapper {
+
+ RequestContext _requestContext;
+
+ public DispatchedRequestWrapper( HttpServletRequest request, RequestDispatcher dispatcher ) {
+ super( request );
+ _requestContext = (RequestContext) dispatcher;
+ _requestContext.setParentRequest( request );
+ }
+
+
+ public String getParameter( String s ) {
+ return _requestContext.getParameter( s );
+ }
+
+
+ public Enumeration getParameterNames() {
+ return _requestContext.getParameterNames();
+ }
+
+
+ public String[] getParameterValues( String s ) {
+ return _requestContext.getParameterValues( s );
+ }
+
+
+ public Map getParameterMap() {
+ return _requestContext.getParameterMap();
+ }
+
+}
+
+
+class IncludeRequestWrapper extends DispatchedRequestWrapper {
+
+ final static String REQUEST_URI = "javax.servlet.include.request_uri";
+ final static String CONTEXT_PATH = "javax.servlet.include.context_path";
+ final static String SERVLET_PATH = "javax.servlet.include.servlet_path";
+ final static String PATH_INFO = "javax.servlet.include.path_info";
+ final static String QUERY_STRING = "javax.servlet.include.query_string";
+
+ private Hashtable _attributes = new Hashtable();
+
+
+ public IncludeRequestWrapper( HttpServletRequest request, RequestDispatcher dispatcher ) {
+ super( request, dispatcher );
+ _attributes.put( REQUEST_URI, ((RequestDispatcherImpl) dispatcher ).getRequestURI() );
+ _attributes.put( CONTEXT_PATH, request.getContextPath() );
+ _attributes.put( SERVLET_PATH, ((RequestDispatcherImpl) dispatcher ).getServletMetaData().getServletPath() );
+ final String pathInfo = ((RequestDispatcherImpl) dispatcher ).getServletMetaData().getPathInfo();
+ if (pathInfo != null) _attributes.put( PATH_INFO, pathInfo );
+ }
+
+
+ public Object getAttribute( String s ) {
+ Object result = _attributes.get( s );
+ return (result != null) ? result : super.getAttribute( s );
+ }
+
+}
+
+
+class ForwardRequestWrapper extends DispatchedRequestWrapper {
+
+ private RequestDispatcherImpl _requestContext;
+
+ public ForwardRequestWrapper( HttpServletRequest request, RequestDispatcher dispatcher ) {
+ super( request, dispatcher );
+ _requestContext = (RequestDispatcherImpl) dispatcher;
+ }
+
+
+ public String getRequestURI() {
+ return _requestContext.getRequestURI();
+ }
+
+
+ public String getQueryString() {
+ return super.getQueryString();
+ }
+
+
+ public String getServletPath() {
+ return _requestContext.getServletMetaData().getServletPath();
+ }
+
+
+ public String getPathInfo() {
+ return _requestContext.getServletMetaData().getPathInfo();
}
}
Index: RequestContext.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/RequestContext.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RequestContext.java 11 Feb 2003 04:32:00 -0000 1.1
+++ RequestContext.java 13 Feb 2003 20:25:55 -0000 1.2
@@ -21,12 +21,11 @@
*******************************************************************************************************************/
import com.meterware.httpunit.HttpUnitUtils;
-import java.util.Hashtable;
-import java.util.Enumeration;
-import java.util.Map;
-import java.util.StringTokenizer;
+import java.util.*;
import java.net.URL;
+import javax.servlet.http.HttpServletRequest;
+
/**
*
@@ -36,7 +35,7 @@
private Hashtable _parameters = new Hashtable();
private Hashtable _visibleParameters;
- private RequestContext _parentContext;
+ private HttpServletRequest _parentRequest;
private URL _url;
@@ -47,19 +46,20 @@
}
- void setParentContext( RequestContext parentContext ) {
- _parentContext = parentContext;
+ void setParentRequest( HttpServletRequest parentRequest ) {
+ _parentRequest = parentRequest;
_visibleParameters = null;
}
- RequestContext getParentContext() {
- return _parentContext;
+ String getRequestURI() {
+ return _url.getPath();
}
- String getRequestURI() {
- return _url.getPath();
+ String getParameter( String name ) {
+ String[] parameters = (String[]) getParameters().get( name );
+ return parameters == null ? null : parameters[0];
}
@@ -149,10 +149,15 @@
private Hashtable getParameters() {
if (_visibleParameters == null) {
- if (_parentContext == null) {
+ if (_parentRequest == null) {
_visibleParameters = _parameters;
} else {
- _visibleParameters = (Hashtable) _parentContext.getParameters().clone();
+ _visibleParameters = new Hashtable();
+ final Map parameterMap = _parentRequest.getParameterMap();
+ for (Iterator i = parameterMap.keySet().iterator(); i.hasNext();) {
+ Object key = i.next();
+ _visibleParameters.put( key, parameterMap.get( key ) );
+ }
for (Enumeration e = _parameters.keys(); e.hasMoreElements();) {
Object key = e.nextElement();
_visibleParameters.put( key, _parameters.get( key ) );
Index: RequestDispatcherImpl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/RequestDispatcherImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RequestDispatcherImpl.java 11 Feb 2003 04:32:00 -0000 1.2
+++ RequestDispatcherImpl.java 13 Feb 2003 20:25:55 -0000 1.3
@@ -26,7 +26,7 @@
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.ServletException;
-import javax.servlet.Servlet;
+import javax.servlet.http.HttpServletRequest;
/**
@@ -35,22 +35,27 @@
**/
class RequestDispatcherImpl extends RequestContext implements RequestDispatcher {
- private Servlet _servlet;
+ private ServletMetaData _servletMetaData;
- public RequestDispatcherImpl( WebApplication application, URL url ) throws ServletException {
+ RequestDispatcherImpl( WebApplication application, URL url ) throws ServletException {
super( url );
- _servlet = application.getServletRequest( url ).getServlet();
+ _servletMetaData = application.getServletRequest( url );
+ }
+
+
+ public ServletMetaData getServletMetaData() {
+ return _servletMetaData;
}
public void forward( ServletRequest request, ServletResponse response ) throws ServletException, IOException {
((ServletUnitHttpResponse) response).restartResponse();
- _servlet.service( request, response );
+ _servletMetaData.getServlet().service( new ForwardRequestWrapper( (HttpServletRequest) request, this ), response );
}
public void include( ServletRequest request, ServletResponse response ) throws ServletException, IOException {
- _servlet.service( request, response );
+ _servletMetaData.getServlet().service( new IncludeRequestWrapper( (HttpServletRequest) request, this ), response );
}
}
Index: ServletUnitHttpRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- ServletUnitHttpRequest.java 13 Feb 2003 15:37:00 -0000 1.23
+++ ServletUnitHttpRequest.java 13 Feb 2003 20:25:56 -0000 1.24
@@ -52,7 +52,7 @@
/**
* Constructs a ServletUnitHttpRequest from a WebRequest object.
**/
- ServletUnitHttpRequest( ServletRequest servletRequest, WebRequest request, ServletUnitContext context, Dictionary clientHeaders, byte[] messageBody ) throws MalformedURLException {
+ ServletUnitHttpRequest( ServletMetaData servletRequest, WebRequest request, ServletUnitContext context, Dictionary clientHeaders, byte[] messageBody ) throws MalformedURLException {
if (context == null) throw new IllegalArgumentException( "Context must not be null" );
_servletRequest = servletRequest;
@@ -720,31 +720,12 @@
}
- String[] getRoles() {
- return _roles == null ? NO_ROLES : _roles;
- }
-
-
- void pushRequestContext( RequestContext requestContext ) {
- requestContext.setParentContext( _requestContext );
- _requestContext = requestContext;
- }
-
-
- void popRequestContext() {
- _requestContext = _requestContext.getParentContext();
- }
-
-
-
//--------------------------------------------- private members ----------------------------------------------
final static private String LOOPBACK_ADDRESS = "127.0.0.1";
- final static private String[] NO_ROLES = new String[0];
-
private WebRequest _request;
- private ServletRequest _servletRequest;
+ private ServletMetaData _servletRequest;
private WebClient.HeaderDictionary _headers;
private ServletUnitContext _context;
private ServletUnitHttpSession _session;
Index: WebApplication.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/WebApplication.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- WebApplication.java 3 Jan 2003 16:12:35 -0000 1.16
+++ WebApplication.java 13 Feb 2003 20:25:56 -0000 1.17
@@ -26,12 +26,7 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Map;
+import java.util.*;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
@@ -134,7 +129,7 @@
}
- ServletRequest getServletRequest( URL url ) {
+ ServletMetaData getServletRequest( URL url ) {
return _servletMapping.get( url );
}
@@ -189,9 +184,9 @@
/**
- * Returns true of the specified role may access the desired URL path.
+ * Returns an array containing the roles permitted to access the specified URL.
*/
- boolean roleMayAccess( String roleName, URL url ) {
+ String[] getPermittedRoles( URL url ) {
String result;
String file = url.getFile();
if (_contextPath.equals( "" )) {
@@ -201,7 +196,7 @@
} else {
result = null;
}
- return getControllingConstraint( result ).hasRole( roleName );
+ return getControllingConstraint( result ).getPermittedRoles();
}
@@ -429,19 +424,22 @@
boolean controlsPath( String urlPath );
- boolean hasRole( String roleName );
+ String[] getPermittedRoles();
}
static class NullSecurityConstraint implements SecurityConstraint {
+ private static final String[] NO_ROLES = new String[0];
+
+
public boolean controlsPath( String urlPath ) {
return false;
}
- public boolean hasRole( String roleName ) {
- return true;
+ public String[] getPermittedRoles() {
+ return NO_ROLES;
}
}
@@ -450,7 +448,7 @@
SecurityConstraintImpl( Element root ) throws SAXException {
final NodeList roleNames = root.getElementsByTagName( "role-name" );
- for (int i = 0; i < roleNames.getLength(); i++) _roles.add( getTextValue( roleNames.item( i ) ) );
+ for (int i = 0; i < roleNames.getLength(); i++) _roleList.add( getTextValue( 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 ) ) );
@@ -462,12 +460,16 @@
}
- public boolean hasRole( String roleName ) {
- return _roles.contains( roleName );
+ public String[] getPermittedRoles() {
+ if (_roles == null) {
+ _roles = (String[]) _roleList.toArray( new String[ _roleList.size() ] );
+ }
+ return _roles;
}
- private ArrayList _roles = new ArrayList();
+ private String[] _roles;
+ private ArrayList _roleList = new ArrayList();
private ArrayList _resources = new ArrayList();
@@ -502,7 +504,7 @@
}
- static class ServletRequestImpl implements ServletRequest {
+ static class ServletRequestImpl implements ServletMetaData {
private URL _url;
private String _servletName;
@@ -641,7 +643,7 @@
}
- ServletRequest get( URL url ) {
+ ServletMetaData get( URL url ) {
String file = url.getFile();
if (!file.startsWith( _contextPath )) throw new HttpNotFoundException( "File path does not begin with '" + _contextPath + "'", url );
|
|
From: Russell G. <rus...@us...> - 2003-02-13 20:25:58
|
Update of /cvsroot/httpunit/httpunit/doc
In directory sc8-pr-cvs1:/tmp/cvs-serv7442/doc
Modified Files:
release_notes.txt
Log Message:
Implemented request property changes for RequestDispatcher calls
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.252
retrieving revision 1.253
diff -u -r1.252 -r1.253
--- release_notes.txt 13 Feb 2003 15:36:59 -0000 1.252
+++ release_notes.txt 13 Feb 2003 20:25:54 -0000 1.253
@@ -7,17 +7,26 @@
Limitations:
1. JDK 1.3.1 or higher is required
2. JavaScript support does not include some DOM properties
- 3. Document.cookie= does not restrict the cookie by path and domain
+ 3. The JavaScript assignment Document.cookie= does not restrict the cookie by path and domain
Revision History:
13-Feb-2003
Acknowledgements:
- Thanks to Ron Hanson for catching the obsolete behavior of HttpServletRequest.setAttribute
+ Thanks to Ron Hanson for catching the obsolete behavior of HttpServletRequest.setAttribute.
+ Thanks to Ron Hanson and also to Daniel Sheppard for help in adding capabilities to the RequestDispatcher implementation.
Problems Fixed:
1. Calling HttpServletRequest.setAttribute in ServletUnit no longer throws an IllegalStateException if the value
had previously been defined.
+ 2. Included and forwarded servlets now inherit parameters from their calling servlet.
+ 3. Included servlets now have access to their path information as attributes, as per the spec.
+ 4. Forwarded servlets now have access to their path information from the standard request methods, as required.
+
+Additions:
+ 1. InvocationContext now supports include and forwarded servlets: calling pushIncludeRequest or pushForwardRequest
+ updates the servlet, request, and response properties of the context so that subsequent calls can be done from
+ the dispatched servlet. Calling popRequest reverts to the dispatching servlet.
5-Feb-2003
Acknowledgements:
|
|
From: Russell G. <rus...@us...> - 2003-02-13 15:37:34
|
Update of /cvsroot/httpunit/httpunit/doc
In directory sc8-pr-cvs1:/tmp/cvs-serv18094/doc
Modified Files:
release_notes.txt
Log Message:
setAttribute now permits multiple calls with the same value
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.251
retrieving revision 1.252
diff -u -r1.251 -r1.252
--- release_notes.txt 6 Feb 2003 02:55:58 -0000 1.251
+++ release_notes.txt 13 Feb 2003 15:36:59 -0000 1.252
@@ -11,6 +11,14 @@
Revision History:
+ 13-Feb-2003
+Acknowledgements:
+ Thanks to Ron Hanson for catching the obsolete behavior of HttpServletRequest.setAttribute
+
+Problems Fixed:
+ 1. Calling HttpServletRequest.setAttribute in ServletUnit no longer throws an IllegalStateException if the value
+ had previously been defined.
+
5-Feb-2003
Acknowledgements:
Thanks to Navid Vahdat for ServletUnit fixes for invalid session handling and request dispatcher paths
|
|
From: Russell G. <rus...@us...> - 2003-02-13 15:37:11
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit
In directory sc8-pr-cvs1:/tmp/cvs-serv18094/test/com/meterware/servletunit
Modified Files:
HttpServletRequestTest.java
Log Message:
setAttribute now permits multiple calls with the same value
Index: HttpServletRequestTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/HttpServletRequestTest.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- HttpServletRequestTest.java 6 Feb 2003 01:33:11 -0000 1.12
+++ HttpServletRequestTest.java 13 Feb 2003 15:37:01 -0000 1.13
@@ -188,15 +188,21 @@
public void testDuplicateAttributes() throws Exception {
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
- Object value = new Integer(1);
- request.setAttribute( "one", value );
+ request.setAttribute( "one", new Integer(1) );
+ request.setAttribute( "one", "One" );
+ assertEquals( "Revised attribute value", "One", request.getAttribute( "one" ) );
+ }
- try {
- request.setAttribute( "one", value );
- fail( "Did not complain about illegal state" );
- } catch (IllegalStateException e) {
- }
+
+ public void testNullAttributeValue() throws Exception {
+ WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
+ HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
+
+ request.setAttribute( "one", "One" );
+ assertEquals( "Initial attribute value", "One", request.getAttribute( "one" ) );
+ request.setAttribute( "one", null );
+ assertNull( "Attribute 'one' should have been removed", request.getAttribute( "one" ) );
}
|
|
From: Russell G. <rus...@us...> - 2003-02-13 15:37:10
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit
In directory sc8-pr-cvs1:/tmp/cvs-serv18094/src/com/meterware/servletunit
Modified Files:
ServletUnitHttpRequest.java
Log Message:
setAttribute now permits multiple calls with the same value
Index: ServletUnitHttpRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- ServletUnitHttpRequest.java 11 Feb 2003 04:32:00 -0000 1.22
+++ ServletUnitHttpRequest.java 13 Feb 2003 15:37:00 -0000 1.23
@@ -473,13 +473,10 @@
*
* Stores an attribute in the context of this request.
* Attributes are reset between requests.
- *
- * @exception IllegalStateException if the specified attribute already has a value
- *
**/
public void setAttribute( String key, Object o ) {
- if (_attributes.get( key ) != null) throw new IllegalStateException( "Attribute '" + key + "' already has a value" );
- _attributes.put( key, o );
+ if (o == null) _attributes.remove( key );
+ else _attributes.put( key, o );
}
|
|
From: Russell G. <rus...@us...> - 2003-02-12 13:47:30
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit
In directory sc8-pr-cvs1:/tmp/cvs-serv9526/test/com/meterware/servletunit
Modified Files:
ServletUnitSuite.java
Added Files:
RequestContextTest.java RequestDispatcherTest.java
Log Message:
Added tests for request dispatcher enhancements
***** Error reading new file[Errno 2] No such file or directory: 'RequestContextTest.java'
--- NEW FILE ---
package com.meterware.servletunit;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import junit.framework.TestCase;
import junit.framework.Test;
import junit.framework.TestSuite;
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
public class RequestDispatcherTest extends TestCase {
final String outerServletName = "something/interesting";
final String innerServletName = "something/more";
final static String REQUEST_URI = "javax.servlet.include.request_uri";
final static String CONTEXT_PATH = "javax.servlet.include.context_path";
final static String SERVLET_PATH = "javax.servlet.include.servlet_path";
final static String PATH_INFO = "javax.servlet.include.path_info";
final static String QUERY_STRING = "javax.servlet.include.query_string";
private ServletRunner _runner;
public static void main(String args[]) {
junit.textui.TestRunner.run( suite() );
}
public static Test suite() {
return new TestSuite( RequestDispatcherTest.class );
}
public RequestDispatcherTest( String name ) {
super( name );
}
public void setUp() throws Exception {
super.setUp();
WebXMLString wxs = new WebXMLString();
wxs.addServlet( outerServletName, RequestDispatcherServlet.class );
wxs.addServlet( innerServletName, IncludedServlet.class );
_runner = new ServletRunner( wxs.asInputStream(), "/sample");
}
public void testRequestDispatcherParameters() throws Exception {
InvocationContext ic = _runner.newClient().newInvocation( "http://localhost/sample/" + outerServletName + "?param=original¶m1=first" );
final HttpServletRequest request = ic.getRequest();
RequestDispatcherServlet servlet = (RequestDispatcherServlet) ic.getServlet();
RequestDispatcher rd = servlet.getServletContext().getRequestDispatcher( "/" + innerServletName + "?param=revised¶m2=new" );
assertEquals( "param", "original", request.getParameter( "param" ) );
assertEquals( "param1", "first", request.getParameter( "param1" ) );
assertNull( "param2 should not be defined", request.getParameter( "param2" ) );
ic.pushIncludedContext( rd );
assertEquals( "param in included servlet", "revised", request.getParameter( "param" ) );
assertEquals( "param1 in included servlet", "first", request.getParameter( "param1" ) );
assertEquals( "param2 in included servlet", "new", request.getParameter( "param2" ) );
ic.popContext();
assertEquals( "reverted param", "original", request.getParameter( "param" ) );
assertEquals( "reverted param1", "first", request.getParameter( "param1" ) );
assertNull( "reverted param2 should not be defined", request.getParameter( "param2" ) );
}
public void notestRequestDispatcherIncludePaths() throws Exception {
InvocationContext ic = _runner.newClient().newInvocation( "http://localhost/sample/" + outerServletName + "?param=original¶m1=first" );
final HttpServletRequest request = ic.getRequest();
RequestDispatcherServlet servlet = (RequestDispatcherServlet) ic.getServlet();
RequestDispatcher rd = servlet.getServletContext().getRequestDispatcher( "/" + innerServletName + "?param=revised¶m2=new" );
assertEquals( "request URI", "/sample/" + outerServletName, request.getRequestURI() );
assertEquals( "context path attribute", "/sample", request.getContextPath() );
assertEquals( "servlet path attribute", "/" + outerServletName, request.getServletPath() );
assertNull( "path info not null attribute", request.getPathInfo() );
// assertEquals( "query string attribute", "param=original¶m1=first", request.getQueryString() ); TODO make this work
ic.pushIncludedContext( rd );
assertEquals( "request URI", "/sample/" + outerServletName, request.getRequestURI() );
assertEquals( "context path attribute", "/sample", request.getContextPath() );
assertEquals( "servlet path attribute", "/" + outerServletName, request.getServletPath() );
assertNull( "path info not null attribute", request.getPathInfo() );
// assertEquals( "query string attribute", "param=original¶m1=first", request.getQueryString() );
assertEquals( "request URI attribute", "/sample/" + innerServletName, request.getAttribute( REQUEST_URI ) );
assertEquals( "context path attribute", "/sample", request.getAttribute( CONTEXT_PATH ) );
assertEquals( "servlet path attribute", "/" + innerServletName, request.getAttribute( SERVLET_PATH ) );
assertNull( "path info attribute not null", request.getAttribute( PATH_INFO ) );
// assertEquals( "query string attribute", "param=revised¶m2=new", request.getAttribute( QUERY_STRING ) );
ic.popContext();
assertNull( "reverted URI attribute not null", request.getAttribute( REQUEST_URI ) );
assertNull( "context path attribute not null", request.getAttribute( CONTEXT_PATH ) );
assertNull( "servlet path attribute not null", request.getAttribute( SERVLET_PATH ) );
assertNull( "path info attribute not null", request.getAttribute( PATH_INFO ) );
// assertNull( "query string attribute not null", "param=revised¶m2=new", request.getAttribute( QUERY_STRING ) );
}
public void notestInitialAttributes() throws Exception {
WebRequest request = new GetMethodWebRequest( "http://localhost/" + outerServletName );
InvocationContext ic = _runner.newClient().newInvocation( request );
HttpServletRequest servletRequest = ic.getRequest();
servletRequest.setAttribute( REQUEST_URI, "r" );
servletRequest.setAttribute( QUERY_STRING, "q" );
servletRequest.setAttribute( SERVLET_PATH, "s" );
Servlet servlet = ic.getServlet();
servlet.service( ic.getRequest(), ic.getResponse() );
WebResponse response = ic.getServletResponse();
assertEquals( "Request URI", "r", servletRequest.getAttribute( REQUEST_URI ) );
assertEquals( "Query String", "q", servletRequest.getAttribute( QUERY_STRING ) );
assertEquals( "ServletPath", "s", servletRequest.getAttribute( SERVLET_PATH ) );
assertNotNull( "No response received", response );
assertEquals( "Response Code", 200, response.getResponseCode() );
assertEquals( "content type", "text/plain", response.getContentType() );
assertEquals( "requested resource", IncludedServlet.DESIRED_OUTPUT, response.getText() );
}
static class RequestDispatcherServlet extends HttpServlet {
public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher( "/subdir/pagename.jsp?param=value¶m2=value" );
dispatcher.forward( request, response );
}
}
static class IncludedServlet extends HttpServlet {
static String DESIRED_REQUEST_URI = "localhost/subdir/pagename.jsp";
static String DESIRED_SERVLET_PATH = "/subdir/pagename.jsp";
static String DESIRED_QUERY_STRING = "param=value¶m2=value";
static String DESIRED_OUTPUT = DESIRED_REQUEST_URI + DESIRED_QUERY_STRING + DESIRED_SERVLET_PATH;
public void service( HttpServletRequest request, HttpServletResponse response ) throws IOException {
response.setContentType( "text/plain" );
String requestUri = (String) request.getAttribute( REQUEST_URI );
String queryString = (String) request.getAttribute( QUERY_STRING );
String servletPath = (String) request.getAttribute( SERVLET_PATH );
PrintWriter pw = response.getWriter();
pw.write( blankIfNull( requestUri ) );
pw.write( blankIfNull( queryString ) );
pw.write( blankIfNull( servletPath ) );
pw.close();
}
private String blankIfNull( String s ) {
return s == null ? "" : s;
}
}
}
Index: ServletUnitSuite.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/ServletUnitSuite.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ServletUnitSuite.java 11 Feb 2003 04:32:01 -0000 1.6
+++ ServletUnitSuite.java 12 Feb 2003 13:47:24 -0000 1.7
@@ -4,12 +4,12 @@
*
* Copyright (c) 2000-2003, 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
@@ -34,8 +34,8 @@
public static void main( String args[] ) {
junit.textui.TestRunner.run( suite() );
}
-
-
+
+
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest( HttpServletRequestTest.suite() );
@@ -46,6 +46,8 @@
suite.addTest( NavigationTest.suite() );
suite.addTest( ConfigTest.suite() );
suite.addTest( WebXMLTest.suite() );
+ suite.addTest( RequestContextTest.suite() );
+ suite.addTest( RequestDispatcherTest.suite() );
addOptionalTestCase( suite, "com.meterware.servletunit.JUnitServletTest" );
return suite;
}
|
|
From: Russell G. <rus...@us...> - 2003-02-11 04:32:04
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit
In directory sc8-pr-cvs1:/tmp/cvs-serv29478/src/com/meterware/servletunit
Modified Files:
InvocationContext.java InvocationContextImpl.java
RequestDispatcherImpl.java ServletUnitHttpRequest.java
ServletUnitServletContext.java
Added Files:
RequestContext.java
Log Message:
Support parameter overrides in request dispatcher
***** Error reading new file[Errno 2] No such file or directory: 'RequestContext.java'
Index: InvocationContext.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/InvocationContext.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- InvocationContext.java 6 Mar 2002 04:59:52 -0000 1.5
+++ InvocationContext.java 11 Feb 2003 04:32:00 -0000 1.6
@@ -26,6 +26,8 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
+import javax.servlet.RequestDispatcher;
+
import java.io.IOException;
@@ -67,5 +69,17 @@
* Returns the target for the original request.
*/
String getTarget();
+
+
+ /**
+ * Adds a request dispatcher to this context.
+ */
+ void pushIncludedContext( RequestDispatcher rd );
+
+
+ /**
+ * Removes the top request dispatcher from this context.
+ */
+ void popContext();
}
Index: InvocationContextImpl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/InvocationContextImpl.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- InvocationContextImpl.java 21 Oct 2002 13:34:19 -0000 1.9
+++ InvocationContextImpl.java 11 Feb 2003 04:32:00 -0000 1.10
@@ -32,6 +32,7 @@
import javax.servlet.Servlet;
import javax.servlet.ServletException;
+import javax.servlet.RequestDispatcher;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -106,6 +107,16 @@
*/
public String getTarget() {
return _target;
+ }
+
+
+ public void pushIncludedContext( RequestDispatcher rd ) {
+ _request.pushRequestContext( (RequestContext) rd );
+ }
+
+
+ public void popContext() {
+ _request.popRequestContext();
}
Index: RequestDispatcherImpl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/RequestDispatcherImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RequestDispatcherImpl.java 22 Jan 2002 15:25:16 -0000 1.1
+++ RequestDispatcherImpl.java 11 Feb 2003 04:32:00 -0000 1.2
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2002, Russell Gold
+ * Copyright (c) 2002-2003, 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
@@ -20,6 +20,7 @@
*
*******************************************************************************************************************/
import java.io.IOException;
+import java.net.URL;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletRequest;
@@ -30,15 +31,16 @@
/**
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
-class RequestDispatcherImpl implements RequestDispatcher {
+class RequestDispatcherImpl extends RequestContext implements RequestDispatcher {
private Servlet _servlet;
- public RequestDispatcherImpl( Servlet servlet ) {
- _servlet = servlet;
+ public RequestDispatcherImpl( WebApplication application, URL url ) throws ServletException {
+ super( url );
+ _servlet = application.getServletRequest( url ).getServlet();
}
Index: ServletUnitHttpRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- ServletUnitHttpRequest.java 6 Feb 2003 01:33:11 -0000 1.21
+++ ServletUnitHttpRequest.java 11 Feb 2003 04:32:00 -0000 1.22
@@ -19,7 +19,6 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
-import com.meterware.httpunit.HttpUnitUtils;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebClient;
import com.meterware.httpunit.Base64;
@@ -47,12 +46,15 @@
private String _contentType;
private Vector _locales;
private boolean _secure;
+ private RequestContext _requestContext;
/**
* Constructs a ServletUnitHttpRequest from a WebRequest object.
**/
ServletUnitHttpRequest( ServletRequest servletRequest, WebRequest request, ServletUnitContext context, Dictionary clientHeaders, byte[] messageBody ) throws MalformedURLException {
+ if (context == null) throw new IllegalArgumentException( "Context must not be null" );
+
_servletRequest = servletRequest;
_request = request;
_context = context;
@@ -62,13 +64,10 @@
_messageBody = messageBody;
_secure = request.getURL().getProtocol().equalsIgnoreCase( "https" );
_contentType = (String) _headers.get( "Content-Type" );
- 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 ) );
- if (_messageBody == null) return;
- if (_contentType == null || _contentType.indexOf( "x-www-form-urlencoded" ) >= 0 ) {
- loadParameters( new String( _messageBody ) );
+ _requestContext = new RequestContext( request.getURL() );
+ if (_messageBody != null && (_contentType == null || _contentType.indexOf( "x-www-form-urlencoded" ) >= 0 )) {
+ _requestContext.loadParameters( new String( _messageBody ) );
}
}
@@ -222,13 +221,10 @@
* Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.
**/
public String getRequestURI() {
- try {
- return _request.getURL().getPath();
- } catch (MalformedURLException e) {
- return null;
- }
+ return _requestContext.getRequestURI();
}
+
/**
* Returns the current HttpSession associated with this request or, if there is no current session
* and create is true, returns a new session.
@@ -357,7 +353,7 @@
* been read.
**/
public Enumeration getParameterNames() {
- return _parameters.keys();
+ return _requestContext.getParameterNames();
}
@@ -391,7 +387,7 @@
* containing the values of a query string or posted form.
**/
public String[] getParameterValues( String name ) {
- return (String[]) _parameters.get( name );
+ return _requestContext.getParameterValues( name );
}
@@ -612,7 +608,7 @@
* but does not end with a "/" character. For servlets in the default (root) context,
* this method returns "".
**/
- public java.lang.String getContextPath() {
+ public String getContextPath() {
return _context.getContextPath();
}
@@ -627,7 +623,7 @@
* @since 1.3
**/
public Map getParameterMap() {
- return _parameters;
+ return _requestContext.getParameterMap();
}
@@ -732,6 +728,17 @@
}
+ void pushRequestContext( RequestContext requestContext ) {
+ requestContext.setParentContext( _requestContext );
+ _requestContext = requestContext;
+ }
+
+
+ void popRequestContext() {
+ _requestContext = _requestContext.getParentContext();
+ }
+
+
//--------------------------------------------- private members ----------------------------------------------
@@ -745,7 +752,6 @@
private ServletUnitContext _context;
private ServletUnitHttpSession _session;
private Hashtable _attributes = new Hashtable();
- private Hashtable _parameters = new Hashtable();
private Vector _cookies = new Vector();
private String _sessionID;
private byte[] _messageBody;
@@ -754,75 +760,6 @@
private String[] _roles;
- final static private int STATE_INITIAL = 0;
- final static private int STATE_HAVE_NAME = 1;
- final static private int STATE_HAVE_EQUALS = 2;
- final static private int STATE_HAVE_VALUE = 3;
-
-
- /**
- * This method employs a state machine to parse a parameter query string.
- * The transition rules are as follows:
- * State \ text '=' '&'
- * initial: have_name - initial
- * have_name: - have_equals initial
- * have_equals: have_value - initial
- * have_value: - initial initial
- * actions occur on the following transitions:
- * initial -> have_name: save token as name
- * have_equals -> initial: record parameter with null value
- * have_value -> initial: record parameter with value
- **/
- private void loadParameters( String queryString ) {
- if (queryString.length() == 0) return;
- StringTokenizer st = new StringTokenizer( queryString, "&=", /* return tokens */ true );
- int state = STATE_INITIAL;
- String name = null;
- String value = null;
-
- while (st.hasMoreTokens()) {
- String token = st.nextToken();
- if (token.equals( "&" )) {
- state = STATE_INITIAL;
- if (name != null && value != null) addParameter( name, value );
- name = value = null;
- } else if (token.equals( "=" )) {
- if (state == STATE_HAVE_NAME) {
- state = STATE_HAVE_EQUALS;
- } else if (state == STATE_HAVE_VALUE) {
- state = STATE_INITIAL;
- }
- } else if (state == STATE_INITIAL) {
- name = HttpUnitUtils.decode( token );
- value = "";
- state = STATE_HAVE_NAME;
- } else {
- value = HttpUnitUtils.decode( token );
- state = STATE_HAVE_VALUE;
- }
- }
- if (name != null && value != null) addParameter( name, value );
- }
-
-
- private void addParameter( String name, String encodedValue ) {
- String[] values = (String[]) _parameters.get( name );
- if (values == null) {
- _parameters.put( name, new String[] { encodedValue } );
- } else {
- _parameters.put( name, extendedArray( values, encodedValue ) );
- }
- }
-
-
- private String[] extendedArray( String[] baseArray, String newValue ) {
- String[] result = new String[ baseArray.length+1 ];
- System.arraycopy( baseArray, 0, result, 0, baseArray.length );
- result[ baseArray.length ] = newValue;
- return result;
- }
-
-
private void throwNotImplementedYet() {
throw new RuntimeException( "Not implemented yet" );
}
@@ -871,3 +808,5 @@
}
}
+
+
Index: ServletUnitServletContext.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitServletContext.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ServletUnitServletContext.java 6 Feb 2003 01:33:11 -0000 1.11
+++ ServletUnitServletContext.java 11 Feb 2003 04:32:01 -0000 1.12
@@ -152,7 +152,7 @@
public javax.servlet.RequestDispatcher getRequestDispatcher( String path ) {
try {
URL url = new URL( "http", "localhost", _application.getContextPath() + path );
- return new RequestDispatcherImpl( _application.getServletRequest( url ).getServlet() );
+ return new RequestDispatcherImpl( _application, url );
} catch (ServletException e) {
return null;
} catch (MalformedURLException e) {
|
|
From: Russell G. <rus...@us...> - 2003-02-11 04:32:04
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit
In directory sc8-pr-cvs1:/tmp/cvs-serv29478/test/com/meterware/servletunit
Modified Files:
ServletUnitSuite.java
Log Message:
Support parameter overrides in request dispatcher
Index: ServletUnitSuite.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/ServletUnitSuite.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ServletUnitSuite.java 26 Nov 2002 11:55:57 -0000 1.5
+++ ServletUnitSuite.java 11 Feb 2003 04:32:01 -0000 1.6
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000, Russell Gold
+* Copyright (c) 2000-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -31,7 +31,7 @@
**/
public class ServletUnitSuite extends ConditionalTestSuite {
- public static void main(String args[]) {
+ public static void main( String args[] ) {
junit.textui.TestRunner.run( suite() );
}
|