Wolfgang,

Attached is a small program to test things out with sample output from
Kaffe and Blackdown java.

I've added a test-case for another small bug with the .getHeaderFieldKey()
method; it's throwing exceptions that it shouldn't.

best,
rhw



 On Fri, 8 Jul 2005, Wolfgang Baer wrote:

> Hi Robert,
>
> thanks for your bug report - can you write a small testcase so I can
> test it against the kaffe cvs version if it is maybe already solved.
>
> There was a lot of bug fixes on the URL/HTTP stuff the last weeks in
> gnu classpath.
>
> If not I will forward the bug report upstream.
>
> Thanks,
>
> Wolfgang
>
/***
  * HTTPBugDemo.java
  * @author [EMAIL PROTECTED]
  * @author Robert H. Warren
  * With thanks to [EMAIL PROTECTED]
  *
  * Problem: java.net.HttpURLConnection (or
  * gnu.java.net.protocol.http.HTTPURLConnection) is not handling gzip'ed
  * connections properly and reporting the gzipped content length all the
  * way to the InputStream. This is a problem because HttpURLConnection is
  * decompressing the stream along the way but still using the compressed
  * length to drive the read() and available() methods. The resulting data
  * is therefore truncated about halfway.
  *
  * Minor Problem: Method getHeaderFieldKey(int n) is throwing
  * java.util.NoSuchElementException when an invalid header number is
  * requested. According to the API, it should return a null instead.
  *
  *   ----- Sample code and output follows -----
  *
  * For reference:
  *
  * [EMAIL PROTECTED]:~$ lynx -source http://www.gutenberg.org/etext/11751 | wc 
-c
  * 9122
  *
  * With kaffe:
  *  
  * [EMAIL PROTECTED]:~$ kaffe -version
  * Kaffe Virtual Machine
  * 
  * Copyright (c) 1996-2004 Kaffe.org project contributors (please see the
  * source code for a full list of contributors).  All rights reserved. Portions
  * Copyright (c) 1996-2002 Transvirtual Technologies, Inc.
  * 
  * The Kaffe virtual machine is free software, licensed under the terms of
  * the GNU General Public License.  Kaffe.org is a an independent, free 
software
  * community project, not directly affiliated with Transvirtual Technologies,
  * Inc.  Kaffe is a Trademark of Transvirtual Technologies, Inc.  Kaffe comes
  * with ABSOLUTELY NO WARRANTY.
  * 
  * Engine: Just-in-time v3   Version: 1.1.5   Java Version: 1.1
  *
  *
  *
  *
  * [EMAIL PROTECTED]:~$ kaffe HTTPBugDemo
  * Response code is 200
  * Content type (classfile)    :text/html; charset=UTF-8
  * Content encoding (classfile): gzip
  * Content length (classfile)  : 3006
  * Key [Date] value [Tue, 12 Jul 2005 20:10:45 GMT]
  * Key [Server] value [Apache/1.3.33 (Unix) PHP/4.3.11]
  * Key [Cache-Control] value [max-age=90000]
  * Key [Expires] value [Wed, 13 Jul 2005 21:10:45 GMT]
  * Key [X-Powered-By] value [PHP/4.3.11]
  * Key [Content-Encoding] value [gzip]
  * Key [Vary] value [Accept-Encoding]
  * Key [Content-Length] value [3006]
  * Key [Connection] value [close]
  * Key [Content-Type] value [text/html; charset=UTF-8]
  * java.util.NoSuchElementException
  *    at java.util.LinkedHashMap$1.next (LinkedHashMap.java:475)
  *    at gnu.java.net.protocol.http.HTTPURLConnection.
  * getHeaderFieldKey (HTTPURLConnection.java:547)
  *    at HTTPBugDemo.main (HTTPBugDemo.java:34)
  * Data has 3006 bytes.
  *
  *
  * Using the blackdown java:
  *
  * [EMAIL PROTECTED]:~$ java -version
  * java version "1.4.2-02"
  * Java(TM) 2 Runtime Environment, Standard Edition (build Blackdown-1.4.2-02)
  * Java HotSpot(TM) Client VM (build Blackdown-1.4.2-02, mixed mode)
  *
  *
  * [EMAIL PROTECTED]:~$ java HTTPBugDemo
  * Response code is 200
  * Content type (classfile)    :text/html; charset=UTF-8
  * Content encoding (classfile): null
  * Content length (classfile)  : 9122
  * Key [Date] value [Tue, 12 Jul 2005 20:13:30 GMT]
  * Key [Server] value [Apache/1.3.33 (Unix) PHP/4.3.11]
  * Key [Cache-Control] value [max-age=90000]
  * Key [Expires] value [Wed, 13 Jul 2005 21:13:30 GMT]
  * Key [X-Powered-By] value [PHP/4.3.11]
  * Key [Vary] value [Accept-Encoding]
  * Key [Content-Length] value [9122]
  * Key [Connection] value [close]
  * Key [Content-Type] value [text/html; charset=UTF-8]
  * Data has 9122 bytes.
  * 
  * 
  * 
  *
  *
  *
  *
 ***/
