pygmy.handlers
Class FileHandler

java.lang.Object
  extended by pygmy.core.AbstractHandler
      extended by pygmy.handlers.FileHandler
All Implemented Interfaces:
Handler

public class FileHandler
extends AbstractHandler
implements Handler

This is the most basic Handler of a web server. It serves up files from a specified directory. For all urls matching the url-prefix parameter, it translates those into files on the root files system starting at the root parameter. It does pay attention to the Range http header parameter, and will send a range of bytes from a request file. It also sets the file-path request property to the translate local system path of the file. Other handlers could use this so that they don't have to translate the URL into a path. This handler ignores directory requests, but will serve up default files ( like index.html, if the config parameter is set ). It does not provide a directory listing see DirectoryHandler for that functionality.

Parameter NameExplanationDefault ValueRequired
url-prefixThe prefix to filter request urls.NoneYes
rootA local system path to the root of the folder to share.NoneYes
default-fileThe name of the default file that should be used if no file is specified in the URL.index.htmlNo


Field Summary
static ConfigOption DEFAULT_FILE_OPTION
           
static java.lang.String IF_MODIFIED
           
static java.lang.String LAST_MODIFIED_KEY
           
static java.util.logging.Logger log
           
static java.lang.String RANGE_HEADER_KEY
           
static ConfigOption ROOT_OPTION
           
 
Fields inherited from class pygmy.core.AbstractHandler
handlerName, server, URL_PREFIX_OPTION, urlPrefix
 
Constructor Summary
FileHandler()
           
 
Method Summary
protected  boolean handleBody(HttpRequest request, HttpResponse response)
           
 boolean initialize(java.lang.String handlerName, Server server)
           
static void sendFile(HttpRequest request, HttpResponse response, java.io.File file, java.lang.String type)
           
 
Methods inherited from class pygmy.core.AbstractHandler
getMimeType, getName, getUrlPrefix, handle, isRequestdForHandler, shutdown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface pygmy.core.Handler
getName, handle, shutdown
 

Field Detail

log

public static final java.util.logging.Logger log

ROOT_OPTION

public static final ConfigOption ROOT_OPTION

DEFAULT_FILE_OPTION

public static final ConfigOption DEFAULT_FILE_OPTION

IF_MODIFIED

public static final java.lang.String IF_MODIFIED
See Also:
Constant Field Values

LAST_MODIFIED_KEY

public static final java.lang.String LAST_MODIFIED_KEY
See Also:
Constant Field Values

RANGE_HEADER_KEY

public static final java.lang.String RANGE_HEADER_KEY
See Also:
Constant Field Values
Constructor Detail

FileHandler

public FileHandler()
Method Detail

initialize

public boolean initialize(java.lang.String handlerName,
                          Server server)
Specified by:
initialize in interface Handler
Overrides:
initialize in class AbstractHandler

handleBody

protected boolean handleBody(HttpRequest request,
                             HttpResponse response)
                      throws java.io.IOException
Overrides:
handleBody in class AbstractHandler
Throws:
java.io.IOException

sendFile

public static void sendFile(HttpRequest request,
                            HttpResponse response,
                            java.io.File file,
                            java.lang.String type)
                     throws java.io.IOException
Throws:
java.io.IOException