ikrs.httpd
Class HTTPHandler

java.lang.Object
  extended by ikrs.yuccasrv.ConnectionHandler
      extended by ikrs.yuccasrv.TCPAdapter
          extended by ikrs.httpd.HTTPHandler
All Implemented Interfaces:
ObjectWithUUID, BindListener, java.util.concurrent.RejectedExecutionHandler

public class HTTPHandler
extends TCPAdapter
implements java.util.concurrent.RejectedExecutionHandler


Field Summary
protected static HTTPHandler sharedInstance
          This is a bit ugly.
protected static java.lang.String[] SUPPORTED_METHODS
          Technically these are all _implemented_ methods, not all supported.
 
Constructor Summary
HTTPHandler()
           
 
Method Summary
 HexDumpOutputStream createHexDumpOutputStream()
           
 void finalize(long time, java.util.concurrent.TimeUnit unit)
          This method will be called if the SocketManager is going to terminate.
protected  java.util.Set<java.lang.String> getCGIMapHeadersSet()
          This method returns the internal Header-to-CGI mapping set.
 java.net.URI getDefaultErrorDocumentURI(java.lang.Integer statusCode)
          Get the default configured error document (URI relative to document root) by the given status code.
protected  DefaultResponseBuilder getDefaultResponseBuilder()
          Get the global response builder with dynamic type 'DefaultResponseBuilder'.
 java.io.File getDocumentRoot()
          Get the handler's configured document root file.
 Environment<java.lang.String,BasicType> getEnvironment()
           
protected  java.util.Map<java.lang.Integer,java.net.URI> getErrorDocumentMap()
          This method returns the internal error document map which will be configured by the HTTPConfigurator.
 HTTPFileFilter getFileFilter()
           
 FileHandler getFileHandlerByExtension(java.lang.String fileExtension)
          This method resolves the FileHandler matching the given file extension.
 FileHandler getFileHandlerByName(java.lang.String handlerName)
          This method resolves the FileHandler matching the given file extension.
 Environment<java.lang.String,BasicType> getGlobalConfiguration()
           
 java.text.DateFormat getHTTPDateFormat()
           
 CustomLogger getLogger()
          Get the global logger.
 ResourceAccessor getResourceAccessor()
          Get the global resource accessor.
 ResponseBuilder getResponseBuilder()
          Get the global response builder.
protected  HTTPDRuntimeStatistics getRuntimeStatistics()
          Get the runtime statistics for this handler.
 SessionManager<java.lang.String,BasicType,HTTPConnectionUserID> getSessionManager()
          Get this handler's session manager.
 java.lang.String getSoftwareName()
          Get the server's software name, compatible with the 'Server' header field.
 java.util.List<java.lang.String> getSupportedMethods()
          Get a list of allowed (implemented) methods.
 void init(Environment<java.lang.String,BasicType> additionalSettings, Environment<java.lang.String,BasicType> optionalReturnValues)
          This method will be called after the connection handler was instantiated (usually using the Class.newInstance() method).
protected  void initFileHandlers(java.io.File fileHandlersFile)
          This method initializes the FileHandler map.
 boolean isDirectoryListingAllowed()
          This is a global flag indicatng if directory listings are allowed or not.
 boolean isInsideDocumentRoot(java.io.File file)
          This method checks whether the passed file-system file is 'inside' the configured document root.
 boolean isSupportedMethod(java.lang.String method)
           
 java.lang.Boolean mapHeaderToCGIEnvironment(java.lang.String headerName)
          This method indicates if a given HTTP header should be mapped to the CGI environment or not.
protected  void perform_hexdumpFormat(java.lang.String formatString)
          This method is called by ikrs.http.ModuleCommand.execute().
protected  void perform_status()
          This method is called by ikrs.http.ModuleCommand.execute().
 void rejectedExecution(java.lang.Runnable r, java.util.concurrent.ThreadPoolExecutor executor)
          The RejectedExecutionHandler.rejectedExecution(...) is called by the ThreadPoolExecutor if the request queue is full and all threads are busy.
 void serverAcceptedTCPConnection(BindManager source, java.util.UUID socketID, java.net.Socket sock, ConnectionUserID<ConnectionUserID> userID)
           
