webcore.webserver
Class WebServer

java.lang.Object
  |
  +--webcore.webserver.WebServer
All Implemented Interfaces:
java.lang.Runnable

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

WebServer listens on a port for HTTP requests and processes them.

The WebServer uses an instance of WebServerSocketFactoryInterface to create listening Sockets. The default factory creates instances of java.net.ServerSocket.

The WebServer uses an instance of WebRequestableFactoryInterface to to process HTTP requests.


Constructor Summary
WebServer()
           
 
Method Summary
 void addWebServerListener(WebServerListener l)
          adds a listener to this WebServer
 java.lang.String getDocumentBase()
          Gets the document base.
 int getPort()
          returns the port being used
 WebServerSocketFactoryInterface getSocketFactory()
          returns the current socket factory.
 WebRequestableFactoryInterface getWebRequestableFactory()
          returns the current web requestable factory.
 boolean isTerminated()
          determines if the webserver has been terminated
 void removeWebServerListener(WebServerListener l)
          removes a listener from this WebServer
 void run()
          called by runThread to start the listening process.
 void setDocumentBase(java.lang.String documentBase)
          Sets the document base.
 void setPort(int p)
          Sets the port the webserver will listen on.
 void setSocketFactory(WebServerSocketFactoryInterface factory)
          The factory is used to create listening sockets for the server.
 void setWebRequestableFactory(WebRequestableFactoryInterface factory)
          sets the web requestable factory.
 void start()
          Starts the webserver with the listening Thread being set as not daemon.
 void start(boolean daemon)
          Start the webserver.
 void terminate()
          terminates the webserver, the compliment to start()
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebServer

public WebServer()
Method Detail

start

public void start()
           throws java.io.IOException
Starts the webserver with the listening Thread being set as not daemon. The webserver will continue to listen until terminate() is called.

java.io.IOException

start

public void start(boolean daemon)
           throws java.io.IOException
Start the webserver. The webserver will continue to listen until terminate() is called.

Parameters:
daemon - determine if the listening thread should be set as a daemon thread or not
java.io.IOException

getPort

public int getPort()
returns the port being used


setPort

public void setPort(int p)
Sets the port the webserver will listen on. The default HTTP port is 80. The port must be set before the WebServer is started or it will have no affect.


isTerminated

public boolean isTerminated()
determines if the webserver has been terminated


terminate

public void terminate()
               throws java.io.IOException
terminates the webserver, the compliment to start()

java.io.IOException

getWebRequestableFactory

public WebRequestableFactoryInterface getWebRequestableFactory()
returns the current web requestable factory. This factory is used to create WebRequestables to handle the HTTP requests.


setWebRequestableFactory

public void setWebRequestableFactory(WebRequestableFactoryInterface factory)
sets the web requestable factory. This factory is used to create WebRequestables to handle the HTTP requests.


getSocketFactory

public WebServerSocketFactoryInterface getSocketFactory()
returns the current socket factory. The factory is used to create listening sockets for the server.


setSocketFactory

public void setSocketFactory(WebServerSocketFactoryInterface factory)
The factory is used to create listening sockets for the server. This factory must be set before the start() method is called or it will have no affect.


setDocumentBase

public void setDocumentBase(java.lang.String documentBase)
Sets the document base. This is the path to the documents this WebServer is serving. This property is used to populate the HTTPRequest's property. A WebRequestable should use the property of HTTPRequest to determine where documents are located. (HTTPFileRetriever used the property to locate the files it returns.)


getDocumentBase

public java.lang.String getDocumentBase()
Gets the document base. This is the path to the documents this WebServer is serving. This property is used to populate the HTTPRequest's property. A WebRequestable should use the property of HTTPRequest to determine where documents are located. (HTTPFileRetriever used the property to locate the files it returns.)


run

public void run()
called by runThread to start the listening process. This will continuously accept connections and pass them to WebRequestables until the WebServer has been terminated.

Specified by:
run in interface java.lang.Runnable

addWebServerListener

public void addWebServerListener(WebServerListener l)
adds a listener to this WebServer


removeWebServerListener

public void removeWebServerListener(WebServerListener l)
removes a listener from this WebServer