appli.http
Class HttpServer

java.lang.Object
  extended byappli.http.HttpServer
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
HttpFileServer

public abstract class HttpServer
extends java.lang.Object
implements java.lang.Runnable

HttpServer is an abstract class that provides the basic functionality of a mini-webserver, specialized to load files only. This HttpServer must be extended and the concrete subclass should define the getBytes method which is responsible for retrieving the bytecodes for a class.

The HttpServer creates a thread that listens on a socket and accepts HTTP GET requests. The HTTP response contains the bytecodes for the class that requested in the GET header.

For loading remote classes, an RMI application can use a concrete subclass of this server in place of an HTTP server.

This server was originally only a java .class server and was called ClassServer

Version:
1.1 Jan 2003 (SJ) Modification to read any file, not only .class, 1.2 Mar 2003 (MW) getPath returns the actual path. Class rename HttpServer
Author:
Sun Microsystems (see Copyright), Sylvaine Jaehn/stage UTBM - allow any file, Marc Wenger/CDS - return the actual path
See Also:
HttpFileServer

Field Summary
private  int port
           
private  java.net.ServerSocket server
           
 
Constructor Summary
protected HttpServer(int port)
          Constructs a ClassServer that listens on port and obtains any file using the method getBytes.
 
Method Summary
abstract  byte[] getBytes(java.lang.String path)
          Returns an array of bytes containing the file represented by the argument path.
private static java.lang.String getPath(java.io.BufferedReader in)
          Returns the path to the class file obtained from parsing the HTML header.
private  void newListener()
          Create a new thread to listen.
 void run()
          The "listen" thread that accepts a connection to the server, parses the header to obtain the [class] file name and sends back the content of the file (or error if the class is not found or the response was malformed).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

server

private java.net.ServerSocket server

port

private int port
Constructor Detail

HttpServer

protected HttpServer(int port)
              throws java.io.IOException
Constructs a ClassServer that listens on port and obtains any file using the method getBytes.

Parameters:
port - the port number
Throws:
java.io.IOException - if the ClassServer could not listen on port.
Method Detail

getBytes

public abstract byte[] getBytes(java.lang.String path)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
Returns an array of bytes containing the file represented by the argument path. The path is a dot separated class name with the ".class" extension removed.

Parameters:
path - the file path
Returns:
the content of the file
Throws:
java.lang.ClassNotFoundException - if the class corresponding to path could not be loaded.
java.io.IOException - if error occurs reading the class

run

public void run()
The "listen" thread that accepts a connection to the server, parses the header to obtain the [class] file name and sends back the content of the file (or error if the class is not found or the response was malformed).

Specified by:
run in interface java.lang.Runnable

newListener

private void newListener()
Create a new thread to listen.


getPath

private static java.lang.String getPath(java.io.BufferedReader in)
                                 throws java.io.IOException
Returns the path to the class file obtained from parsing the HTML header.

Parameters:
in - input reader
Returns:
path of the requested object
Throws:
java.io.IOException - if reading fails