protected  void setDocumentRoot(java.io.File newDocumentRoot)
           
 
Methods inherited from class ikrs.yuccasrv.TCPAdapter
serverAcceptedUDPConnection, serverClosed, serverCreated, serverError
 
Methods inherited from class ikrs.yuccasrv.ConnectionHandler
getUUID
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sharedInstance

protected static HTTPHandler sharedInstance
This is a bit ugly. Problem: the ModuleCommand/~Factory would require an HTTPHandler instance to be passed on system start. But the system instantiates the HTTPHandler at a later point by added a new handler to the yucca server. So the factory requires the handler on instantiation and vice versa. To solve this problem the handler stores the first instance that was created in this static attribute. When called the ModuleCommand tries to access this field. Warning: this only works if HTTP config uses a shared instance for _all_ listening ports. See the 'sharedHandlerInstance' attribute in the ikrs.httpd.conf file (server node). If the 'sharedHandlerInstance' is not set Yucca will create different handler instances for each 'server' tag. In this case the command will only work for the first handler instance created.


SUPPORTED_METHODS

protected static final java.lang.String[] SUPPORTED_METHODS
Technically these are all _implemented_ methods, not all supported. If a method M is supported or not is configured by the DISABLE_METHOD.M directive inside the ikrs.httpd.conf file.

Constructor Detail

HTTPHandler

public HTTPHandler()
Method Detail

setDocumentRoot

protected void setDocumentRoot(java.io.File newDocumentRoot)
                        throws java.lang.NullPointerException
Throws:
java.lang.NullPointerException

isInsideDocumentRoot

public boolean isInsideDocumentRoot(java.io.File file)
                             throws java.lang.NullPointerException
This method checks whether the passed file-system file is 'inside' the configured document root. The passed file should be rooted at the global file system root. Note that the document root directory is considered to be inside itself, as it is accessible by the URI '/'.

Parameters:
file - A file inside the local system's file system; must not be null.
Returns:
True if - and only if - the passed file is a file or a directory inside the document root directory or inside any subdirectory inside the document root or the passed file is document root itself. Or in other words: if the passed file is inside the configured HTTP document tree.
Throws:
java.lang.NullPointerException - If the passed file is null.

initFileHandlers

protected void initFileHandlers(java.io.File fileHandlersFile)
This method initializes the FileHandler map.


getGlobalConfiguration

public Environment<java.lang.String,BasicType> getGlobalConfiguration()

getRuntimeStatistics

protected HTTPDRuntimeStatistics getRuntimeStatistics()
Get the runtime statistics for this handler. The returned object is never null.


getDocumentRoot

public java.io.File getDocumentRoot()
Get the handler's configured document root file.

Returns:
Thhe handler's configured document root file, which should not be null.

isDirectoryListingAllowed

public boolean isDirectoryListingAllowed()
This is a global flag indicatng if directory listings are allowed or not. The ResourceAccessor/FilesystemResourceAccessor uses this method to check if it should show a requested directory's contents. The idea is to make the returned value configurable in future versions.

Returns:
true If and only if directory listings are allowed. If the method returns false no ResourceAccessors should print any directory listings (no matter what the local configuration is about)! Instead they should raise a SecurityException/403 Forbidden.

isSupportedMethod

public boolean isSupportedMethod(java.lang.String method)

getSupportedMethods

public java.util.List<java.lang.String> getSupportedMethods()
Get a list of allowed (implemented) methods. The returned array is a new copy.


getHTTPDateFormat

public java.text.DateFormat getHTTPDateFormat()

createHexDumpOutputStream

public HexDumpOutputStream createHexDumpOutputStream()

getSoftwareName

public java.lang.String getSoftwareName()
Get the server's software name, compatible with the 'Server' header field. 'Server' should have the format: Apache/1.3.29 (Unix) PHP/4.3.4


getResponseBuilder

public ResponseBuilder getResponseBuilder()
Get the global response builder.


getDefaultResponseBuilder

protected DefaultResponseBuilder getDefaultResponseBuilder()
Get the global response builder with dynamic type 'DefaultResponseBuilder'.


