Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.psibt.framework.net
Class PluggableHTTPServer  view PluggableHTTPServer download PluggableHTTPServer.java

java.lang.Object
  extended bycom.psibt.framework.net.PluggableHTTPServer
All Implemented Interfaces:
java.lang.Runnable

public class PluggableHTTPServer
extends java.lang.Object
implements java.lang.Runnable

This class implements a HTTP-server frame. All HTTP-requests are handled by HTTPRequestHandler classes which implement the HTTPRequestHandler interface. Every RequestHandler has to be registered in the PluggableHTTPServer with the addRequestHandler method. A new thread is created for each connection to handle the request. If all reply data are sent to the client the connection is closed and the thread ends. An example how to use the PluggableHTTPServer class can be found in the main method at the end of the source file.


Nested Class Summary
(package private)  class PluggableHTTPServer.ServerThread
          This class handles the incomming connection for one request.
 
Field Summary
(package private) static org.apache.log4j.Category cat
           
static int DEFAULT_PORT
           
private  java.util.Vector handler
           
private  int port
           
private  java.net.ServerSocket server
           
 
Constructor Summary
PluggableHTTPServer()
          Creates a new server object on the default TCP port 80 If the port is occupied by another process a IOException (java.net.BindException) is thrown.
PluggableHTTPServer(int port)
          Creates a new server object on the given TCP port.
 
Method Summary
 void addRequestHandler(HTTPRequestHandler h)
          Registers the given HTTPRequestHandler
 void autoCreateRootPage(int index)
          Creates the ReplyHTML data for the root page
static void main(java.lang.String[] args)
          Demo how to use the PluggableHTTPServer.
 void removeRequestHandler(HTTPRequestHandler h)
          Unregisters the given HTTPRequestHandler
static void replyMethodNotAllowed(java.io.Writer out)
          Sends the HTTP message 405 - Method Not Allowed see RFC2616 for details
static void replyNotFound(java.io.Writer out)
          Sends the HTTP message 404 - File Not Found see RFC2616 for details
 void run()
          Main loop of the PluggableHTTPServer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static final int DEFAULT_PORT
See Also:
Constant Field Values

cat

static org.apache.log4j.Category cat

port

private int port

handler

private java.util.Vector handler

server

private java.net.ServerSocket server
Constructor Detail

PluggableHTTPServer

public PluggableHTTPServer(int port)
                    throws java.io.IOException
Creates a new server object on the given TCP port. If the port is occupied by another process a IOException (java.net.BindException) is thrown.


PluggableHTTPServer

public PluggableHTTPServer()
                    throws java.io.IOException
Creates a new server object on the default TCP port 80 If the port is occupied by another process a IOException (java.net.BindException) is thrown.

Method Detail

addRequestHandler

public void addRequestHandler(HTTPRequestHandler h)
Registers the given HTTPRequestHandler


removeRequestHandler

public void removeRequestHandler(HTTPRequestHandler h)
Unregisters the given HTTPRequestHandler


replyNotFound

public static void replyNotFound(java.io.Writer out)
Sends the HTTP message 404 - File Not Found see RFC2616 for details


replyMethodNotAllowed

public static void replyMethodNotAllowed(java.io.Writer out)
Sends the HTTP message 405 - Method Not Allowed see RFC2616 for details


autoCreateRootPage

public void autoCreateRootPage(int index)
Creates the ReplyHTML data for the root page


run

public void run()
Main loop of the PluggableHTTPServer

Specified by:
run in interface java.lang.Runnable

main

public static void main(java.lang.String[] args)
Demo how to use the PluggableHTTPServer.