com.lukasfeiler.httpd
Class HTTPServer

java.lang.Object
  extended byjava.net.ServerSocket
      extended bycom.lukasfeiler.tcpserver.TCPServer
          extended bycom.lukasfeiler.httpd.HTTPServer

public class HTTPServer
extends com.lukasfeiler.tcpserver.TCPServer

This class implements a simple and secure HTTP server.

Version:
0.1
Author:
Lukas Feiler

Constructor Summary
protected HTTPServer(java.util.Map configuration)
          Constructor.
 
Method Summary
static HTTPServer configuredHTTPServer(java.lang.String configFile)
          Factory method.
 java.lang.String getConfigurationOption(java.lang.String name, java.lang.String defaultValue)
          Returns the specified configuration option and in case it is undefined a default value.
 java.lang.String getContentType(java.io.File f)
          Returns the content type of the file pass as argument.
 java.lang.String getDate()
          Returns the current date and time.
 java.io.File getDocumentRoot()
          Returns an instance of File for the document root - please see the configuration option DocumentRoot.
 java.lang.String getFileExtension(java.io.File f)
          Returns the extension of the file pass as argument.
 java.lang.String getListenAddress()
          Returns the address the server listens on - please see the configuration option ListenAddress.
 java.lang.String getListenPort()
          Returns the port the server listens on - please see the configuration option ListenPort.
 HTTPServerPlugin[] getPlugins()
          Returns the loaded plugins - please see the configuration option Plugins.
 java.lang.String getServerBanner()
          Return the server banner - please see the configuration option ServerBanner.
 void logAccess(HTTPSocket socket, java.io.File f, java.lang.String requestedResource, java.util.Vector headers, int statusCode, int byteSize)
          Write to access log file.
 void logError(HTTPSocket socket, java.io.File f, java.lang.String requestedResource, java.util.Vector headers, int statusCode, java.lang.String message)
          Write to error log file.
 void logError(java.lang.String message)
          Write to error log file.
 void logSecure(HTTPSocket socket, java.io.File f, java.lang.String requestedResource, java.util.Vector headers, java.lang.String message)
          Write to secure log file.
static void main(java.lang.String[] args)
          Create a new HTTPServer with the configuration file passed as argument.
protected  com.lukasfeiler.tcpserver.TCPSocket socketFactory(java.net.Socket tcpSocket, java.lang.Integer socketId, com.lukasfeiler.tcpserver.TCPServer tcpServer, int connectionTimeout)
          Factory method for creating new sockets.
 
Methods inherited from class com.lukasfeiler.tcpserver.TCPServer
connectionMaximumExceeded, connectionMaximumReached, getConnectionLifetime, getConnectionMaximum, getConnectionMaximumDelay, getConnectionQueueLength, getConnectionTimeout, removeSocket, start, stop
 
Methods inherited from class java.net.ServerSocket
accept, bind, bind, close, getChannel, getInetAddress, getLocalPort, getLocalSocketAddress, getReceiveBufferSize, getReuseAddress, getSoTimeout, implAccept, isBound, isClosed, setReceiveBufferSize, setReuseAddress, setSocketFactory, setSoTimeout, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HTTPServer

protected HTTPServer(java.util.Map configuration)
              throws java.io.IOException
Constructor. The preferred way to create a new instance is configuredHTTPServer(String configFile).

See Also:
configuredHTTPServer(String configFile)
Method Detail

configuredHTTPServer

public static HTTPServer configuredHTTPServer(java.lang.String configFile)
Factory method. Please note that this is the preferred way of creating a new instance of HTTPServer. It makes sure that all essential configuration options are set.

Parameters:
configFile - Path the the configuration file (usually named httpd.conf).

socketFactory

protected com.lukasfeiler.tcpserver.TCPSocket socketFactory(java.net.Socket tcpSocket,
                                                            java.lang.Integer socketId,
                                                            com.lukasfeiler.tcpserver.TCPServer tcpServer,
                                                            int connectionTimeout)
                                                     throws java.io.IOException
Factory method for creating new sockets. This method overwrites a method inherited from TCPServer and returns a new instance of HTTPSocket instead of TCPSocket.

Throws:
java.io.IOException
See Also:
HTTPSocket

getDocumentRoot

public java.io.File getDocumentRoot()
Returns an instance of File for the document root - please see the configuration option DocumentRoot. If the document root does not exist the server will termiate with an exit code of 1.


getListenAddress

public java.lang.String getListenAddress()
Returns the address the server listens on - please see the configuration option ListenAddress.


getListenPort

public java.lang.String getListenPort()
Returns the port the server listens on - please see the configuration option ListenPort.


getPlugins

public HTTPServerPlugin[] getPlugins()
Returns the loaded plugins - please see the configuration option Plugins. All plugins are sub-classes of HTTPServerPlugin.


getConfigurationOption

public java.lang.String getConfigurationOption(java.lang.String name,
                                               java.lang.String defaultValue)
Returns the specified configuration option and in case it is undefined a default value.


getContentType

public java.lang.String getContentType(java.io.File f)
Returns the content type of the file pass as argument.


getFileExtension

public java.lang.String getFileExtension(java.io.File f)
Returns the extension of the file pass as argument.


getDate

public java.lang.String getDate()
Returns the current date and time.


getServerBanner

public java.lang.String getServerBanner()
Return the server banner - please see the configuration option ServerBanner.


logAccess

public void logAccess(HTTPSocket socket,
                      java.io.File f,
                      java.lang.String requestedResource,
                      java.util.Vector headers,
                      int statusCode,
                      int byteSize)
Write to access log file.


logError

public void logError(java.lang.String message)
Write to error log file.


logError

public void logError(HTTPSocket socket,
                     java.io.File f,
                     java.lang.String requestedResource,
                     java.util.Vector headers,
                     int statusCode,
                     java.lang.String message)
Write to error log file.


logSecure

public void logSecure(HTTPSocket socket,
                      java.io.File f,
                      java.lang.String requestedResource,
                      java.util.Vector headers,
                      java.lang.String message)
Write to secure log file.


main

public static void main(java.lang.String[] args)
Create a new HTTPServer with the configuration file passed as argument.