org.webbitserver.handler
Class AbstractResourceHandler

java.lang.Object
  extended by org.webbitserver.handler.AbstractResourceHandler
All Implemented Interfaces:
HttpHandler
Direct Known Subclasses:
EmbeddedResourceHandler, StaticFileHandler

public abstract class AbstractResourceHandler
extends Object
implements HttpHandler


Nested Class Summary
protected  class AbstractResourceHandler.IOWorker
          All IO is performed by this worker on a separate thread, so we never block the HttpHandler.
 
Field Summary
static Map<String,String> DEFAULT_MIME_TYPES
           
protected static String DEFAULT_WELCOME_FILE_NAME
           
protected  DirectoryListingFormatter directoryListingFormatter
           
protected  Executor ioThread
           
protected  Map<String,String> mimeTypes
           
protected  TemplateEngine templateEngine
           
protected  String welcomeFileName
           
 
Constructor Summary
AbstractResourceHandler(Executor ioThread)
           
AbstractResourceHandler(Executor ioThread, TemplateEngine templateEngine)
           
 
Method Summary
 AbstractResourceHandler addMimeType(String extension, String mimeType)
           
protected abstract  AbstractResourceHandler.IOWorker createIOWorker(HttpRequest request, HttpResponse response, HttpControl control)
           
 AbstractResourceHandler enableDirectoryListing(boolean isDirectoryListingEnabled)
           
 AbstractResourceHandler enableDirectoryListing(boolean isDirectoryListingEnabled, DirectoryListingFormatter directoryListingFormatter)
           
 void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control)
           
protected  void serve(String mimeType, byte[] staticContents, HttpControl control, HttpResponse response, HttpRequest request, String path)
           
protected  void serveRange(int start, int end, ByteBuffer contents, HttpResponse response)
           
 AbstractResourceHandler welcomeFile(String welcomeFile)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MIME_TYPES

public static final Map<String,String> DEFAULT_MIME_TYPES

DEFAULT_WELCOME_FILE_NAME

protected static final String DEFAULT_WELCOME_FILE_NAME
See Also:
Constant Field Values

ioThread

protected final Executor ioThread

mimeTypes

protected final Map<String,String> mimeTypes

welcomeFileName

protected String welcomeFileName

directoryListingFormatter

protected DirectoryListingFormatter directoryListingFormatter

templateEngine

protected final TemplateEngine templateEngine
Constructor Detail

AbstractResourceHandler

public AbstractResourceHandler(Executor ioThread,
                               TemplateEngine templateEngine)

AbstractResourceHandler

public AbstractResourceHandler(Executor ioThread)
Method Detail

addMimeType

public AbstractResourceHandler addMimeType(String extension,
                                           String mimeType)

welcomeFile

public AbstractResourceHandler welcomeFile(String welcomeFile)

enableDirectoryListing

public AbstractResourceHandler enableDirectoryListing(boolean isDirectoryListingEnabled)

enableDirectoryListing

public AbstractResourceHandler enableDirectoryListing(boolean isDirectoryListingEnabled,
                                                      DirectoryListingFormatter directoryListingFormatter)

handleHttpRequest

public void handleHttpRequest(HttpRequest request,
                              HttpResponse response,
                              HttpControl control)
                       throws Exception
Specified by:
handleHttpRequest in interface HttpHandler
Throws:
Exception

serve

protected void serve(String mimeType,
                     byte[] staticContents,
                     HttpControl control,
                     HttpResponse response,
                     HttpRequest request,
                     String path)

serveRange

protected void serveRange(int start,
                          int end,
                          ByteBuffer contents,
                          HttpResponse response)

createIOWorker

protected abstract AbstractResourceHandler.IOWorker createIOWorker(HttpRequest request,
                                                                   HttpResponse response,
                                                                   HttpControl control)


Copyright © 2012. All Rights Reserved.