org.xlightweb
Class FileServiceRequestHandler

Package class diagram package FileServiceRequestHandler
java.lang.Object
  extended by org.xlightweb.FileServiceRequestHandler
All Implemented Interfaces:
IHttpRequestHandler, IWebHandler

public class FileServiceRequestHandler
extends Object
implements IHttpRequestHandler

Handler implementation to handle file requests. If the requested file does not exists, the handler will forward the request. If the handler is embedded within RequestHandlerChain the next handler will be called. If no successor exists, a 404 will be returned. If the flag isShowDirectoryTree is set (default is false) the directory tree will be printed, in case the request file does not exists. See example:

  String basePath = "public/files";
  IHttpRequestHandler handler = new FileServiceRequestHandler(basePath, true);  // will show the directory tree, if a directory is requested
  
  IServer server = new HttpServer(8080, handler);
  server.start();
 


Field Summary
static boolean SHOW_DIRECTORY_TREE_DEFAULT
           
 
Fields inherited from interface org.xlightweb.IHttpRequestHandler
DEFAULT_EXECUTION_MODE, DEFAULT_INVOKE_ON_MODE, DEFAULT_SYNCHRONIZED_ON_MODE
 
Constructor Summary
FileServiceRequestHandler(String fileBasepath)
          constructor
FileServiceRequestHandler(String fileBasepath, boolean isShowDirectoryTree)
          constructor
FileServiceRequestHandler(String fileBasepath, Integer expireSec)
          constructor
FileServiceRequestHandler(String fileBasepath, Integer expireSec, boolean isShowDirectoryTree)
          constructor
 
Method Summary
 void onRequest(IHttpExchange exchange)
          call back method, which will be called if a request message (header) is received
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHOW_DIRECTORY_TREE_DEFAULT

public static final boolean SHOW_DIRECTORY_TREE_DEFAULT
See Also:
Constant Field Values
Constructor Detail

FileServiceRequestHandler

public FileServiceRequestHandler(String fileBasepath)
                          throws FileNotFoundException
constructor

Parameters:
fileBasepath - the base path
Throws:
FileNotFoundException - if the base path not exists

FileServiceRequestHandler

public FileServiceRequestHandler(String fileBasepath,
                                 Integer expireSec)
                          throws FileNotFoundException
constructor

Parameters:
fileBasepath - the base path
expireSec - the expire time sec, which will be added to each response for caching or null
Throws:
FileNotFoundException - if the base path not exists

FileServiceRequestHandler

public FileServiceRequestHandler(String fileBasepath,
                                 boolean isShowDirectoryTree)
                          throws FileNotFoundException
constructor

Parameters:
fileBasepath - the base path
isShowDirectoryTree - true, if the directory tree will been shown, if the requests file is a directory
Throws:
FileNotFoundException - if the base path not exists

FileServiceRequestHandler

public FileServiceRequestHandler(String fileBasepath,
                                 Integer expireSec,
                                 boolean isShowDirectoryTree)
                          throws FileNotFoundException
constructor

Parameters:
fileBasepath - the base path
expireSec - the expire time sec, which will be added to each response for caching or null
isShowDirectoryTree - true, if the directory tree will been shown, if the requests file is a directory
Throws:
FileNotFoundException - if the base path not exists
Method Detail

onRequest

public void onRequest(IHttpExchange exchange)
               throws IOException,
                      BadMessageException
Description copied from interface: IHttpRequestHandler
call back method, which will be called if a request message (header) is received

Specified by:
onRequest in interface IHttpRequestHandler
Parameters:
exchange - the exchange contains the request from the client is used to send the response
Throws:
IOException - if an exception occurred. By throwing this exception an error http response message will be sent by xSocket, if one or more requests are unanswered. The underlying connection will be closed
BadMessageException - By throwing this exception an error http response message will be sent by xSocket, which contains the exception message. The underlying connection will be closed