com.dalsemi.tininet.http
Class HTTPServer

java.lang.Object
  |
  +--com.dalsemi.tininet.http.HTTPServer

public class HTTPServer
extends java.lang.Object

This class implements an HTTP server. This class currently only supports the GET method. The POST method will be supported when java.lang.Runtime.exec() support is added. POST requests currently echo the posted data.
"serviceRequests" blocks on a ServerSocket accept call. A new thread is spawned to service each new connection.


Field Summary
static int DEFAULT_HTTP_PORT
           
static int DELETE
           
static int GET
           
static int HEAD
           
static int HTTP_BAD_REQUEST
           
static int HTTP_CREATED
           
static int HTTP_FORBIDDEN
           
static int HTTP_INTERNAL_ERROR
           
static int HTTP_NOT_FOUND
           
static int HTTP_OK
           
static int HTTP_SERVER_ERROR
           
static int HTTP_UNAUTHORIZED
           
static int HTTP_UNSUPPORTED_TYPE
           
static int OPTIONS
           
static int POST
           
static int PUT
           
static int TRACE
           
static int TYPE_FULL_REQUEST
           
static int TYPE_FULL_RESPONSE
           
static int TYPE_SIMPLE_REQUEST
           
static int UNSUPPORTED
           
 
Constructor Summary
HTTPServer()
          Default constructor.
HTTPServer(int httpPort)
          Creates an HTTPServer using port httpPort.
HTTPServer(int httpPort, boolean logEnabled)
          Creates an HTTPServer using port httpPort.
 
Method Summary
 java.lang.String getHTTPRoot()
          Returns the HTTP root of the server.
 java.lang.String getIndexPage()
          Returns the server's index page.
 java.lang.String getLogFilename()
          Returns the name of the log file.
 boolean getLogging()
          Returns the logging status.
 int getPortNumber()
          Returns the server's current port number.
 int serviceRequests()
          Checks for incoming client HTTP request and services supported requests that are detected.
 int serviceRequests(java.lang.Object lock)
          Checks for incoming client HTTP request and services supported requests that are detected.
 void setHTTPRoot(java.lang.String httpRoot)
          Sets the http root.
 void setIndexPage(java.lang.String indexPage)
          Sets the servers index page.
 void setLogFilename(java.lang.String logFileName)
          Sets the log file name.
 void setLogging(boolean logEnabled)
          Sets the logging status.
 void setPortNumber(int httpPort)
          Sets the server's port number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTTP_OK

public static final int HTTP_OK

HTTP_CREATED

public static final int HTTP_CREATED

HTTP_BAD_REQUEST

public static final int HTTP_BAD_REQUEST

HTTP_UNAUTHORIZED

public static final int HTTP_UNAUTHORIZED

HTTP_FORBIDDEN

public static final int HTTP_FORBIDDEN

HTTP_NOT_FOUND

public static final int HTTP_NOT_FOUND

HTTP_UNSUPPORTED_TYPE

public static final int HTTP_UNSUPPORTED_TYPE

HTTP_SERVER_ERROR

public static final int HTTP_SERVER_ERROR

HTTP_INTERNAL_ERROR

public static final int HTTP_INTERNAL_ERROR

TYPE_SIMPLE_REQUEST

public static final int TYPE_SIMPLE_REQUEST

TYPE_FULL_REQUEST

public static final int TYPE_FULL_REQUEST

TYPE_FULL_RESPONSE

public static final int TYPE_FULL_RESPONSE

DEFAULT_HTTP_PORT

public static final int DEFAULT_HTTP_PORT

UNSUPPORTED

public static final int UNSUPPORTED

GET

public static final int GET

POST

public static final int POST

HEAD

public static final int HEAD

OPTIONS

public static final int OPTIONS

PUT

public static final int PUT

DELETE

public static final int DELETE

TRACE

public static final int TRACE
Constructor Detail

HTTPServer

public HTTPServer()
           throws HTTPServerException
Default constructor. Uses default port and disables logging.
Throws:
HTTPServerException - if server instantiation error occurs.

HTTPServer

public HTTPServer(int httpPort)
           throws HTTPServerException
Creates an HTTPServer using port httpPort. Logging is disabled.
Parameters:
httpPort - port number for server.
Throws:
HTTPServerException - if server instantiation error occurs.

HTTPServer

public HTTPServer(int httpPort,
                  boolean logEnabled)
           throws HTTPServerException
Creates an HTTPServer using port httpPort. Logging is enabled if logEnabled is true.
Parameters:
httpPort - port number for server.
logEnabled - set logging option.
Throws:
HTTPServerException - if server instantiation error occurs.
Method Detail

getLogging

public boolean getLogging()
Returns the logging status.
Returns:
true if logging is enabled

setLogging

public void setLogging(boolean logEnabled)
                throws HTTPServerException
Sets the logging status. If logging is enabled the server will attempt to open a new log file if one does not exist. If logging is disabled the server will attempt to close the log file. Log files are always appended.
Parameters:
logEnabled - true if the server is to write to a default log file.
Throws:
HTTPServerException - if a log file error occurs.

getLogFilename

public java.lang.String getLogFilename()
Returns the name of the log file. This represents the file name including path.
Returns:
log file name.

setLogFilename

public void setLogFilename(java.lang.String logFileName)
Sets the log file name. If the path is not given the file will be written to the current directory.
Parameters:
logFileName - name of the log file

getHTTPRoot

public java.lang.String getHTTPRoot()
Returns the HTTP root of the server.
Returns:
server root.

setHTTPRoot

public void setHTTPRoot(java.lang.String httpRoot)
Sets the http root.
Parameters:
httpRoot - path indicating the root of the server.

getIndexPage

public java.lang.String getIndexPage()
Returns the server's index page.
Returns:
current index page.

setIndexPage

public void setIndexPage(java.lang.String indexPage)
Sets the servers index page.
Parameters:
indexPage - page to be used by the server as a default index page.

getPortNumber

public int getPortNumber()
Returns the server's current port number.
Returns:
current port number.

setPortNumber

public void setPortNumber(int httpPort)
                   throws HTTPServerException
Sets the server's port number. Note: The server will close any open ports and opens the new port.
Parameters:
httpPort - number of the port to be opened.
Throws:
HTTPServerException - if the port is opened by another server.

serviceRequests

public int serviceRequests()
                    throws HTTPServerException
Checks for incoming client HTTP request and services supported requests that are detected.
Returns:
the response code of the incomming request. 0 is returned if no requests are pending.
Throws:
HTTPServerException - if a server error occurs.

serviceRequests

public int serviceRequests(java.lang.Object lock)
                    throws HTTPServerException
Checks for incoming client HTTP request and services supported requests that are detected.
Parameters:
lock - - lock for exclusive access to web page.
Returns:
the response code of the incomming request. 0 is returned if no requests are pending.
Throws:
HTTPServerException - if a server error occurs.