Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.mortbay.http.handler
Class ResourceHandler  view ResourceHandler download ResourceHandler.java

java.lang.Object
  extended byorg.mortbay.http.handler.AbstractHttpHandler
      extended byorg.mortbay.http.handler.ResourceHandler
All Implemented Interfaces:
org.mortbay.http.HttpHandler, org.mortbay.util.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.58 2003/10/05 23:46:27 gregwilkins Exp $

Field Summary
private  boolean _acceptRanges
           
private  java.lang.String _allowed
           
private  boolean _dirAllowed
           
private  org.mortbay.util.StringMap _methodMap
           
private  java.lang.String[] _methods
           
private  int _minGzipLength
           
private  boolean _redirectWelcomeFiles
           
private static org.apache.commons.logging.Log log
           
 
Fields inherited from class org.mortbay.http.handler.AbstractHttpHandler
 
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()
           
protected  org.mortbay.util.Resource getResource(java.lang.String pathInContext)
          get Resource to serve.
 void handle(java.lang.String pathInContext, java.lang.String pathParams, org.mortbay.http.HttpRequest request, org.mortbay.http.HttpResponse response)
          Handle a request.
(package private)  void handleDelete(org.mortbay.http.HttpRequest request, org.mortbay.http.HttpResponse response, java.lang.String pathInContext, org.mortbay.util.Resource resource)
           
 void handleGet(org.mortbay.http.HttpRequest request, org.mortbay.http.HttpResponse response, java.lang.String pathInContext, java.lang.String pathParams, org.mortbay.util.Resource resource)
           
(package private)  void handleMove(org.mortbay.http.HttpRequest request, org.mortbay.http.HttpResponse response, java.lang.String pathInContext, org.mortbay.util.Resource resource)
           
(package private)  void handleOptions(org.mortbay.http.HttpResponse response, java.lang.String pathInContext)
           
(package private)  void handlePut(org.mortbay.http.HttpRequest request, org.mortbay.http.HttpResponse response, java.lang.String pathInContext, org.mortbay.util.Resource resource)
           
 boolean isAcceptRanges()
           
 boolean isDirAllowed()
           
 boolean isMethodAllowed(java.lang.String method)
           
private  boolean passConditionalHeaders(org.mortbay.http.HttpRequest request, org.mortbay.http.HttpResponse response, org.mortbay.util.Resource resource)
           
 void sendData(org.mortbay.http.HttpRequest request, org.mortbay.http.HttpResponse response, java.lang.String pathInContext, org.mortbay.util.Resource resource, boolean writeHeaders)
           
(package private)  void sendDirectory(org.mortbay.http.HttpRequest request, org.mortbay.http.HttpResponse response, org.mortbay.util.Resource resource, boolean parent)
           
 void setAcceptRanges(boolean ar)
          Set if the handler accepts range requests.
 void setAllowedMethods(java.lang.String[] methods)
           
(package private)  void setAllowHeader(org.mortbay.http.HttpResponse response)
           
 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(org.mortbay.http.HttpResponse response, org.mortbay.util.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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log

_acceptRanges

private boolean _acceptRanges

_redirectWelcomeFiles

private boolean _redirectWelcomeFiles

_methods

private java.lang.String[] _methods

_allowed

private java.lang.String _allowed

_dirAllowed

private boolean _dirAllowed

_minGzipLength

private int _minGzipLength

_methodMap

private org.mortbay.util.StringMap _methodMap
Constructor Detail

ResourceHandler

public ResourceHandler()
Construct a ResourceHandler.

Method Detail

start

public void start()
           throws java.lang.Exception
Description copied from interface: org.mortbay.util.LifeCycle
Start the LifeCycle.

Specified by:
start in interface org.mortbay.util.LifeCycle
Overrides:
start in class AbstractHttpHandler

stop

public void stop()
          throws java.lang.InterruptedException
Description copied from interface: org.mortbay.util.LifeCycle
Stop the LifeCycle. The LifeCycle may wait for current activities to complete normally, but it can be interrupted.

Specified by:
stop in interface org.mortbay.util.LifeCycle
Overrides:
stop in class AbstractHttpHandler

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()

setRedirectWelcome

public void setRedirectWelcome(boolean redirectWelcome)

setAcceptRanges

public void setAcceptRanges(boolean ar)
Set if the handler accepts range requests. Default is false;


getMinGzipLength

public int getMinGzipLength()
Get minimum content length for GZIP encoding.


setMinGzipLength

public void setMinGzipLength(int minGzipLength)
Set minimum content length for GZIP encoding.


getResource

protected org.mortbay.util.Resource getResource(java.lang.String pathInContext)
                                         throws java.io.IOException
get Resource to serve. Map a path to a resource. The default implementation calls HttpContext.getResource but derived handers may provide their own mapping.


handle

public void handle(java.lang.String pathInContext,
                   java.lang.String pathParams,
                   org.mortbay.http.HttpRequest request,
                   org.mortbay.http.HttpResponse response)
            throws org.mortbay.http.HttpException,
                   java.io.IOException
Description copied from interface: org.mortbay.http.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.


handleGet

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

passConditionalHeaders

private boolean passConditionalHeaders(org.mortbay.http.HttpRequest request,
                                       org.mortbay.http.HttpResponse response,
                                       org.mortbay.util.Resource resource)
                                throws java.io.IOException

handlePut

void handlePut(org.mortbay.http.HttpRequest request,
               org.mortbay.http.HttpResponse response,
               java.lang.String pathInContext,
               org.mortbay.util.Resource resource)
         throws java.io.IOException

handleDelete

void handleDelete(org.mortbay.http.HttpRequest request,
                  org.mortbay.http.HttpResponse response,
                  java.lang.String pathInContext,
                  org.mortbay.util.Resource resource)
            throws java.io.IOException

handleMove

void handleMove(org.mortbay.http.HttpRequest request,
                org.mortbay.http.HttpResponse response,
                java.lang.String pathInContext,
                org.mortbay.util.Resource resource)
          throws java.io.IOException

handleOptions

void handleOptions(org.mortbay.http.HttpResponse response,
                   java.lang.String pathInContext)
             throws java.io.IOException

setAllowHeader

void setAllowHeader(org.mortbay.http.HttpResponse response)

writeHeaders

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

sendData

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

sendDirectory

void sendDirectory(org.mortbay.http.HttpRequest request,
                   org.mortbay.http.HttpResponse response,
                   org.mortbay.util.Resource resource,
                   boolean parent)
             throws java.io.IOException