httpunit-commit Mailing List for httpunit (Page 47)
Brought to you by:
russgold
You can subscribe to this list here.
| 2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(5) |
Sep
(31) |
Oct
(39) |
Nov
(18) |
Dec
(6) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2001 |
Jan
(8) |
Feb
(5) |
Mar
(8) |
Apr
(25) |
May
(20) |
Jun
(23) |
Jul
(28) |
Aug
(10) |
Sep
(3) |
Oct
(32) |
Nov
(61) |
Dec
(24) |
| 2002 |
Jan
(50) |
Feb
(34) |
Mar
(35) |
Apr
(3) |
May
(25) |
Jun
(25) |
Jul
(30) |
Aug
(146) |
Sep
(49) |
Oct
(156) |
Nov
(121) |
Dec
(54) |
| 2003 |
Jan
(12) |
Feb
(79) |
Mar
(88) |
Apr
(26) |
May
(67) |
Jun
(29) |
Jul
(8) |
Aug
(16) |
Sep
(20) |
Oct
(17) |
Nov
|
Dec
(5) |
| 2004 |
Jan
|
Feb
(40) |
Mar
(30) |
Apr
(5) |
May
|
Jun
(83) |
Jul
(34) |
Aug
(20) |
Sep
(44) |
Oct
(46) |
Nov
|
Dec
(14) |
| 2005 |
Jan
(4) |
Feb
|
Mar
(5) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
(1) |
| 2006 |
Jan
|
Feb
|
Mar
(26) |
Apr
(8) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(5) |
Nov
|
Dec
|
| 2008 |
Jan
|
Feb
|
Mar
|
Apr
(36) |
May
(38) |
Jun
(1) |
Jul
(1) |
Aug
|
Sep
(4) |
Oct
|
Nov
(18) |
Dec
(4) |
| 2009 |
Jan
|
Feb
(2) |
Mar
(3) |
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
(35) |
Sep
(1) |
Oct
|
Nov
|
Dec
(1) |
| 2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2011 |
Jan
(9) |
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(21) |
Oct
(18) |
Nov
(1) |
Dec
|
|
From: Russell G. <rus...@us...> - 2002-10-21 13:34:23
|
Update of /cvsroot/httpunit/httpunit/doc
In directory usw-pr-cvs1:/tmp/cvs-serv5578/doc
Modified Files:
release_notes.txt
Log Message:
Use application context as session cookie path
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.195
retrieving revision 1.196
diff -u -r1.195 -r1.196
--- release_notes.txt 17 Oct 2002 23:50:48 -0000 1.195
+++ release_notes.txt 21 Oct 2002 13:34:18 -0000 1.196
@@ -10,6 +10,11 @@
Revision History:
+21-Oct-2002
+Problems fixed:
+ 1. The cookie fixes of 17-Oct had caused ServletUnit to see multiple servlets in an application with varying paths
+ as being in separate sessions.
+
17-Oct-2002
Additions:
1. Cookies are now restricted by their origin server, rather than being sent on every request.
|
|
From: Russell G. <rus...@us...> - 2002-10-21 02:21:08
|
Update of /cvsroot/httpunit/httpunit/jars In directory usw-pr-cvs1:/tmp/cvs-serv8714 Added Files: nekohtml.jar xercesImpl.jar xmlParserAPIs.jar Log Message: Added jars with binary option |
|
From: Russell G. <rus...@us...> - 2002-10-21 02:19:20
|
Update of /cvsroot/httpunit/httpunit/jars In directory usw-pr-cvs1:/tmp/cvs-serv8428 Removed Files: nekohtml.jar xercesImpl.jar xmlParserAPIs.jar Log Message: remove jars added w/o binary option |
|
From: Russell G. <rus...@us...> - 2002-10-17 23:52:51
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/cookies In directory usw-pr-cvs1:/tmp/cvs-serv4656/test/com/meterware/httpunit/cookies Added Files: CookieTest.java Log Message: Added support for associating cookies with servers ***** Error reading new file[Errno 2] No such file or directory: 'CookieTest.java' |
|
From: Russell G. <rus...@us...> - 2002-10-17 23:52:09
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/cookies In directory usw-pr-cvs1:/tmp/cvs-serv4389/test/com/meterware/httpunit/cookies Log Message: Directory /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/cookies added to the repository |
|
From: Russell G. <rus...@us...> - 2002-10-17 23:51:22
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv3856/src/com/meterware/httpunit
Modified Files:
WebClient.java WebConversation.java WebResponse.java
Log Message:
Added support for associating cookies with servers
Index: WebClient.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- WebClient.java 14 Oct 2002 12:40:05 -0000 1.43
+++ WebClient.java 17 Oct 2002 23:50:48 -0000 1.44
@@ -24,10 +24,13 @@
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
+import java.net.URL;
import java.util.*;
import org.xml.sax.SAXException;
+import com.meterware.httpunit.cookies.CookieJar;
+import com.meterware.httpunit.cookies.CookieJar;
/**
@@ -204,7 +207,7 @@
**/
public void clearContents() {
_mainWindow = new WebWindow( this );
- _cookies = new Hashtable();
+ _cookieJar.clear();
_headers = new HeaderDictionary();
}
@@ -213,7 +216,7 @@
* Defines a cookie to be sent to the server on every request.
**/
public void addCookie( String name, String value ) {
- _cookies.put( name, value );
+ _cookieJar.addCookie( name, value );
}
@@ -221,12 +224,7 @@
* Returns the name of all the active cookies which will be sent to the server.
**/
public String[] getCookieNames() {
- String[] names = new String[ _cookies.size() ];
- int i = 0;
- for (Enumeration e = _cookies.keys(); e.hasMoreElements();) {
- names[i++] = (String) e.nextElement();
- }
- return names;
+ return _cookieJar.getCookieNames();
}
@@ -234,7 +232,7 @@
* Returns the value of the specified cookie.
**/
public String getCookieValue( String name ) {
- return (String) _cookies.get( name );
+ return _cookieJar.getCookieValue( name );
}
@@ -431,34 +429,22 @@
/**
- * Returns the value of the cookie header, or null if none is defined.
- **/
- protected String getCookieHeaderField() {
- String names[] = getCookieNames();
- if (names.length == 0) return null;
-
- StringBuffer sb = new StringBuffer(HttpUnitUtils.DEFAULT_BUFFER_SIZE);
- for (int i = 0; i < names.length; i++) {
- if (i != 0) sb.append( ";" );
- String name = names[i];
- sb.append( name ).append( '=' ).append( getCookieValue( name ) );
- }
- return sb.toString();
- }
-
-
- /**
* Returns the value of all current header fields.
**/
- protected Dictionary getHeaderFields() {
- setHeaderField( "User-Agent", getClientProperties().getUserAgent() );
+ protected Dictionary getHeaderFields( URL targetURL ) {
Hashtable result = (Hashtable) _headers.clone();
- if (getCookieHeaderField() != null) result.put( "Cookie", getCookieHeaderField() );
- if (_authorizationString != null) result.put( getAuthorizationHeaderName(), _authorizationString );
+ result.put( "User-Agent", getClientProperties().getUserAgent() );
+ AddHeaderIfNotNull( result, "Cookie", _cookieJar.getCookieHeaderField( targetURL ) );
+ AddHeaderIfNotNull( result, getAuthorizationHeaderName(), _authorizationString );
return result;
}
+ private void AddHeaderIfNotNull( Hashtable result, final String headerName, final String headerValue ) {
+ if (headerValue != null) result.put( headerName, headerValue );
+ }
+
+
private String getAuthorizationHeaderName() {
return getProxyHost() != null ? "Proxy-Authorization" : "Authorization";
}
@@ -475,7 +461,7 @@
void updateClient( WebResponse response ) throws IOException {
- updateCookies( response );
+ if (HttpUnitOptions.isAcceptCookies()) _cookieJar.updateCookies( response.getCookieJar() );
validateHeaders( response );
}
@@ -565,7 +551,7 @@
private LinkedList _alerts = new LinkedList();
/** The currently defined cookies. **/
- private Hashtable _cookies = new Hashtable();
+ private CookieJar _cookieJar = new CookieJar();
/** A map of header names to values. **/
@@ -596,19 +582,6 @@
throw new HttpNotFoundException( response.getResponseMessage(), response.getURL() );
} else if (response.getResponseCode() >= HttpURLConnection.HTTP_BAD_REQUEST) {
throw new HttpException( response.getResponseCode(), response.getResponseMessage(), response.getURL() );
- }
- }
-
-
- /**
- * Updates the cookies maintained in this client based on new cookies requested by the server.
- **/
- private void updateCookies( WebResponse response ) {
- if (!HttpUnitOptions.isAcceptCookies()) return;
-
- String[] names = response.getNewCookieNames();
- for (int i = 0; i < names.length; i++) {
- addCookie( names[i], response.getNewCookieValue( names[i] ) );
}
}
Index: WebConversation.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- WebConversation.java 4 Oct 2002 00:40:28 -0000 1.26
+++ WebConversation.java 17 Oct 2002 23:50:49 -0000 1.27
@@ -57,7 +57,7 @@
URLConnection connection = openConnection( request.getURL() );
sendHeaders( connection, request.getHeaderDictionary() );
if (HttpUnitOptions.isLoggingHttpHeaders()) {
- for (Enumeration e = getHeaderFields().keys(); e.hasMoreElements(); ) {
+ for (Enumeration e = getHeaderFields( request.getURL() ).keys(); e.hasMoreElements(); ) {
String key = (String) e.nextElement();
System.out.println( "Sending:: " + key + ": " + connection.getRequestProperty( key ) );
}
@@ -83,7 +83,7 @@
private void sendHeaders( URLConnection connection ) {
- sendHeaders( connection, getHeaderFields() );
+ sendHeaders( connection, getHeaderFields( connection.getURL() ) );
}
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.92
retrieving revision 1.93
diff -u -r1.92 -r1.93
--- WebResponse.java 14 Oct 2002 04:19:06 -0000 1.92
+++ WebResponse.java 17 Oct 2002 23:50:49 -0000 1.93
@@ -20,6 +20,9 @@
*
*******************************************************************************************************************/
import com.meterware.httpunit.scripting.ScriptableDelegate;
+import com.meterware.httpunit.cookies.CookieJar;
+import com.meterware.httpunit.cookies.Cookie;
+import com.meterware.httpunit.cookies.CookieSource;
import java.io.*;
import java.net.HttpURLConnection;
@@ -45,7 +48,7 @@
* @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
**/
abstract
-public class WebResponse implements HTMLSegment {
+public class WebResponse implements HTMLSegment, CookieSource {
/**
* Returns a web response built from a URL connection. Provided to allow
@@ -206,12 +209,7 @@
* Returns a list of new cookie names defined as part of this response.
**/
public String[] getNewCookieNames() {
- String[] names = new String[ getNewCookies().size() ];
- int i = 0;
- for (Enumeration e = getNewCookies().keys(); e.hasMoreElements(); i++ ) {
- names[i] = (String) e.nextElement();
- }
- return names;
+ return getCookieJar().getCookieNames();
}
@@ -219,7 +217,7 @@
* Returns the new cookie value defined as part of this response.
**/
public String getNewCookieValue( String name ) {
- return (String) getNewCookies().get( name );
+ return getCookieJar().getCookieValue( name );
}
@@ -230,7 +228,7 @@
public String[] getHeaderFieldNames();
- /**
+ /**
* Returns the value for the specified header field. If no such field is defined, will return null.
* If more than one header is defined for the specified name, returns only the first found.
**/
@@ -239,13 +237,6 @@
/**
- * Returns the values for the specified header field. If no such field is defined, will return an empty array.
- **/
- abstract
- public String[] getHeaderFields( String fieldName );
-
-
- /**
* Returns the text of the response (excluding headers) as a string. Use this method in preference to 'toString'
* which may be used to represent internal state of this object.
**/
@@ -775,26 +766,6 @@
//--------------------------------- private members --------------------------------------
- /**
- * A version flag indicating a cookie is based on the
- * Internet Engineering Task Force's (IETF)
- * <a href="http://www.ietf.org/rfc/rfc2109.txt">RFC 2109</a>
- *
- * <br />
- * These cookies come from the <code>Set-Cookie:</code> header
- **/
- final private static int IETF_RFC2109 = 0;
-
- /**
- * A version flag indicating a cookie is based on the
- * Internet Engineering Task Force's (IETF)
- * <a href="http://www.ietf.org/rfc/rfc2965.txt">RFC 2965</a>
- *
- * <br />
- * These cookies come from the <code>Set-Cookie2:</code> header
- **/
- final private static int IETF_RFC2965 = 1;
-
final private static String HTML_CONTENT = "text/html";
final private static int UNINITIALIZED_INT = -2;
@@ -813,8 +784,6 @@
private String _characterSet;
- private Hashtable _newCookies;
-
private WebRequest _refreshRequest;
private int _refreshDelay;
@@ -899,152 +868,13 @@
}
- /**
- * Parses cookies from the <code>Set-Cookie</code> and the
- * <code>Set-Cookie2</code> header fields.
- * <p>
- * This class does not strictly follow the specifications, but
- * attempts to imitate the behavior of popular browsers. Specifically,
- * this method allows cookie values to contain commas, which the
- * Netscape standard does not allow for.
- * </p><p>
- * This method does not parse path,domain,expires or secure information
- * about the cookie.</p>
- *
- * @return Hashtable a <code>Hashtable</code> of where the name of the
- * cookie is the key and the value of the cookie is
- * the value
- */
- private Hashtable getNewCookies() {
- if (_newCookies == null) _newCookies = new Hashtable();
- processCookieHeaders( getHeaderFields( "Set-Cookie" ), IETF_RFC2109 );
- processCookieHeaders( getHeaderFields( "Set-Cookie2" ), IETF_RFC2965 );
- return _newCookies;
- }
-
-
- private void processCookieHeaders( String cookieHeader[], int version ) {
- for (int i = 0; i < cookieHeader.length; i++) {
- processCookieHeader( cookieHeader[i], version );
- }
- }
-
-
- private void processCookieHeader( String cookieHeader, int version ) {
- Vector tokens = getCookieTokens( cookieHeader );
- String tokensToAdd = "";
- for (int i = tokens.size() - 1; i >= 0; i--) {
- String token = (String) tokens.elementAt( i );
-
- int equalsIndex = getEqualsIndex( token );
- if (equalsIndex != -1) {
- String name = token.substring( 0, equalsIndex ).trim();
- if (!isCookieAttribute( name, version )) {
- String value = token.substring( equalsIndex + 1 ).trim();
- _newCookies.put( name, value + tokensToAdd );
- }
- tokensToAdd = "";
- } else if (isCookieReservedWord( token, version )) {
- tokensToAdd = "";
- } else {
- tokensToAdd = token + tokensToAdd;
- if (i > 0) {
- String preceedingToken = (String) tokens.elementAt( i - 1 );
- char lastChar = preceedingToken.charAt( preceedingToken.length() - 1 );
- if (lastChar != '=') {
- tokensToAdd = "," + tokensToAdd;
- }
- }
- }
- }
- }
-
-
- /**
- * Returns the index (if any) of the equals sign separating a cookie name from the its value.
- * Equals signs at the end of the token are ignored in this calculation, since they may be
- * part of a Base64-encoded value.
- */
- private int getEqualsIndex( String token ) {
- if (!token.endsWith( "==" )) {
- return token.indexOf( '=' );
- } else {
- return getEqualsIndex( token.substring( 0, token.length()-2 ) );
- }
+ CookieJar getCookieJar() {
+ if (_cookies == null) _cookies = new CookieJar( this );
+ return _cookies;
}
- /**
- * Tokenizes a cookie header and returns the tokens in a
- * <code>Vector</code>.
- **/
- private Vector getCookieTokens(String cookieHeader) {
- StringReader sr = new StringReader(cookieHeader);
- StreamTokenizer st = new StreamTokenizer(sr);
- Vector tokens = new Vector();
-
- // clear syntax tables of the StreamTokenizer
- st.resetSyntax();
-
- // set all characters as word characters
- st.wordChars(0,Character.MAX_VALUE);
-
- // set up characters for quoting
- st.quoteChar( '"' ); //double quotes
- st.quoteChar( '\'' ); //single quotes
-
- // set up characters to separate tokens
- st.whitespaceChars(59,59); //semicolon
- st.whitespaceChars(44,44); //comma
-
- try {
- while (st.nextToken() != StreamTokenizer.TT_EOF) {
- tokens.addElement( st.sval.trim() );
- }
- }
- catch (IOException ioe) {
- // this will never happen with a StringReader
- }
- sr.close();
- return tokens;
- }
-
-
- private boolean isCookieAttribute( String string, int version ) {
- String stringLowercase = string.toLowerCase();
- if (version == IETF_RFC2109) {
- return stringLowercase.equals("path") ||
- stringLowercase.equals("domain") ||
- stringLowercase.equals("expires") ||
- stringLowercase.equals("comment") ||
- stringLowercase.equals("max-age") ||
- stringLowercase.equals("version");
- } else if (version == IETF_RFC2965) {
- return stringLowercase.equals("path") ||
- stringLowercase.equals("domain") ||
- stringLowercase.equals("comment") ||
- stringLowercase.equals("commenturl") ||
- stringLowercase.equals("max-age") ||
- stringLowercase.equals("version") ||
- stringLowercase.equals("$version") ||
- stringLowercase.equals("port");
- } else {
- return false;
- }
- }
-
-
- private boolean isCookieReservedWord( String token,
- int version ) {
- if (version == IETF_RFC2109) {
- return token.equalsIgnoreCase( "secure" );
- } else if (version == IETF_RFC2965) {
- return token.equalsIgnoreCase( "discard" ) || token.equalsIgnoreCase( "secure" );
- } else {
- return false;
- }
- }
-
+ private CookieJar _cookies;
private void readContentTypeHeader() {
String contentHeader = (_contentHeader != null) ? _contentHeader
|
|
From: Russell G. <rus...@us...> - 2002-10-17 23:51:21
|
Update of /cvsroot/httpunit/httpunit/doc
In directory usw-pr-cvs1:/tmp/cvs-serv3856/doc
Modified Files:
release_notes.txt
Log Message:
Added support for associating cookies with servers
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.194
retrieving revision 1.195
diff -u -r1.194 -r1.195
--- release_notes.txt 14 Oct 2002 18:27:42 -0000 1.194
+++ release_notes.txt 17 Oct 2002 23:50:48 -0000 1.195
@@ -10,6 +10,11 @@
Revision History:
+17-Oct-2002
+Additions:
+ 1. Cookies are now restricted by their origin server, rather than being sent on every request.
+ 2. A new package com.meterware.httpunit.cookies, now exists to support the cookie functionality.
+
14-Oct-2002
Acknowledgements:
Thanks to Stefan Renz for describing the correct way to set up proxy servers in Java 2 and later.
|
|
From: Russell G. <rus...@us...> - 2002-10-17 23:50:54
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit
In directory usw-pr-cvs1:/tmp/cvs-serv3856/src/com/meterware/servletunit
Modified Files:
InvocationContextFactory.java InvocationContextImpl.java
ServletRunner.java ServletUnitClient.java
Log Message:
Added support for associating cookies with servers
Index: InvocationContextFactory.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/InvocationContextFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- InvocationContextFactory.java 1 Aug 2002 14:58:59 -0000 1.3
+++ InvocationContextFactory.java 17 Oct 2002 23:50:49 -0000 1.4
@@ -25,19 +25,17 @@
import java.net.MalformedURLException;
import java.util.Dictionary;
-import javax.servlet.http.Cookie;
-
/**
* An interface for an object which acts as a factory of InvocationContexts
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
public interface InvocationContextFactory {
/**
* Creates and returns a new invocation context to test calling of servlet methods.
**/
- public InvocationContext newInvocation( ServletUnitClient client, WebRequest request, Cookie[] clientCookies, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException;
+ public InvocationContext newInvocation( ServletUnitClient client, WebRequest request, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException;
}
Index: InvocationContextImpl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/InvocationContextImpl.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- InvocationContextImpl.java 1 Aug 2002 14:58:59 -0000 1.7
+++ InvocationContextImpl.java 17 Oct 2002 23:50:49 -0000 1.8
@@ -19,19 +19,19 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
+import com.meterware.httpunit.HttpException;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
-import com.meterware.httpunit.Base64;
-import com.meterware.httpunit.HttpException;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
-import java.io.IOException;
import java.util.Dictionary;
+import java.util.StringTokenizer;
+import java.util.Vector;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
-
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -130,7 +130,7 @@
* Constructs a servlet invocation context for a specified servlet container,
* request, and cookie headers.
**/
- InvocationContextImpl( ServletUnitClient client, ServletRunner runner, WebRequest request, Cookie[] cookies, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException {
+ InvocationContextImpl( ServletUnitClient client, ServletRunner runner, WebRequest request, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException {
_client = client;
_application = runner.getApplication();
_requestURL = request.getURL();
@@ -138,6 +138,7 @@
_request = new ServletUnitHttpRequest( _application.getServletRequest( _requestURL ), request, runner.getContext(),
clientHeaders, messageBody );
+ Cookie[] cookies = getCookies( clientHeaders );
for (int i = 0; i < cookies.length; i++) _request.addCookie( cookies[i] );
if (_application.usesBasicAuthentication()) _request.readBasicAuthentication();
@@ -151,6 +152,9 @@
//------------------------------ private members ---------------------------------------
+ final private static Cookie[] NO_COOKIES = new Cookie[0];
+
+
private ServletUnitClient _client;
private WebApplication _application;
@@ -161,6 +165,25 @@
private Servlet _servlet;
private WebResponse _webResponse;
+
+
+ private Cookie[] getCookies( Dictionary clientHeaders ) {
+ String cookieHeader = (String) clientHeaders.get( "Cookie" );
+ if (cookieHeader == null) return NO_COOKIES;
+ Vector cookies = new Vector();
+
+ StringTokenizer st = new StringTokenizer( cookieHeader, "=;" );
+ while (st.hasMoreTokens()) {
+ String name = st.nextToken();
+ if (st.hasMoreTokens()) {
+ String value = st.nextToken();
+ cookies.addElement( new Cookie( name, value ) );
+ }
+ }
+ Cookie[] results = new Cookie[ cookies.size() ];
+ cookies.copyInto( results );
+ return results;
+ }
}
Index: ServletRunner.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletRunner.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ServletRunner.java 1 Aug 2002 14:58:59 -0000 1.18
+++ ServletRunner.java 17 Oct 2002 23:50:49 -0000 1.19
@@ -185,8 +185,8 @@
private ServletUnitContext _context;
private InvocationContextFactory _factory = new InvocationContextFactory() {
- public InvocationContext newInvocation( ServletUnitClient client, WebRequest request, Cookie[] clientCookies, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException {
- return new InvocationContextImpl( client, ServletRunner.this, request, clientCookies, clientHeaders, messageBody );
+ public InvocationContext newInvocation( ServletUnitClient client, WebRequest request, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException {
+ return new InvocationContextImpl( client, ServletRunner.this, request, clientHeaders, messageBody );
}
};
Index: ServletUnitClient.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitClient.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ServletUnitClient.java 4 Oct 2002 00:40:28 -0000 1.9
+++ ServletUnitClient.java 17 Oct 2002 23:50:50 -0000 1.10
@@ -21,20 +21,12 @@
*******************************************************************************************************************/
import com.meterware.httpunit.*;
-import java.io.IOException;
import java.io.ByteArrayOutputStream;
-
+import java.io.IOException;
import java.net.MalformedURLException;
-import java.net.URL;
-
-import java.util.StringTokenizer;
-import java.util.Vector;
-import java.util.Hashtable;
import javax.servlet.ServletException;
-import javax.servlet.http.Cookie;
-
import org.xml.sax.SAXException;
/**
@@ -72,7 +64,7 @@
public InvocationContext newInvocation( WebRequest request ) throws IOException, MalformedURLException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
writeMessageBody( request, baos );
- return _invocationContextFactory.newInvocation( this, request, getCookies(), this.getHeaderFields(), baos.toByteArray() );
+ return _invocationContextFactory.newInvocation( this, request, getHeaderFields( request.getURL() ), baos.toByteArray() );
}
@@ -111,33 +103,11 @@
private InvocationContextFactory _invocationContextFactory;
- final private static Cookie[] NO_COOKIES = new Cookie[0];
-
-
//--------------------------------- package methods ---------------------------------------
private ServletUnitClient( InvocationContextFactory factory ) {
_invocationContextFactory = factory;
- }
-
-
- private Cookie[] getCookies() {
- String cookieHeader = (String) getHeaderFields().get( "Cookie" );
- if (cookieHeader == null) return NO_COOKIES;
- Vector cookies = new Vector();
-
- StringTokenizer st = new StringTokenizer( cookieHeader, "=;" );
- while (st.hasMoreTokens()) {
- String name = st.nextToken();
- if (st.hasMoreTokens()) {
- String value = st.nextToken();
- cookies.addElement( new Cookie( name, value ) );
- }
- }
- Cookie[] results = new Cookie[ cookies.size() ];
- cookies.copyInto( results );
- return results;
}
}
|
|
From: Russell G. <rus...@us...> - 2002-10-17 23:50:54
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv3856/test/com/meterware/httpunit
Modified Files:
HttpUnitSuite.java WebClientTest.java
Log Message:
Added support for associating cookies with servers
Index: HttpUnitSuite.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitSuite.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- HttpUnitSuite.java 14 Oct 2002 04:19:06 -0000 1.23
+++ HttpUnitSuite.java 17 Oct 2002 23:50:50 -0000 1.24
@@ -20,6 +20,7 @@
*
*******************************************************************************************************************/
import com.meterware.pseudoserver.PseudoServerTest;
+import com.meterware.httpunit.cookies.CookieTest;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -59,6 +60,7 @@
result.addTest( PseudoServerTest.suite() );
result.addTest( WebClientTest.suite() );
result.addTest( MessageBodyRequestTest.suite() );
+ result.addTest( CookieTest.suite() );
if (HttpUnitOptions.getHTMLParser().getClass().getName().indexOf("Tidy") >= 0) result.addTest( JTidyPrintWriterTest.suite() );
addOptionalTestCase( result, "com.meterware.httpunit.XMLPageTest" );
addOptionalTestCase( result, "com.meterware.httpunit.FileUploadTest" );
Index: WebClientTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebClientTest.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- WebClientTest.java 10 Oct 2002 21:10:19 -0000 1.8
+++ WebClientTest.java 17 Oct 2002 23:50:51 -0000 1.9
@@ -54,6 +54,10 @@
super( name );
}
+ public void testNothing() {
+ new WebConversation(); // XXX delete me!!!
+ }
+
public void testCookies() throws Exception {
String resourceName = "something/baking";
|
|
From: Russell G. <rus...@us...> - 2002-10-17 23:50:54
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit
In directory usw-pr-cvs1:/tmp/cvs-serv3856/test/com/meterware/servletunit
Modified Files:
JUnitServletTest.java
Log Message:
Added support for associating cookies with servers
Index: JUnitServletTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/JUnitServletTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JUnitServletTest.java 1 Aug 2002 14:58:59 -0000 1.3
+++ JUnitServletTest.java 17 Oct 2002 23:50:51 -0000 1.4
@@ -19,28 +19,27 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
+import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
import com.meterware.httpunit.WebTable;
-import com.meterware.httpunit.WebRequest;
-import java.util.Properties;
-import java.util.Dictionary;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.MalformedURLException;
+import java.util.Dictionary;
+import java.util.Properties;
+import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.Cookie;
-import javax.servlet.ServletException;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
public class JUnitServletTest extends TestCase {
private ServletRunner _runner;
@@ -180,8 +179,8 @@
static class MyFactory implements InvocationContextFactory {
private static ServletRunner _runner;
- public InvocationContext newInvocation( ServletUnitClient client, WebRequest request, Cookie[] clientCookies, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException {
- return new InvocationContextImpl( client, _runner, request, clientCookies, clientHeaders, messageBody );
+ public InvocationContext newInvocation( ServletUnitClient client, WebRequest request, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException {
+ return new InvocationContextImpl( client, _runner, request, clientHeaders, messageBody );
}
}
}
|
|
From: Russell G. <rus...@us...> - 2002-10-17 23:50:52
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/cookies In directory usw-pr-cvs1:/tmp/cvs-serv3856/src/com/meterware/httpunit/cookies Added Files: Cookie.java CookieJar.java CookieSource.java Log Message: Added support for associating cookies with servers ***** Error reading new file[Errno 2] No such file or directory: 'Cookie.java' ***** Error reading new file[Errno 2] No such file or directory: 'CookieJar.java' ***** Error reading new file[Errno 2] No such file or directory: 'CookieSource.java' |
|
From: Russell G. <rus...@us...> - 2002-10-15 01:07:32
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv11484/C:/opensource/httpunit/test/com/meterware/httpunit
Modified Files:
WebFormTest.java
Log Message:
Made test only care about names, not their order
Index: WebFormTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- WebFormTest.java 2 Oct 2002 16:37:56 -0000 1.26
+++ WebFormTest.java 15 Oct 2002 01:07:29 -0000 1.27
@@ -248,7 +248,7 @@
WebForm form = page.getForms()[0];
String[] parameterNames = form.getParameterNames();
assertEquals( "Number of parameters", 2, parameterNames.length );
- assertEquals( "First parameter name", "name", parameterNames[0] );
+ assertMatchingSet( "parameter names", new String[] { "name","sex" }, parameterNames );
assertEquals( "Default name", "", form.getParameterValue( "name" ) );
assertEquals( "Default sex", "female", form.getParameterValue( "sex" ) );
WebRequest request = form.getRequest();
|
|
From: Russell G. <rus...@us...> - 2002-10-14 22:03:57
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/cookies In directory usw-pr-cvs1:/tmp/cvs-serv23114/cookies Log Message: Directory /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/cookies added to the repository |
|
From: Russell G. <rus...@us...> - 2002-10-14 18:27:54
|
Update of /cvsroot/httpunit/httpunit/doc
In directory usw-pr-cvs1:/tmp/cvs-serv618/doc
Modified Files:
release_notes.txt todo.txt
Log Message:
Use user-set default encoding for independent requests
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.193
retrieving revision 1.194
diff -u -r1.193 -r1.194
--- release_notes.txt 14 Oct 2002 12:40:04 -0000 1.193
+++ release_notes.txt 14 Oct 2002 18:27:42 -0000 1.194
@@ -17,6 +17,10 @@
1. The proxy server may now be specified by calling WebClient.setProxyServer. This should also ensure that the
correct authorization header is sent.
+Problems fixed:
+ 1. Requests created by calling the web request constructors directly, rather than being derived from an HTML page
+ were always using the Latin-1 encoding, rather than the user-specified default encoding.
+
13-Oct-2002
Notes:
1. The NekoHTML parser is now supported. If it is present in the classpath, it will be used in preference to JTidy.
Index: todo.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/todo.txt,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- todo.txt 14 Oct 2002 12:40:05 -0000 1.38
+++ todo.txt 14 Oct 2002 18:27:42 -0000 1.39
@@ -1,3 +1,6 @@
+High priority:
+o Support cookie paths
+
Medium priority:
o Support optional tags which hide their contents (as in IFRAME, OBJECT, etc.)
o Check conformance with RFC 2109 - not currently sending $Version=1 string
|
|
From: Russell G. <rus...@us...> - 2002-10-14 18:27:53
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv618/src/com/meterware/httpunit
Modified Files:
HttpUnitOptions.java UncheckedParameterHolder.java
Log Message:
Use user-set default encoding for independent requests
Index: HttpUnitOptions.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- HttpUnitOptions.java 14 Oct 2002 04:19:06 -0000 1.30
+++ HttpUnitOptions.java 14 Oct 2002 18:27:43 -0000 1.31
@@ -115,8 +115,8 @@
/**
- * Sets the default character set for pages which do not specify one. By default, HttpUnit uses the platform
- * default encoding.
+ * Sets the default character set for pages which do not specify one and for requests created without HTML sources.
+ * By default, HttpUnit uses the HTTP default encoding, iso-8859-1.
**/
public static void setDefaultCharacterSet( String characterSet ) {
_characterSet = characterSet;
Index: UncheckedParameterHolder.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/UncheckedParameterHolder.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- UncheckedParameterHolder.java 30 Aug 2002 18:19:13 -0000 1.7
+++ UncheckedParameterHolder.java 14 Oct 2002 18:27:44 -0000 1.8
@@ -30,7 +30,7 @@
/**
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
final class UncheckedParameterHolder extends ParameterHolder implements ParameterProcessor {
@@ -42,7 +42,7 @@
UncheckedParameterHolder() {
- _characterSet = "iso-8859-1";
+ _characterSet = HttpUnitOptions.getDefaultCharacterSet();
}
@@ -158,6 +158,11 @@
boolean isFileParameter( String name ) {
return true;
+ }
+
+
+ String getCharacterSet() {
+ return _characterSet;
}
|
|
From: Russell G. <rus...@us...> - 2002-10-14 18:27:53
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv618/test/com/meterware/httpunit
Modified Files:
WebPageTest.java
Log Message:
Use user-set default encoding for independent requests
Index: WebPageTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebPageTest.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- WebPageTest.java 24 Jul 2002 17:32:08 -0000 1.21
+++ WebPageTest.java 14 Oct 2002 18:27:45 -0000 1.22
@@ -40,7 +40,7 @@
/**
* Unit tests for page structure, style, and headers.
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
* @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
**/
public class WebPageTest extends HttpUnitTest {
@@ -225,6 +225,37 @@
WebResponse formPage = wc.getResponse( getHostPath() + "/HebrewForm.html" );
WebForm form = formPage.getForms()[0];
WebRequest request = form.getRequest();
+ request.setParameter( "name", hebrewName );
+
+ WebResponse answer = wc.getResponse( request );
+ String[][] cells = answer.getTables()[0].asText();
+
+ assertEquals( "Message", "Hello, " + hebrewName, cells[0][0] );
+ assertEquals( "Character set", "iso-8859-8", answer.getCharacterSet() );
+ }
+
+
+ public void testEncodedRequestWithoutForm() throws Exception {
+ String hebrewName = "\u05d0\u05d1\u05d2\u05d3";
+ defineResource( "SayHello", new PseudoServlet() {
+ public WebResource getPostResponse() {
+ try {
+ String name = getParameter( "name" )[0];
+ WebResource result = new WebResource( "<html><body><table><tr><td>Hello, " +
+ new String( name.getBytes( "iso-8859-1" ), "iso-8859-8" ) +
+ "</td></tr></table></body></html>" );
+ result.setCharacterSet( "iso-8859-8" );
+ result.setSendCharacterSet( true );
+ return result;
+ } catch (java.io.UnsupportedEncodingException e) {
+ return null;
+ }
+ }
+ } );
+
+ WebConversation wc = new WebConversation();
+ HttpUnitOptions.setDefaultCharacterSet( "iso-8859-8" );
+ WebRequest request = new PostMethodWebRequest( getHostPath() + "/SayHello" );
request.setParameter( "name", hebrewName );
WebResponse answer = wc.getResponse( request );
|
|
From: Russell G. <rus...@us...> - 2002-10-14 12:40:08
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv25444/doc Modified Files: faq.html release_notes.txt todo.txt Log Message: Added support for proxy servers Index: faq.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/faq.html,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- faq.html 2 Oct 2002 13:16:38 -0000 1.19 +++ faq.html 14 Oct 2002 12:40:04 -0000 1.20 @@ -38,8 +38,7 @@ <A NAME="org.xml.sax"><h3>What is the org.xml.sax package?</h3></A> You may be getting compile or runtime errors asking for the org.xml.sax package. -This package is found in <a href="http://www.sf.net/projects/jtidy">JTidy</a>, the HTML parser used -by HttpUnit. It is included in the download. +You need to have xerces or another XML parser in your classpath. Xerces is included in the download. <A NAME="#reload"><h3>Why do I get java.lang.IllegalAccessError when calling getResponse()?</h3></A> <p>This happens when you use HttpUnit and certain versions of JTidy with one of the JUnit graphical test runners, which reloads @@ -58,9 +57,8 @@ <h2>Server Issues</h2> <A NAME="proxy"><h3>Can I use HttpUnit through a proxy server?</h3></A> -Yes. HttpUnit uses java.net.HttpURLConnection, so the -<A HREF="http://www.javaworld.com/javaworld/javatips/jw-javatip42.html">normal Java way to use -proxies</A> will work. At some point HttpUnit may support this more directly, but for now, you will need to set the system properties yourself. +Yes. Call <code>WebClient.setProxyServer( host, port )</code> before sending your request. +This feature is available in the <a href="http://www.httpunit.org/prerelease">latest pre-release build.</a> <A NAME="charset"><h3>Why isn't HttpUnit handling my non-English pages?</h3></A> Older versions of HttpUnit (through 1.2) incorrectly assumed that all pages were in the default character set for the client platform. @@ -92,10 +90,14 @@ <A NAME="buttons"><h3>HttpUnit is not finding the buttons and parameters in my forms. What is wrong?</h3></A> This often happens when your HTML is not valid. Most browsers are extremely forgiving of bad HTML; however, -JTidy (the HTML parser used by HttpUnit) is not. It expects tags to be nested according to the HTML specification and -will reject any that are not. JTidy can display error messages to tell you what is wrong. To see them, +JTidy (the HTML parser originally used by HttpUnit) is not. It expects tags to be nested according to the HTML +specification and will reject any that are not. JTidy can display error messages to tell you what is wrong. To see them, call <code>HttpUnitOptions.setParserWarningsEnabled( true )</code> before retrieving your HTML page. Once you have corrected any errors, HttpUnit should see your form buttons and parameters. + +The <a href="http://www.httpunit.org/prerelease">latest pre-release build</a> supports +<a href="http://www.apache.org/~andyc/neko/doc/html/">NekoHTML</a>, a much more forgiving parser. +It is strongly recommended that you use it in preference to JTidy, as it should correct problems like this. <A NAME="#badPost"><h3>Why doesn't my servlet see parameters on a POST request?</h3></A> Some older servlet engines, such as Tomcat 3.1, get confused when they see a charset attribute on the Content-Type Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.192 retrieving revision 1.193 diff -u -r1.192 -r1.193 --- release_notes.txt 14 Oct 2002 04:19:05 -0000 1.192 +++ release_notes.txt 14 Oct 2002 12:40:04 -0000 1.193 @@ -10,6 +10,13 @@ Revision History: +14-Oct-2002 +Acknowledgements: + Thanks to Stefan Renz for describing the correct way to set up proxy servers in Java 2 and later. +Additions: + 1. The proxy server may now be specified by calling WebClient.setProxyServer. This should also ensure that the + correct authorization header is sent. + 13-Oct-2002 Notes: 1. The NekoHTML parser is now supported. If it is present in the classpath, it will be used in preference to JTidy. Index: todo.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/todo.txt,v retrieving revision 1.37 retrieving revision 1.38 diff -u -r1.37 -r1.38 --- todo.txt 11 Oct 2002 01:26:22 -0000 1.37 +++ todo.txt 14 Oct 2002 12:40:05 -0000 1.38 @@ -1,14 +1,10 @@ -High priority: -o better support for use with proxy server - Medium priority: -o replace JTidy with a simpler custom parser or NekoHTML o Support optional tags which hide their contents (as in IFRAME, OBJECT, etc.) o Check conformance with RFC 2109 - not currently sending $Version=1 string o Documentation, Documentation JavaScript priorities: -o Document.write - will require replacing JTidy +o Document.write - some more parser work is needed for this to work Possibles: |
|
From: Russell G. <rus...@us...> - 2002-10-14 12:40:08
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv25444/src/com/meterware/httpunit
Modified Files:
WebClient.java
Log Message:
Added support for proxy servers
Index: WebClient.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- WebClient.java 11 Oct 2002 01:26:22 -0000 1.42
+++ WebClient.java 14 Oct 2002 12:40:05 -0000 1.43
@@ -35,7 +35,7 @@
* session context, computes relative URLs, and generally emulates the browser behavior
* needed to build an automated test of a web site.
*
- * @author Russell Gold
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
* @author Jan Ohrstrom
* @author Seth Ladd
* @author Oliver Imbusch
@@ -47,6 +47,7 @@
/** The current main window. **/
private WebWindow _mainWindow = new WebWindow( this );
private ArrayList _openWindows = new ArrayList();
+ private String _authorizationString;
public WebWindow getMainWindow() {
@@ -267,11 +268,43 @@
* Sets a username and password for a basic authentication scheme.
**/
public void setAuthorization( String userName, String password ) {
- setHeaderField( "Authorization", "Basic " + Base64.encode( userName + ':' + password ) );
+ _authorizationString = "Basic " + Base64.encode( userName + ':' + password );
+ setHeaderField( "Authorization", _authorizationString );
}
/**
+ * Specifies a proxy server to use. Note that at present this is global to all web clients in the VM.
+ */
+ public void setProxyServer( String proxyHost, int proxyPort ) {
+ System.setProperty( "proxyHost", proxyHost );
+ System.setProperty( "proxyPost", Integer.toString( proxyPort ) );
+ }
+
+
+ /**
+ * Returns the name of the active proxy server.
+ */
+ public String getProxyHost() {
+ return System.getProperty( "proxyHost" );
+ }
+
+
+ /**
+ * Returns the number of the active proxy port, or 0 is none is specified.
+ */
+ public int getProxyPort() {
+ try {
+ return Integer.parseInt( System.getProperty( "proxyPort" ) );
+ } catch (NumberFormatException e) {
+ return 0;
+ }
+ }
+
+
+
+
+ /**
* Sets the value for a header field to be sent with all requests. If the value set is null,
* removes the header from those to be sent.
**/
@@ -421,7 +454,13 @@
setHeaderField( "User-Agent", getClientProperties().getUserAgent() );
Hashtable result = (Hashtable) _headers.clone();
if (getCookieHeaderField() != null) result.put( "Cookie", getCookieHeaderField() );
+ if (_authorizationString != null) result.put( getAuthorizationHeaderName(), _authorizationString );
return result;
+ }
+
+
+ private String getAuthorizationHeaderName() {
+ return getProxyHost() != null ? "Proxy-Authorization" : "Authorization";
}
|
|
From: Russell G. <rus...@us...> - 2002-10-14 04:19:09
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv10393/src/com/meterware/httpunit
Modified Files:
FormControl.java HTMLPage.java HttpUnitOptions.java
NodeUtils.java ParsedHTML.java WebLink.java WebResponse.java
Added Files:
HTMLParser.java JTidyHTMLParser.java NekoHTMLParser.java
Log Message:
Added NekoHTML support
***** Error reading new file[Errno 2] No such file or directory: 'HTMLParser.java'
***** Error reading new file[Errno 2] No such file or directory: 'JTidyHTMLParser.java'
***** Error reading new file[Errno 2] No such file or directory: 'NekoHTMLParser.java'
Index: FormControl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- FormControl.java 13 Oct 2002 23:53:48 -0000 1.28
+++ FormControl.java 14 Oct 2002 04:19:06 -0000 1.29
@@ -272,9 +272,9 @@
static FormControl newFormParameter( WebForm form, Node node ) {
if (node.getNodeType() != Node.ELEMENT_NODE) {
return null;
- } else if (node.getNodeName().equals( "textarea" )) {
+ } else if (node.getNodeName().equalsIgnoreCase( "textarea" )) {
return new TextAreaFormControl( form, node );
- } else if (node.getNodeName().equals( "select" )) {
+ } else if (node.getNodeName().equalsIgnoreCase( "select" )) {
return new SelectionFormControl( form, node );
} else if (node.getNodeName().equalsIgnoreCase( "button" )) {
final String type = NodeUtils.getNodeAttribute( node, "type", "submit" );
@@ -285,7 +285,7 @@
} else {
return new Button( form, node );
}
- } else if (!node.getNodeName().equals( "input" )) {
+ } else if (!node.getNodeName().equalsIgnoreCase( "input" )) {
return null;
} else {
final String type = NodeUtils.getNodeAttribute( node, "type", "text" );
@@ -991,8 +991,9 @@
_options = new Option[ nl.getLength() ];
for (int i = 0; i < _options.length; i++) {
- _options[i] = new Option( getValue( nl.item(i).getFirstChild() ),
- getOptionValue( nl.item(i) ),
+ final String displayedText = getValue( nl.item(i).getFirstChild() ).trim();
+ _options[i] = new Option( displayedText,
+ getOptionValue( nl.item(i), displayedText ),
nl.item(i).getAttributes().getNamedItem( "selected" ) != null );
_options[i].setIndex( this, i );
}
@@ -1136,12 +1137,12 @@
}
- private String getOptionValue( Node optionNode ) {
+ private String getOptionValue( Node optionNode, String displayedText ) {
NamedNodeMap nnm = optionNode.getAttributes();
if (nnm.getNamedItem( "value" ) != null) {
return getValue( nnm.getNamedItem( "value" ) );
} else {
- return getValue( optionNode.getFirstChild() );
+ return displayedText;
}
}
Index: HTMLPage.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLPage.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- HTMLPage.java 13 Oct 2002 23:53:48 -0000 1.12
+++ HTMLPage.java 14 Oct 2002 04:19:06 -0000 1.13
@@ -21,22 +21,18 @@
*******************************************************************************************************************/
import com.meterware.httpunit.scripting.NamedDelegate;
import com.meterware.httpunit.scripting.ScriptableDelegate;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Vector;
-import java.util.ArrayList;
-
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import org.w3c.tidy.Tidy;
import org.xml.sax.SAXException;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Vector;
+
/**
* This class represents an HTML page returned from a request.
@@ -49,7 +45,7 @@
private Scriptable _scriptable;
- public HTMLPage( WebResponse response, URL url, String parentTarget, String pageText, String characterSet ) throws SAXException {
+ HTMLPage( WebResponse response, URL url, String parentTarget, String pageText, String characterSet ) throws IOException, SAXException {
super( response, url, parentTarget, getDOM( url, pageText ), characterSet );
setBaseAttributes();
}
@@ -239,24 +235,8 @@
//---------------------------------- private members --------------------------------
- private static Node getDOM( URL url, String pageText ) throws SAXException {
- try {
- return getParser( url ).parseDOM( new ByteArrayInputStream( pageText.getBytes( getUTFEncodingName() ) ), null );
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException( "UTF-8 encoding failed" );
- }
- }
-
-
- private static String _utfEncodingName;
-
- private static String getUTFEncodingName() {
- if (_utfEncodingName == null) {
- String versionNum = System.getProperty( "java.version" );
- if (versionNum.startsWith( "1.1" )) _utfEncodingName = "UTF8";
- else _utfEncodingName = "UTF-8";
- }
- return _utfEncodingName;
+ private static Node getDOM( URL url, String pageText ) throws IOException, SAXException {
+ return HttpUnitOptions.getHTMLParser().getDocument( url, pageText );
}
@@ -281,16 +261,5 @@
}
}
-
- private static Tidy getParser( URL url ) {
- Tidy tidy = new Tidy();
- tidy.setCharEncoding( org.w3c.tidy.Configuration.UTF8 );
- tidy.setQuiet( true );
- tidy.setShowWarnings( HttpUnitOptions.getParserWarningsEnabled() );
- if (!HttpUnitOptions.getHtmlErrorListeners().isEmpty()) {
- tidy.setErrout(new JTidyPrintWriter( url ));
- }
- return tidy;
- }
}
Index: HttpUnitOptions.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- HttpUnitOptions.java 9 Oct 2002 13:50:07 -0000 1.29
+++ HttpUnitOptions.java 14 Oct 2002 04:19:06 -0000 1.30
@@ -27,7 +27,7 @@
/**
* A collection of global options to control HttpUnit's behavior.
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
* @author <a href="mailto:dg...@ss...">Dave Glowacki</a>
* @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
**/
@@ -61,6 +61,11 @@
}
+ public static HTMLParser getHTMLParser() {
+ return _htmlParser;
+ }
+
+
/**
* Returns true if HttpUnit is accepting and saving cookies. The default is to accept them.
*/
@@ -506,10 +511,30 @@
private static boolean _exceptionsThrownOnScriptError = true;
+ private static HTMLParser _htmlParser;
+ private static HTMLParser _jtidyParser;
+
+ private static HTMLParser _nekoParser;
static {
_listeners = new Vector();
reset();
+
+ try {
+ _jtidyParser = (HTMLParser) Class.forName( "com.meterware.httpunit.JTidyHTMLParser" ).newInstance();
+ } catch (InstantiationException e) {
+ } catch (IllegalAccessException e) {
+ } catch (ClassNotFoundException e) {
+ }
+
+ try {
+ _nekoParser = (HTMLParser) Class.forName( "com.meterware.httpunit.NekoHTMLParser" ).newInstance();
+ } catch (InstantiationException e) {
+ } catch (IllegalAccessException e) {
+ } catch (ClassNotFoundException e) {
+ }
+
+ _htmlParser = (_nekoParser == null) ? _jtidyParser : _nekoParser;
}
}
Index: NodeUtils.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/NodeUtils.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- NodeUtils.java 5 Aug 2002 15:21:19 -0000 1.12
+++ NodeUtils.java 14 Oct 2002 04:19:06 -0000 1.13
@@ -109,7 +109,7 @@
return true;
}
public void processTextNodeValue( String value ) {
- sb.append( convertNBSP( value ) );
+ sb.append( HttpUnitOptions.getHTMLParser().getCleanedText( value ) );
}
} );
return sb.toString();
@@ -136,15 +136,6 @@
pushNodeList( node.getChildNodes(), pendingNodes );
}
- }
-
-
- final static private char NBSP = (char) 160; // non-breaking space, defined by JTidy
-
-
- private static String convertNBSP( String text ) {
- if (text == null) return "";
- return text.replace( NBSP, ' ' );
}
Index: ParsedHTML.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- ParsedHTML.java 4 Oct 2002 02:16:00 -0000 1.30
+++ ParsedHTML.java 14 Oct 2002 04:19:06 -0000 1.31
@@ -27,7 +27,7 @@
import org.w3c.dom.*;
/**
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
* @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
**/
class ParsedHTML {
@@ -375,7 +375,7 @@
private boolean isLinkAnchor( Node node ) {
if (node.getNodeType() != Node.ELEMENT_NODE) {
return false;
- } else if (!node.getNodeName().equals( "a" ) && !node.getNodeName().equals( "area" )) {
+ } else if (!node.getNodeName().equalsIgnoreCase( "a" ) && !node.getNodeName().equalsIgnoreCase( "area" )) {
return false;
} else {
return (node.getAttributes().getNamedItem( "href" ) != null);
Index: WebLink.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- WebLink.java 13 Oct 2002 23:53:48 -0000 1.32
+++ WebLink.java 14 Oct 2002 04:19:06 -0000 1.33
@@ -66,7 +66,7 @@
* Returns the text value of this link.
**/
public String asText() {
- if (getNode().getNodeName().equals( "area" )) {
+ if (getNode().getNodeName().equalsIgnoreCase( "area" )) {
return getAttribute( "alt" );
} else if (!getNode().hasChildNodes()) {
return "";
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -r1.91 -r1.92
--- WebResponse.java 13 Oct 2002 23:53:48 -0000 1.91
+++ WebResponse.java 14 Oct 2002 04:19:06 -0000 1.92
@@ -39,7 +39,7 @@
/**
* A response to a web request from a web server.
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
* @author <a href="mailto:DRE...@or...">Drew Varner</a>
* @author <a href="mailto:dg...@ss...">Dave Glowacki</a>
* @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
@@ -1088,7 +1088,8 @@
if (!isHTML()) throw new NotHTMLException( getContentType() );
_page = new HTMLPage( this, _url, _frameName, getText(), getCharacterSet() );
} catch (IOException e) {
- throw new SAXException( e );
+ e.printStackTrace();
+ throw new RuntimeException( e.toString() );
}
}
return _page;
|
|
From: Russell G. <rus...@us...> - 2002-10-14 04:19:09
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv10393/test/com/meterware/httpunit
Modified Files:
HttpUnitSuite.java WebLinkTest.java
Log Message:
Added NekoHTML support
Index: HttpUnitSuite.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitSuite.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- HttpUnitSuite.java 4 Oct 2002 00:40:28 -0000 1.22
+++ HttpUnitSuite.java 14 Oct 2002 04:19:06 -0000 1.23
@@ -59,7 +59,7 @@
result.addTest( PseudoServerTest.suite() );
result.addTest( WebClientTest.suite() );
result.addTest( MessageBodyRequestTest.suite() );
- result.addTest( JTidyPrintWriterTest.suite() );
+ if (HttpUnitOptions.getHTMLParser().getClass().getName().indexOf("Tidy") >= 0) result.addTest( JTidyPrintWriterTest.suite() );
addOptionalTestCase( result, "com.meterware.httpunit.XMLPageTest" );
addOptionalTestCase( result, "com.meterware.httpunit.FileUploadTest" );
addOptionalTestCase( result, "com.meterware.httpunit.javascript.JavaScriptTestSuite" );
Index: WebLinkTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebLinkTest.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- WebLinkTest.java 13 Sep 2002 14:17:26 -0000 1.24
+++ WebLinkTest.java 14 Oct 2002 04:19:06 -0000 1.25
@@ -33,7 +33,7 @@
/**
* Tests for the WebLink class.
*
- * @author <a href="mailto:rus...@ac...>Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...>Russell Gold</a>
* @author <a href="mailto:bx...@bi...>Benoit Xhenseval</a>
**/
public class WebLinkTest extends HttpUnitTest {
@@ -166,7 +166,7 @@
WebResponse initialPage = wc.getResponse( getHostPath() + "/HasImage.html" );
WebLink link = initialPage.getLinks()[0];
- assertEquals( "Link text", "", link.asText() );
+ assertEquals( "Link text", "", link.asText().trim() );
initialPage.getLinkWithImageText("Blah Blah");
}
|
|
From: Russell G. <rus...@us...> - 2002-10-14 04:19:09
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript
In directory usw-pr-cvs1:/tmp/cvs-serv10393/src/com/meterware/httpunit/javascript
Modified Files:
JavaScriptEngineFactory.java
Log Message:
Added NekoHTML support
Index: JavaScriptEngineFactory.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScriptEngineFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JavaScriptEngineFactory.java 13 Sep 2002 18:34:57 -0000 1.6
+++ JavaScriptEngineFactory.java 14 Oct 2002 04:19:06 -0000 1.7
@@ -24,8 +24,9 @@
/**
+ * An implementation of the scripting engine factory which selects a Rhino-based implementation of JavaScript.
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
public class JavaScriptEngineFactory implements ScriptingEngineFactory {
|
|
From: Russell G. <rus...@us...> - 2002-10-14 04:19:08
|
Update of /cvsroot/httpunit/httpunit/jars
In directory usw-pr-cvs1:/tmp/cvs-serv10393/jars
Modified Files:
jars.txt
Added Files:
nekohtml.jar xercesImpl.jar xmlParserAPIs.jar
Removed Files:
xerces.jar
Log Message:
Added NekoHTML support
--- NEW FILE ---
PK
èòrñr
ï 8åÜóê·æè°¡%'åtÚ:éÕ³Rå£/¥ÚE/U´#<wKäÖm㬩fá[HSs¾}JB6dÅT
Ïd\Ó
y$¥H$M{âóÙ¯jª!§ú43iN ZVªëöÓäXRý_sîå#hO^ª.,RydÇÕʵ§·{¸[@¨T_B¢8r(}+oßmµ¶Ø>ç¹h&kH4ÝyìÇEÀfô[^8 ¶õäCº¹OÏRüùKKÀÚy!ÝRêUÇl%ÃÐ
HøIØ
ÏD$±EÂØ*á|I¯ù"'¶áAòM¹wÚ¹wÚ¹wRîóW¡(¶³rÛèdvNv°¼ÙÙÈâûZÂNÖÞ䬽 ܾÂ×9vÐFÆUÅñoqYÀÆc>Ô_P¶yüËó^ôø^ÂôK8Èä1HÄC8,áJ2æcLã¼ÃãNá´3LÎâ çX&ã4Í,§L¨¦×à s"K¦ø|©qr6eî³:+}có
ñjn{/ºàÞ<üQô8À½y8Ѷ5Ä{Ùú_ÂfÓ¨¸Å?àU]GÍߨõK7±2öj®ÀChÌu«X^kËWYòUÑû:êX^oËë,y]4FÔÏò[î·äþhÄpûi¬ä°)VÕFÆÛÉP®hÄ9¤w
--- NEW FILE ---
PK
--- NEW FILE ---
PK
Index: jars.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/jars/jars.txt,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- jars.txt 30 Aug 2002 21:29:36 -0000 1.5
+++ jars.txt 14 Oct 2002 04:19:05 -0000 1.6
@@ -3,9 +3,10 @@
(runtime)
junit 3.8
servlet 2.3
-xerces 1.2.3
+xerces 2.2
jtidy 04aug2000r7
rhino 1.5R3
+NekoHTML 0.6.8
(for testing HttpUnit only)
mail (javamail 1.2)
|
|
From: Russell G. <rus...@us...> - 2002-10-14 04:19:08
|
Update of /cvsroot/httpunit/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv10393
Modified Files:
build.xml
Log Message:
Added NekoHTML support
Index: build.xml
===================================================================
RCS file: /cvsroot/httpunit/httpunit/build.xml,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- build.xml 2 Oct 2002 13:12:44 -0000 1.49
+++ build.xml 14 Oct 2002 04:19:05 -0000 1.50
@@ -53,6 +53,10 @@
classpathref="base.classpath" />
<available property="rhino.present" classname="org.mozilla.javascript.Context"
classpathref="base.classpath" />
+ <available property="jtidy.present" classname="org.w3c.tidy.Tidy"
+ classpathref="base.classpath" />
+ <available property="nekoHTML.present" classname="org.cyberneko.html.parsers.DOMParser"
+ classpathref="base.classpath" />
</target>
@@ -73,6 +77,8 @@
<javac srcdir="${src.dir}" destdir="${build.classes}"
debug="${debug}" deprecation="${deprecation}" optimize="${optimize}">
<classpath refid="base.classpath" />
+ <exclude name="**/JTidyHTMLParser.java" unless="jtidy.present" />
+ <exclude name="**/NekoHTMLParser.java" unless="nekoHTML.present" />
<exclude name="**/servletunit/*" unless="jsdk.present" />
<exclude name="**/javascript/*" unless="rhino.present" />
</javac>
|
|
From: Russell G. <rus...@us...> - 2002-10-14 04:19:08
|
Update of /cvsroot/httpunit/httpunit/doc
In directory usw-pr-cvs1:/tmp/cvs-serv10393/doc
Modified Files:
release_notes.txt
Log Message:
Added NekoHTML support
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.191
retrieving revision 1.192
diff -u -r1.191 -r1.192
--- release_notes.txt 13 Oct 2002 01:09:31 -0000 1.191
+++ release_notes.txt 14 Oct 2002 04:19:05 -0000 1.192
@@ -10,6 +10,16 @@
Revision History:
+13-Oct-2002
+Notes:
+ 1. The NekoHTML parser is now supported. If it is present in the classpath, it will be used in preference to JTidy.
+ Note that NekoHTML is a much more forgiving parser than JTidy, properly handling a lot of bad HTML that JTidy
+ cannot. In addition, the Document class that NekoHTML creates is of type HTMLDocument. On the other hand,
+ the HTMLErrorListener is not currently supporting the NekoHTML parser, although such support will be added if
+ it is really needed. NekoHTML is the current preferred parser and will probably be required to support certain
+ JavaScript enhancements. Ultimately, it is possible that JTidy support will be dropped.
+ 2. The version of xerces now included in the distribution is 2.2, which is required for NekoHTML.
+
12-Oct-2002
Acknowledgements:
Thanks to Richard Harris for finding a case where the handling of JavaScript comments was not working.
|
|
From: Russell G. <rus...@us...> - 2002-10-13 23:53:51
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript
In directory usw-pr-cvs1:/tmp/cvs-serv17745/src/com/meterware/httpunit/javascript
Modified Files:
JavaScript.java
Log Message:
Refactored to permit partial evaluation of scripts
Index: JavaScript.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- JavaScript.java 11 Oct 2002 01:26:22 -0000 1.31
+++ JavaScript.java 13 Oct 2002 23:53:48 -0000 1.32
@@ -21,11 +21,7 @@
*******************************************************************************************************************/
import com.meterware.httpunit.*;
-import com.meterware.httpunit.scripting.ScriptingEngine;
-import com.meterware.httpunit.scripting.ScriptableDelegate;
-import com.meterware.httpunit.scripting.SelectionOption;
-import com.meterware.httpunit.scripting.SelectionOptions;
-import com.meterware.httpunit.scripting.NamedDelegate;
+import com.meterware.httpunit.scripting.*;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
@@ -38,7 +34,7 @@
/**
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
public class JavaScript {
@@ -170,7 +166,7 @@
void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable )
- throws JavaScriptException, NotAFunctionException, PropertyException, SAXException {
+ throws SAXException, PropertyException, JavaScriptException, NotAFunctionException {
_scriptable = scriptable;
_scriptable.setScriptEngine( this );
if (parent != null) setParentScope( parent );
@@ -250,22 +246,47 @@
}
+ public ScriptingEngine newScriptingEngine( ScriptableDelegate child ) {
+ try {
+// return (JavaScriptEngine) Context.getCurrentContext().newObject( this, getScriptableClassName( child ) );
+ return (ScriptingEngine) toScriptable( child );
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException( e.toString() );
+ }
+ }
+
+
/**
* Converts a scriptable delegate obtained from a subobject into the appropriate Rhino-compatible Scriptable.
**/
- final Scriptable toScriptable( ScriptableDelegate delegate )
- throws PropertyException, JavaScriptException, NotAFunctionException, SAXException {
+ final Scriptable toScriptable( ScriptableDelegate delegate ) {
if (delegate.getScriptEngine() instanceof Scriptable) {
return (Scriptable) delegate.getScriptEngine();
} else {
- JavaScriptEngine element = (JavaScriptEngine) Context.getCurrentContext().newObject( this, getScriptableClassName( delegate ) );
- element.initialize( this, delegate );
- return element;
+ try {
+ JavaScriptEngine element = (JavaScriptEngine) Context.getCurrentContext().newObject( this, getScriptableClassName( delegate ) );
+ element.initialize( this, delegate );
+ return element;
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new RhinoException( e );
+ }
}
}
- protected String getScriptableClassName( ScriptableDelegate delegate ) {
+ private String getScriptableClassName( ScriptableDelegate delegate ) {
+ if (delegate instanceof WebResponse.Scriptable) return "Window";
+ if (delegate instanceof HTMLPage.Scriptable) return "Document";
+ if (delegate instanceof WebForm.Scriptable) return "Form";
+ if (delegate instanceof WebLink.Scriptable) return "Link";
+ if (delegate instanceof WebImage.Scriptable) return "Image";
+ if (delegate instanceof SelectionOptions) return "Options";
+ if (delegate instanceof SelectionOption) return "Option";
+ if (delegate instanceof Input) return "Control";
+
throw new IllegalArgumentException( "Unknown ScriptableDelegate class: " + delegate.getClass() );
}
@@ -296,6 +317,9 @@
public Document jsGet_document() {
+ if (_document == null) {
+ _document = (Document) toScriptable( getDelegate().getDocument() );
+ }
return _document;
}
@@ -327,8 +351,6 @@
void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable )
throws JavaScriptException, NotAFunctionException, PropertyException, SAXException {
super.initialize( parent, scriptable );
- _document = (Document) Context.getCurrentContext().newObject( this, "Document" );
- _document.initialize( this, getDelegate().getDocument() );
_navigator = (Navigator) Context.getCurrentContext().newObject( this, "Navigator" );
_navigator.setClientProperties( getDelegate().getClientProperties() );
@@ -383,11 +405,6 @@
}
- protected String getScriptableClassName( ScriptableDelegate delegate ) {
- return (delegate instanceof WebResponse.Scriptable) ? "Window" : super.getScriptableClassName( delegate );
- }
-
-
private WebResponse.Scriptable getDelegate() {
return (WebResponse.Scriptable) _scriptable;
}
@@ -406,81 +423,62 @@
}
- void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable )
- throws JavaScriptException, NotAFunctionException, PropertyException, SAXException {
- super.initialize( parent, scriptable );
- initializeLinks();
- initializeForms();
- initializeImages();
- }
-
-
public String jsGet_title() throws SAXException {
return getDelegate().getTitle();
}
- public Scriptable jsGet_images() {
+ public Scriptable jsGet_images() throws SAXException{
+ if (_images == null) initializeImages();
return _images;
}
- public Scriptable jsGet_links() {
+ public Scriptable jsGet_links() throws SAXException {
+ if (_links == null) initializeLinks();
return _links;
}
- public Scriptable jsGet_forms() {
+ public Scriptable jsGet_forms() throws SAXException {
+ if (_forms == null) initializeForms();
return _forms;
}
- private void initializeImages() throws PropertyException, NotAFunctionException, JavaScriptException, SAXException {
+ private void initializeImages() throws SAXException {
WebImage.Scriptable scriptables[] = getDelegate().getImages();
Image[] images = new Image[ scriptables.length ];
for (int i = 0; i < images.length; i++) {
images[ i ] = (Image) toScriptable( scriptables[ i ] );
}
- _images = (ElementArray) Context.getCurrentContext().newObject( this, "ElementArray" );
+ _images = ElementArray.newElementArray( this );
_images.initialize( images );
}
- private void initializeLinks() throws PropertyException, NotAFunctionException, JavaScriptException, SAXException {
+ private void initializeLinks() throws SAXException {
WebLink.Scriptable scriptables[] = getDelegate().getLinks();
Link[] links = new Link[ scriptables.length ];
for (int i = 0; i < links.length; i++) {
links[ i ] = (Link) toScriptable( scriptables[ i ] );
}
- _links = (ElementArray) Context.getCurrentContext().newObject( this, "ElementArray" );
+ _links = ElementArray.newElementArray( this );
_links.initialize( links );
}
- private void initializeForms() throws PropertyException, NotAFunctionException, JavaScriptException, SAXException {
+ private void initializeForms() throws SAXException {
WebForm.Scriptable scriptables[] = getDelegate().getForms();
Form[] forms = new Form[ scriptables.length ];
for (int i = 0; i < forms.length; i++) {
forms[ i ] = (Form) toScriptable( scriptables[ i ] );
}
- _forms = (ElementArray) Context.getCurrentContext().newObject( this, "ElementArray" );
+ _forms = ElementArray.newElementArray( this );
_forms.initialize( forms );
}
- protected String getScriptableClassName( ScriptableDelegate delegate ) {
- if (delegate instanceof WebForm.Scriptable) {
- return "Form";
- } else if (delegate instanceof WebLink.Scriptable) {
- return "Link";
- } else if (delegate instanceof WebImage.Scriptable) {
- return "Image";
- } else {
- return super.getScriptableClassName( delegate );
- }
- }
-
-
private HTMLPage.Scriptable getDelegate() {
return (HTMLPage.Scriptable) _scriptable;
}
@@ -573,6 +571,19 @@
private JavaScriptEngine _contents[] = new HTMLElement[0];
+ static ElementArray newElementArray( Scriptable parent ) {
+ try {
+ return (ElementArray) Context.getCurrentContext().newObject( parent, "ElementArray" );
+ } catch (PropertyException e) {
+ throw new RhinoException( e );
+ } catch (NotAFunctionException e) {
+ throw new RhinoException( e );
+ } catch (JavaScriptException e) {
+ throw new RhinoException( e );
+ }
+ }
+
+
public ElementArray() {
}
@@ -660,11 +671,6 @@
}
- protected String getScriptableClassName( ScriptableDelegate delegate ) {
- return "Control";
- }
-
-
public String jsGet_action() {
return getDelegate().getAction();
}
@@ -739,10 +745,6 @@
}
- protected String getScriptableClassName( ScriptableDelegate delegate ) {
- return (delegate instanceof SelectionOptions) ? "Options" : super.getScriptableClassName( delegate );
- }
-
}
@@ -779,9 +781,6 @@
}
- protected String getScriptableClassName( ScriptableDelegate delegate ) {
- return "Option";
- }
}
@@ -843,4 +842,20 @@
}
}
+}
+
+
+class RhinoException extends RuntimeException {
+
+ private Exception _cause;
+
+
+ public RhinoException( Exception cause ) {
+ _cause = cause;
+ }
+
+
+ public String getMessage() {
+ return "Rhino exception: " + _cause;
+ }
}
|