java.net.URL working on Kaffe?

Stephen Crane kaffe at rufus.w3.org
Sat Jan 30 18:11:05 PST 1999


On Wed, Jan 13, 1999 at 12:46:03PM -0500, Daniel Veillard wrote:
> 
>   Alternatively, you can probably use W3C implementation present in
> Jigsaw, I used it in Amaya-Java, and was working fine once the simple
> problems were worked out. Jigsaw provides both client and server sides
> of the HTTP/1.1 implementation.
> 
>   http://www.w3.org/Jigsaw/

OK, I've made this work with Kaffe.  It requires some hackery though.
Get Jigsaw from the above URL.  Apply the following patches in the
directory www/protocol/http:

*** HttpURLConnection.java.orig	Sun Jan 17 02:11:30 1999
--- HttpURLConnection.java	Sun Jan 17 02:11:46 1999
***************
*** 243,249 ****
  	    request.setContentType(MimeType.APPLICATION_X_WWW_FORM_URLENCODED);
      }
  
!     HttpURLConnection(URL u) {
  	super(u) ;
      }
      
--- 243,249 ----
  	    request.setContentType(MimeType.APPLICATION_X_WWW_FORM_URLENCODED);
      }
  
!     public HttpURLConnection(URL u) {
  	super(u) ;
      }
      
*** HttpBasicConnection.java.orig	Sun Jan 31 01:43:28 1999
--- HttpBasicConnection.java	Sun Jan 31 01:43:19 1999
***************
*** 160,166 ****
  	if ( socket == null ) {
  	    try {
  		socket = new Socket(inetaddr, port);
! 		socket.setSoTimeout(timeout);
  		output = new BufferedOutputStream(socket.getOutputStream());
  		input  = new BufferedInputStream(socket.getInputStream());
  		parser = new MimeParser(input, reply_factory);
--- 160,166 ----
  	if ( socket == null ) {
  	    try {
  		socket = new Socket(inetaddr, port);
! //		socket.setSoTimeout(timeout);
  		output = new BufferedOutputStream(socket.getOutputStream());
  		input  = new BufferedInputStream(socket.getInputStream());
  		parser = new MimeParser(input, reply_factory);

(The first modification is to allow HttpURLConnection to be instantiated 
from outside the org.w3c package hierarchy and the second works around
the unimplemented (as of 1.0b3) socket timeout feature in Kaffe.)

The following is a very rough first-cut at HttpURLConnection.java (which
strictly belongs in libraries/javalib/java/net).  Compile it and put the
location of the compiled class in your classpath.  (Lots of functionality
is missing from this class but I have used it to fetch simple http URLs.
YMMV.)

/* HttpURLConnection.java
 */
package java.net;

import java.io.IOException;

public abstract class HttpURLConnection extends URLConnection {

private static boolean followRedirects = false;	// shd be system-configurable?

protected HttpURLConnection(URL u) {
	super (u);
	method = new String("GET");
}

public static final int HTTP_OK = 200;
public static final int HTTP_CREATED = 201;
public static final int HTTP_ACCEPTED = 202;
public static final int HTTP_NOT_AUTHORITATIVE = 203;
public static final int HTTP_NO_CONTENT = 204;
public static final int HTTP_MULT_CHOICE = 300;
public static final int HTTP_MOVED_PERM = 301;
public static final int HTTP_MOVED_TEMP = 302;
public static final int HTTP_NOT_MODIFIED = 304;
public static final int HTTP_BAD_REQUEST = 400;
public static final int HTTP_PROXY_AUTH = 401;		// FIXME: check this
public static final int HTTP_PAYMENT_REQUIRED = 402;
public static final int HTTP_FORBIDDEN = 403;
public static final int HTTP_NOT_FOUND = 404;
public static final int HTTP_BAD_METHOD = 405;		// FIXME: check this
public static final int HTTP_CLIENT_TIMEOUT = 408;
public static final int HTTP_CONFLICT = 409;
public static final int HTTP_GONE = 410;
public static final int HTTP_SERVER_ERROR = 500;
public static final int HTTP_UNSUPPORTED_TYPE = 501;
public static final int HTTP_UNAVAILABLE = 502;
public static final int HTTP_GATEWAY_TIMEOUT = 503;
public static final int HTTP_BAD_GATEWAY = 0;		// FIXME: find this
public static final int HTTP_ENTITY_TOO_LARGE = 0;	// FIXME: find this
public static final int HTTP_INTERNAL_ERROR = 0;	// FIXME: find this
public static final int HTTP_LENGTH_REQUIRED = 0;	// FIXME: find this
public static final int HTTP_NOT_ACCEPTABLE = 0;	// FIXME: find this
public static final int HTTP_PARTIAL = 0;		// FIXME: find this
public static final int HTTP_PRECON_FAILED = 0;		// FIXME: find this
public static final int HTTP_REQ_TOO_LONG = 0;		// FIXME: find this
public static final int HTTP_RESET = 0;			// FIXME: find this
public static final int HTTP_SEE_OTHER = 0;		// FIXME: find this
public static final int HTTP_UNAUTHORIZED = 0;		// FIXME: find this
public static final int HTTP_USE_PROXY = 0;		// FIXME: find this
public static final int HTTP_VERSION = 0;		// FIXME: find this

protected String method;
protected int responseCode;
protected String responseMessage;

public static boolean getFollowRedirects () {
	return followRedirects;
}

public static void setFollowRedirects (boolean followRedirects) {
	HttpURLConnection.followRedirects = followRedirects;
}

public abstract void disconnect ();

public String getRequestMethod () {
	return method;
}

public int getResponseCode () throws IOException {
	return responseCode;
}

public String getResponseMessage () throws IOException {
	return responseMessage;
}

public void setRequestMessage (String message) throws ProtocolException {
}

public abstract boolean usingProxy ();

}
/* END OF HttpURLConnection.java */

Finally, you need a Kaffe handler class for the http protocol.  This is
one which instantiates the w3c.org implementation.  Build it and put
the location of the compiled class in your classpath.

/*
 * Java core library component.
 *
 * Copyright (c) 1998
 *      Transvirtual Technologies, Inc.  All rights reserved.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file.
 *
 * Note: this is merely a hook into the W3C's http implementation. To
 * use this class, you must obtain a copy of that implementation, from,
 * e.g., Jigsaw: http://www.w3c.org/pub/WWW/Jigsaw/
 */

package kaffe.net.www.protocol.http;

import java.net.URLStreamHandler;
import java.net.URLConnection;
import java.net.URL;

public class Handler extends URLStreamHandler {

protected URLConnection openConnection (URL u)
{
	return new org.w3c.www.protocol.http.HttpURLConnection(u);
}

}
/* END OF Handler.java */

Then build everything under src/classes/org/w3c/{util, www}.

Of these classes, only HttpURLConnection.java can be integrated into
the core as things stand (Handler.java will cause the build of javalib
to fail unless the Jigsaw classes have already been compiled, and they
won't without HttpURLConnection.class present) unless of course someone 
at W3C wants to contribute the Jigsaw code... Daniel?

If this were the case, I would be willing to undertake this integration.
It shouldn't take too long but would greatly increase the size of the
distribution.  Perhaps it is a good candidate for inclusion in the
proposed kaffe-contrib thingy?

Later,
Steve
-- 
Stephen Crane, insomniac programmer, at home.


More information about the kaffe mailing list