[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit HttpWebResponse.java,1.26,1.27 HttpServer
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-10-22 15:12:57
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv28743/src/com/meterware/httpunit
Modified Files:
HttpWebResponse.java
Removed Files:
HttpServerNotFoundException.java
Log Message:
Use UnknownHostException instead of HttpServerNotFoundException
Index: HttpWebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- HttpWebResponse.java 5 Sep 2002 19:29:55 -0000 1.26
+++ HttpWebResponse.java 22 Oct 2002 15:12:54 -0000 1.27
@@ -19,7 +19,6 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
-
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -27,6 +26,7 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
+import java.net.UnknownHostException;
import java.util.Enumeration;
import java.util.Hashtable;
@@ -37,7 +37,7 @@
/**
* A response from a web server to an Http request.
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
class HttpWebResponse extends WebResponse {
@@ -122,7 +122,6 @@
//------------------------------------- private members -------------------------------------
- private final static String END_OF_LINE = System.getProperty( "line.separator" );
private final static String FILE_ENCODING = System.getProperty( "file.encoding" );
@@ -132,21 +131,32 @@
private Hashtable _headers = new Hashtable();
- private void readResponseHeader( URLConnection connection ) {
- if (connection.getHeaderField(0) == null) throw new HttpServerNotFoundException( connection.getURL() );
- StringTokenizer st = new StringTokenizer( connection.getHeaderField(0) );
- st.nextToken();
- if (!st.hasMoreTokens()) {
- _responseCode = HttpURLConnection.HTTP_OK;
- _responseMessage = "OK";
- } else try {
- _responseCode = Integer.parseInt( st.nextToken() );
- _responseMessage = getRemainingTokens( st );
- } catch (NumberFormatException e) {
- _responseCode = HttpURLConnection.HTTP_INTERNAL_ERROR;
- _responseMessage = "Cannot parse response header";
- }
+ private void readResponseHeader( HttpURLConnection connection ) throws IOException {
+ if (needStatusWorkaround()) {
+ _responseCode = connection.getResponseCode();
+ _responseMessage = connection.getResponseMessage();
+ } else {
+ if (connection.getHeaderField(0) == null) throw new UnknownHostException( connection.getURL().toExternalForm() );
+
+ StringTokenizer st = new StringTokenizer( connection.getHeaderField(0) );
+ st.nextToken();
+ if (!st.hasMoreTokens()) {
+ _responseCode = HttpURLConnection.HTTP_OK;
+ _responseMessage = "OK";
+ } else try {
+ _responseCode = Integer.parseInt( st.nextToken() );
+ _responseMessage = getRemainingTokens( st );
+ } catch (NumberFormatException e) {
+ _responseCode = HttpURLConnection.HTTP_INTERNAL_ERROR;
+ _responseMessage = "Cannot parse response header";
+ }
+ }
+ }
+
+ private boolean needStatusWorkaround() {
+ final String jdkVersion = System.getProperty( "java.version" );
+ return jdkVersion.startsWith( "1.2" ) || jdkVersion.startsWith( "1.3" );
}
@@ -159,10 +169,10 @@
}
- private void readHeaders( URLConnection connection ) {
+ private void readHeaders( URLConnection connection ) throws IOException {
loadHeaders( connection );
if (connection instanceof HttpURLConnection) {
- readResponseHeader( connection );
+ readResponseHeader( (HttpURLConnection) connection );
} else {
_responseCode = HttpURLConnection.HTTP_OK;
_responseMessage = "OK";
|