[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit HttpWebResponse.java,1.17,1.18 WebClient.
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-02-11 14:33:57
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv330/src/com/meterware/httpunit
Modified Files:
HttpWebResponse.java WebClient.java WebConversation.java
WebResponse.java
Log Message:
Moved control of exceptionsThrownOnErrorStatus into WebClient
Index: HttpWebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- HttpWebResponse.java 28 Jan 2002 18:43:25 -0000 1.17
+++ HttpWebResponse.java 11 Feb 2002 14:33:53 -0000 1.18
@@ -47,12 +47,12 @@
* @param url the url from which the response was received
* @param connection the URL connection from which the response can be read
**/
- HttpWebResponse( String target, URL url, URLConnection connection ) throws IOException {
+ HttpWebResponse( String target, URL url, URLConnection connection, boolean throwExceptionOnError ) throws IOException {
super( target, url );
readHeaders( connection );
/** make sure that any IO exception for HTML received page happens here, not later. **/
- if (_responseCode < HttpURLConnection.HTTP_BAD_REQUEST || !HttpUnitOptions.getExceptionsThrownOnErrorStatus()) {
+ if (_responseCode < HttpURLConnection.HTTP_BAD_REQUEST || !throwExceptionOnError) {
defineRawInputStream( new BufferedInputStream( connection.getInputStream() ) );
if (getContentType().startsWith( "text" )) loadResponseText();
}
Index: WebClient.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- WebClient.java 11 Feb 2002 13:54:28 -0000 1.18
+++ WebClient.java 11 Feb 2002 14:33:53 -0000 1.19
@@ -45,7 +45,6 @@
abstract
public class WebClient {
-
/**
* Submits a GET method request and returns a response.
* @exception SAXException thrown if there is an error parsing the retrieved page
@@ -164,6 +163,23 @@
}
+ /**
+ * Specifies whether an exception will be thrown when an error status (4xx or 5xx) is detected on a response.
+ * Defaults to the value returned by HttpUnitOptions.getExceptionsThrownOnErrorStatus.
+ **/
+ public void setExceptionsThrownOnErrorStatus( boolean throwExceptions ) {
+ _exceptionsThrownOnErrorStatus = throwExceptions;
+ }
+
+
+ /**
+ * Returns true if an exception will be thrown when an error status (4xx or 5xx) is detected on a response.
+ **/
+ public boolean getExceptionsThrownOnErrorStatus() {
+ return _exceptionsThrownOnErrorStatus;
+ }
+
+
//------------------------------------------ protected members -----------------------------------
@@ -254,6 +270,8 @@
/** A map of header names to values. **/
private HeaderDictionary _headers = new HeaderDictionary();
+ private boolean _exceptionsThrownOnErrorStatus = HttpUnitOptions.getExceptionsThrownOnErrorStatus();
+
/**
* Examines the headers in the response and throws an exception if appropriate.
@@ -261,7 +279,7 @@
private void validateHeaders( WebResponse response ) throws HttpException, IOException {
if (response.getHeaderField( "WWW-Authenticate" ) != null) {
throw new AuthorizationRequiredException( response.getHeaderField( "WWW-Authenticate" ) );
- } else if (HttpUnitOptions.getExceptionsThrownOnErrorStatus()) {
+ } else if (getExceptionsThrownOnErrorStatus()) {
if (response.getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR) {
throw new HttpInternalErrorException( response.getURL() );
} else if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
Index: WebConversation.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- WebConversation.java 26 Nov 2001 14:20:12 -0000 1.23
+++ WebConversation.java 11 Feb 2002 14:33:53 -0000 1.24
@@ -63,7 +63,7 @@
}
}
request.completeRequest( connection );
- return new HttpWebResponse( request.getTarget(), request.getURL(), connection );
+ return new HttpWebResponse( request.getTarget(), request.getURL(), connection, getExceptionsThrownOnErrorStatus() );
}
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -r1.60 -r1.61
--- WebResponse.java 11 Feb 2002 13:54:28 -0000 1.60
+++ WebResponse.java 11 Feb 2002 14:33:53 -0000 1.61
@@ -64,7 +64,7 @@
* access to WebResponse parsing without using a WebClient.
**/
public static WebResponse newResponse( URLConnection connection ) throws IOException {
- return new HttpWebResponse( "_top", connection.getURL(), connection );
+ return new HttpWebResponse( "_top", connection.getURL(), connection, HttpUnitOptions.getExceptionsThrownOnErrorStatus() );
}
|