getResourceAccessor

public ResourceAccessor getResourceAccessor()
Get the global resource accessor.


getLogger

public CustomLogger getLogger()
Get the global logger.


getEnvironment

public Environment<java.lang.String,BasicType> getEnvironment()

getSessionManager

public SessionManager<java.lang.String,BasicType,HTTPConnectionUserID> getSessionManager()
Get this handler's session manager.


getFileFilter

public HTTPFileFilter getFileFilter()

getFileHandlerByExtension

public FileHandler getFileHandlerByExtension(java.lang.String fileExtension)
This method resolves the FileHandler matching the given file extension.


getFileHandlerByName

public FileHandler getFileHandlerByName(java.lang.String handlerName)
This method resolves the FileHandler matching the given file extension.


getDefaultErrorDocumentURI

public java.net.URI getDefaultErrorDocumentURI(java.lang.Integer statusCode)
Get the default configured error document (URI relative to document root) by the given status code. It is possible that not all error documents are defined; the method will return null in this case.

Parameters:
statusCode - The error code (usually a 30*, 40* or 50* status) you want to get the error document for.
Returns:
The error document (URI) for the passed error code.

getErrorDocumentMap

protected java.util.Map<java.lang.Integer,java.net.URI> getErrorDocumentMap()
This method returns the internal error document map which will be configured by the HTTPConfigurator. The returned map is never null.


getCGIMapHeadersSet

protected java.util.Set<java.lang.String> getCGIMapHeadersSet()
This method returns the internal Header-to-CGI mapping set. The returned map is never null and its comparator is not case-sensitive.


mapHeaderToCGIEnvironment

public java.lang.Boolean mapHeaderToCGIEnvironment(java.lang.String headerName)
This method indicates if a given HTTP header should be mapped to the CGI environment or not. If there is no configured header section (for CGI) the method returns null!


rejectedExecution

public void rejectedExecution(java.lang.Runnable r,
                              java.util.concurrent.ThreadPoolExecutor executor)
The RejectedExecutionHandler.rejectedExecution(...) is called by the ThreadPoolExecutor if the request queue is full and all threads are busy. This server should send a "Service Unavailable" error reply then.

Specified by:
rejectedExecution in interface java.util.concurrent.RejectedExecutionHandler
Parameters:
r - The Runnable object that was rejected to be executed.
executor - The executor that rejected the request.

init

public void init(Environment<java.lang.String,BasicType> additionalSettings,
                 Environment<java.lang.String,BasicType> optionalReturnValues)
          throws java.lang.InstantiationException
This method will be called after the connection handler was instantiated (usually using the Class.newInstance() method). Both params might be null or empty depending on the underlying interface implementation. This method must throw an InstantiationException if any required params are missing.

Specified by:
init in class TCPAdapter
Parameters:
additionalSettings - An environment containing additional initialization params. Might be null or empty.
optionalReturnValues - An environment the method may use to store (optional) return values in. May be null.
Throws:
java.lang.InstantiationException

serverAcceptedTCPConnection

public void serverAcceptedTCPConnection(BindManager source,
                                        java.util.UUID socketID,
                                        java.net.Socket sock,
                                        ConnectionUserID<ConnectionUserID> userID)
Specified by:
serverAcceptedTCPConnection in interface BindListener
Specified by:
serverAcceptedTCPConnection in class TCPAdapter
Parameters:
source - The BindManager that reports the event.
sockedID - The server socket's unique ID.
sock - The accepted connection socket.

finalize

public void finalize(long time,
                     java.util.concurrent.TimeUnit unit)
This method will be called if the SocketManager is going to terminate. All associated BindListener MUST terminate within the given time.

Specified by:
finalize in interface BindListener
Specified by:
finalize in class TCPAdapter
Parameters:
time - The time value all dependent child threads have to terminate in.
unit - The time unit.

perform_hexdumpFormat

protected void perform_hexdumpFormat(java.lang.String formatString)
This method is called by ikrs.http.ModuleCommand.execute(). It just prints some verbose status information.


perform_status

protected void perform_status()
This method is called by ikrs.http.ModuleCommand.execute(). It just prints some verbose status information.