ikrs.httpd
Class AbstractFileHandler

java.lang.Object
  extended by ikrs.httpd.AbstractFileHandler
All Implemented Interfaces:
FileHandler
Direct Known Subclasses:
CGIHandler, IkarosExampleHandler

public abstract class AbstractFileHandler
extends java.lang.Object
implements FileHandler

This is a general abstract FileHandler implementation. Classes implementing the FileHandler interface should extend this class.


Constructor Summary
AbstractFileHandler()
          The file handler class usually is instantiated using the Class.newInstance() method.
 
Method Summary
 HTTPHandler getHTTPHandler()
          Get get FileHandler's global HTTPHandler.
 CustomLogger getLogger()
          Get the custom logger to use to write log messages.
abstract  Resource process(java.util.UUID sessionID, HTTPHeaders headers, PostDataWrapper postData, java.io.File file, java.net.URI requestURI)
          The 'process' method is very generic.
abstract  boolean requiresExistingFile()
          Most file handlers operate on existing files that are located inside the local file system (such as the default handler does for simple file delivery).
 void setHTTPHandler(HTTPHandler handler)
          Set the global HTTP handler.
 void setLogger(CustomLogger logger)
          Set the logger to use.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractFileHandler

public AbstractFileHandler()
                    throws java.lang.NullPointerException
The file handler class usually is instantiated using the Class.newInstance() method. So no params are required here.

Throws:
java.lang.NullPointerException
Method Detail

getHTTPHandler

public HTTPHandler getHTTPHandler()
Get get FileHandler's global HTTPHandler. Warning: as subclasses might be instantiated using the Class.newInstance() method in some very unusual cases the returned handler might be null. In that case be sure you have the handler set before by the use of setHTTPHandler(...).

Specified by:
getHTTPHandler in interface FileHandler
Returns:
The global HTTP handler (if available).

setHTTPHandler

public void setHTTPHandler(HTTPHandler handler)
                    throws java.lang.NullPointerException
Set the global HTTP handler.

Specified by:
setHTTPHandler in interface FileHandler
Parameters:
handler - The new handler (must not be null).
Throws:
java.lang.NullPointerException - If handler is null.

getLogger

public CustomLogger getLogger()
Get the custom logger to use to write log messages. Warning: as subclasses might be instantiated using the Class.newInstance() method in some very unusual cases the returned logger might be null. In that case be sure you have the logger set before by the use of setLogger(...).

Specified by:
getLogger in interface FileHandler
Returns:
The logger to use (if available).

setLogger

public void setLogger(CustomLogger logger)
               throws java.lang.NullPointerException
Set the logger to use.

Specified by:
setLogger in interface FileHandler
Parameters:
logger - The new logger (must not be null).
Throws:
java.lang.NullPointerException - If logger is null.

requiresExistingFile

public abstract boolean requiresExistingFile()
Most file handlers operate on existing files that are located inside the local file system (such as the default handler does for simple file delivery). Some file handlers operate on virtual file systems, which means that the request URI does not necessarily address an existing file but a symbol only the handler may know. The global HTTP handler needs to know if to throw a MissingResourceException (resulting in a 404) if a requested file does not exists --- or if to ignore that fact and simply continue. This method tells how to proceed. If your implementation returns true this handler will not be called at all; the request processing will directly stop raising an HTTP status 404.

Specified by:
requiresExistingFile in interface FileHandler
Returns:
true if this file handler definitely requires existing files. The process(...) method will never be called if the requested file does not exist in that case.

process

public abstract Resource process(java.util.UUID sessionID,
                                 HTTPHeaders headers,
                                 PostDataWrapper postData,
                                 java.io.File file,
                                 java.net.URI requestURI)
                          throws java.io.IOException,
                                 HeaderFormatException,
                                 DataFormatException,
                                 UnsupportedFormatException
The 'process' method is very generic. It depends on the underlying implementation how the passed file should be processed.

Specified by:
process in interface FileHandler
Parameters:
sessionID - The current session's ID.
headers - The HTTP request headers.
postData - The HTTP post data; if the method is not HTTP POST the 'postData' should be null (or empty).
file - The requested file itself (inside the local file system).
requestURI - The requested URI (relative to DOCUMENT_ROOT).
Throws:
java.io.IOException
HeaderFormatException
DataFormatException
UnsupportedFormatException