public class HTTPBugDemo {
 public static void main(String argv[])  throws java.lang.Exception {
  java.net.URL URL_TEXT = new 
java.net.URL("http://www.gutenberg.org/etext/11751";);
  byte[] StoredHTMLData = null;
  byte[] CurrentHTMLData = null;
  java.net.HttpURLConnection WebServerInfo  = null;
  java.io.InputStream WebServerData = null;
  WebServerInfo = (java.net.HttpURLConnection) URL_TEXT.openConnection();
  WebServerInfo.setRequestProperty("Connection", "close");        
  WebServerInfo.setFollowRedirects(true);
  int response_code = WebServerInfo.getResponseCode();
  System.err.println("Response code is "  + response_code);
  if (response_code==404) {
   throw (new java.lang.Exception("Page Missing."));
  }                  
  WebServerData = WebServerInfo.getInputStream();
  int TotalBytesRead =0;
  CurrentHTMLData = new byte[0];
  int BytesToRead = WebServerData.available();
  System.err.println("Content type (classfile)    
:"+WebServerInfo.getContentType());
  System.err.println("Content encoding (classfile): 
"+WebServerInfo.getContentEncoding());
  System.err.println("Content length (classfile)  : 
"+WebServerInfo.getContentLength());
  String HeaderName = new String();
  int HeaderNumber=1;
  while (HeaderName != null) {
   try {  
    HeaderName = WebServerInfo.getHeaderFieldKey(HeaderNumber);
   } catch (java.lang.Exception hn) {
    HeaderName = null;
    hn.printStackTrace();
   }
   if (HeaderName != null) {
    String HeaderValue = WebServerInfo.getHeaderField(HeaderName);
    System.err.println("Key ["+HeaderName+"] value ["+HeaderValue+"]");   
    HeaderNumber++;
   }//if
  }//while
  byte[] ReadBuffer = null;
  int BlockSize = 4096;
  while (BytesToRead>=0) {
   BytesToRead = BlockSize;
   ReadBuffer = new byte[BlockSize];
   BytesToRead = WebServerData.read(ReadBuffer);
   if (BytesToRead>=0) {
    TotalBytesRead = TotalBytesRead + BytesToRead;
    byte[] TempBuffer = new byte[CurrentHTMLData.length+BytesToRead];
    
java.lang.System.arraycopy(CurrentHTMLData,0,TempBuffer,0,CurrentHTMLData.length);
    
java.lang.System.arraycopy(ReadBuffer,0,TempBuffer,(CurrentHTMLData.length),BytesToRead);
    CurrentHTMLData=TempBuffer;
   }
  }//while
  WebServerData.close();
  WebServerInfo.disconnect();
  System.out.println("Data has "+CurrentHTMLData.length+" bytes.");
 }//main
}//class

Reply via email to