## org.mortbay.http.handler
Class ResourceHandler

    java.lang.Object
      |
      +--org.mortbay.http.handler.AbstractHttpHandler
            |
            +--org.mortbay.http.handler.ResourceHandler

All Implemented Interfaces:
  HttpHandler, LifeCycle, java.io.Serializable

public class ResourceHandler
extends AbstractHttpHandler

Handler to serve files and resources. Serves files from a given resource URL base and implements the GET, HEAD, DELETE, OPTIONS, PUT, MOVE methods and the IfModifiedSince and IfUnmodifiedSince header fields. A simple memory cache is also provided to reduce file I/O. HTTP/1.1 ranges are supported.

Version:
  $Id: ResourceHandler.java,v 1.54.2.1 2003/07/19 03:42:46 gregwilkins Exp $
Author:
  Nuno Pregui�a, Greg Wilkins
See Also:
  Serialized Form

Constructor Summary
`ResourceHandler()` Construct a ResourceHandler.

Method Summary
`java.lang.String[]` `getAllowedMethods()`
`java.lang.String` `getAllowedString()`
`int` `getMinGzipLength()` Get minimum content length for GZIP encoding.
`boolean` `getRedirectWelcome()`
`void` `handle(java.lang.String pathInContext, java.lang.String pathParams, HttpRequest request, HttpResponse response)` Handle a request.
`void` `handleGet(HttpRequest request, HttpResponse response, java.lang.String pathInContext, java.lang.String pathParams, Resource resource)`
`boolean` `isAcceptRanges()`
`boolean` `isDirAllowed()`
`boolean` `isMethodAllowed(java.lang.String method)`
`void` `sendData(HttpRequest request, HttpResponse response, java.lang.String pathInContext, Resource resource, boolean writeHeaders)`
`void` `setAcceptRanges(boolean ar)` Set if the handler accepts range requests.
`void` `setAllowedMethods(java.lang.String[] methods)`
`void` `setDirAllowed(boolean dirAllowed)`
`void` `setMinGzipLength(int minGzipLength)` Set minimum content length for GZIP encoding.
`void` `setRedirectWelcome(boolean redirectWelcome)`
`void` `start()` Start the LifeCycle.
`void` `stop()` Stop the LifeCycle.
`void` `writeHeaders(HttpResponse response, Resource resource, long count)`

Methods inherited from class org.mortbay.http.handler.AbstractHttpHandler
`getHttpContext, getName, handleTrace, initialize, isStarted, setName, toString`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### ResourceHandler

    public ResourceHandler()

  Construct a ResourceHandler.

Method Detail

### start

    public void start()
               throws java.lang.Exception

  Description copied from interface: `LifeCycle`
  Start the LifeCycle.

  Specified by:
    `start` in interface `LifeCycle`
  Overrides:
    `start` in class `AbstractHttpHandler`
  Throws:
    `java.lang.Exception` - An arbitrary exception may be thrown.

### stop

    public void stop()
              throws java.lang.InterruptedException

  Description copied from interface: `LifeCycle`
  Stop the LifeCycle. The LifeCycle may wait for current activities to complete normally, but it can be interrupted.

  Specified by:
    `stop` in interface `LifeCycle`
  Overrides:
    `stop` in class `AbstractHttpHandler`
  Throws:
    `java.lang.InterruptedException` - Stopping a lifecycle is rarely atomic and may be interrupted by another thread. If this happens InterruptedException is throw and the component will be in an indeterminant state and should probably be discarded.

### getAllowedMethods

    public java.lang.String[] getAllowedMethods()

### setAllowedMethods

    public void setAllowedMethods(java.lang.String[] methods)

### isMethodAllowed

    public boolean isMethodAllowed(java.lang.String method)

### getAllowedString

    public java.lang.String getAllowedString()

### isDirAllowed

    public boolean isDirAllowed()

### setDirAllowed

    public void setDirAllowed(boolean dirAllowed)

### isAcceptRanges

    public boolean isAcceptRanges()

### getRedirectWelcome

    public boolean getRedirectWelcome()

  Returns:
    True if welcome files are redirected to. False if forward is used.

### setRedirectWelcome

    public void setRedirectWelcome(boolean redirectWelcome)

  Parameters:
    `redirectWelcome` - True if welcome files are redirected to. False if forward is used.

### setAcceptRanges

    public void setAcceptRanges(boolean ar)

  Set if the handler accepts range requests. Default is false;

  Parameters:
    `ar` - True if the handler should accept ranges

### getMinGzipLength

    public int getMinGzipLength()

  Get minimum content length for GZIP encoding.

  Returns:
    Minimum length of content for gzip encoding or -1 if disabled.

### setMinGzipLength

    public void setMinGzipLength(int minGzipLength)

  Set minimum content length for GZIP encoding.

  Parameters:
    `minGzipLength` - If set to a positive integer, then static content larger than this will be served as gzip content encoded if a matching resource is found ending with ".gz"

### handle

    public void handle(java.lang.String pathInContext,
                       java.lang.String pathParams,
                       HttpRequest request,
                       HttpResponse response)
                throws HttpException,
                       java.io.IOException

  Description copied from interface: `HttpHandler`
  Handle a request. Note that Handlers are tried in order until one has handled the request. i.e. until request.isHandled() returns true. In broad terms this means, either a response has been commited or request.setHandled(true) has been called.

  Parameters:
    `pathInContext` - The context path
    `pathParams` - Path parameters such as encoded Session ID
    `request` - The HttpRequest request
    `response` - The HttpResponse response
    `HttpException`
    `java.io.IOException`

### handleGet

    public void handleGet(HttpRequest request,
                          HttpResponse response,
                          java.lang.String pathInContext,
                          java.lang.String pathParams,
                          Resource resource)
                   throws java.io.IOException

    `java.io.IOException`

### writeHeaders

    public void writeHeaders(HttpResponse response,
                             Resource resource,
                             long count)
                      throws java.io.IOException

    `java.io.IOException`

### sendData

    public void sendData(HttpRequest request,
                         HttpResponse response,
                         java.lang.String pathInContext,
                         Resource resource,
                         boolean writeHeaders)
                  throws java.io.IOException

    `java.io.IOException`

Copyright © 2000 Mortbay Consulting Pty. Ltd. All Rights Reserved.