Class FileHandler

java.lang.Object
org.bzdev.ejws.FileHandler
All Implemented Interfaces:
HttpHandler

public class FileHandler extends Object implements HttpHandler
HttpHandler for files. A FileHandler can process HTTP GET or HEAD methods, not other methods (e.g., PUT or POST). The constructors for a FileHandler will provide the class name of a subclass of WebMap and an argument that will be used as a single-argument constructor for an instance of a subclass of WebMap. This instance is used to obtain data necessary for generating a response to an HTTP request. The constructors for FileHandler will configure its WebMap based on flags provided by the constructors. It will also check if the WebMap provides a Web-Inf/web.xml file, and will parse that file. This file can specify the locations of welcome pages, mappings from file extensions to media types, the location of JSP-like pages for error reporting, and the page encoding that various files use.

The method named handle(com.sun.net.httpserver.HttpExchange) (defined by HttpHandler) handles HTTP requests. If an error occurs, and error page is obtained from the FileHandler's WebMap. If the requested URL's path matches that of the prefix for this FileHandler, a welcome page is requested from this FileHandler's WebMap On success, the resource provided in the HTML response is obtained from the WebMap.

The status codes that may be returned in an HTTP response are:

  • 100—Continue.
  • 200—OK.
  • 302—Found.
  • 404—Not Found
  • 405—Method Not Allowed
  • 406—Not Accepted
  • 417—Expectation Failed
  • 500—Internal Server Error
  • Constructor Summary

    Constructors
    Constructor
    Description
    FileHandler(String protocol, Object root, Class<? extends WebMap> clasz, boolean nowebxml)
    Constructor specifying a WebMap's class and using defaults for flags.
    FileHandler(String protocol, Object root, Class<? extends WebMap> clasz, boolean nowebxml, boolean displayDir, boolean hideWebInf)
    Constructor specifying a WebMap's class.
    FileHandler(String protocol, Object root, String className, boolean nowebxml)
    Constructor specifying a WebMap's class name and using defaults for flags.
    FileHandler(String protocol, Object root, String className, boolean nowebxml, boolean displayDir, boolean hideWebInf)
    Constructor specifying a WebMap's class name.
    FileHandler(String protocol, WebMap webmap, boolean nowebxml, boolean displayDir, boolean hideWebInf)
    Constructor using a previously created WebMap.
  • Method Summary

    Modifier and Type
    Method
    Description
    Get the login-alias string.
    Get the logout-alias string.
    Get the logout URI.
    int
    Get the number of outstanding requests.
    void
     
    boolean
    Determine if a login is required.
    static void
    sendResponseHeaders(HttpExchange exchange, int code, long length)
    Send the response headers, adding a session cookie if sessions are enabled.
    protected void
    Set the embedded web server that uses this file handler.
    void
    Set the login-alias string.
    void
    setLoginAlias(String alias, String target)
    Set the login-alias string with a location to visit when the login is successful, with the location represented as a relative path.
    void
    setLoginAlias(String alias, String target, boolean required)
    Set the login-alias string with a location to visit when the login is successful, with the location represented as a relative path, and with a flag indicating if a login is required.
    void
    setLoginAlias(String alias, URI target)
    Set the login-alias string with a location to visit when the login is successful, with the location represented as a URL.
    void
    setLoginAlias(String alias, URI target, boolean required)
    Set the login-alias string with a location to visit when the login is successful, with the location represented as a URL, and with a flag indicating if a login is required.
    void
    setLogoutAlias(String alias, URI target)
    Set the logout-alias string with a location to visit when the logout is successful, with the location represented as a URL.
    void
    Set an Appendable for tracing.
    void
    setTracer(Appendable tracer, boolean stacktrace)
    Set an Appendable for tracing with a stack trace.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait